Skip to content

Commit 9d300f2

Browse files
malfetatalman
authored andcommitted
[BE] Do not package caffe2 in wheel (pytorch#87986)
If PyTorch is build without caffe2 integration, do not package unusable .py files/headers Same is true about functorch - don't package it unless building with `functorch` (although, I wonder if we should remove this option at some point in the future) Followup after pytorch/builder#1181 Pull Request resolved: pytorch#87986 Approved by: https://github.com/seemethere
1 parent cff9766 commit 9d300f2

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

.jenkins/pytorch/win-test-helpers/build_pytorch.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ python setup.py bdist_wheel && sccache --show-stats && python -c "import os, glo
144144
if "%BUILD_ENVIRONMENT%"=="" (
145145
echo NOTE: To run `import torch`, please make sure to activate the conda environment by running `call %CONDA_PARENT_DIR%\Miniconda3\Scripts\activate.bat %CONDA_PARENT_DIR%\Miniconda3` in Command Prompt before running Git Bash.
146146
) else (
147-
7z a %TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torch %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torchgen %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\caffe2 %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\functorch && copy /Y "%TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z" "%PYTORCH_FINAL_PACKAGE_DIR%\"
147+
7z a %TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torch %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torchgen %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\functorch && copy /Y "%TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z" "%PYTORCH_FINAL_PACKAGE_DIR%\"
148148
if errorlevel 1 exit /b
149149
if not errorlevel 0 exit /b
150150

setup.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -762,18 +762,22 @@ def run(self):
762762
super().run()
763763

764764

765+
def get_cmake_cache_vars():
766+
try:
767+
return defaultdict(lambda: False, cmake.get_cmake_cache_variables())
768+
except FileNotFoundError:
769+
# CMakeCache.txt does not exist. Probably running "python setup.py clean" over a clean directory.
770+
return defaultdict(lambda: False)
771+
772+
765773
def configure_extension_build():
766774
r"""Configures extension build options according to system environment and user's choice.
767775
768776
Returns:
769777
The input to parameters ext_modules, cmdclass, packages, and entry_points as required in setuptools.setup.
770778
"""
771779

772-
try:
773-
cmake_cache_vars = defaultdict(lambda: False, cmake.get_cmake_cache_variables())
774-
except FileNotFoundError:
775-
# CMakeCache.txt does not exist. Probably running "python setup.py clean" over a clean directory.
776-
cmake_cache_vars = defaultdict(lambda: False)
780+
cmake_cache_vars = get_cmake_cache_vars()
777781

778782
################################################################################
779783
# Configure compile flags
@@ -877,7 +881,12 @@ def make_relative_rpath_args(path):
877881
################################################################################
878882

879883
extensions = []
880-
packages = find_packages(exclude=('tools', 'tools.*'))
884+
excludes = ['tools', 'tools.*']
885+
if not cmake_cache_vars['BUILD_CAFFE2']:
886+
excludes.extend(['caffe2', 'caffe2.*'])
887+
if not cmake_cache_vars['BUILD_FUNCTORCH']:
888+
excludes.extend(['functorch', 'functorch.*'])
889+
packages = find_packages(exclude=excludes)
881890
C = Extension("torch._C",
882891
libraries=main_libraries,
883892
sources=main_sources,
@@ -1047,8 +1056,7 @@ def main():
10471056
'include/ATen/native/quantized/*.h',
10481057
'include/ATen/native/quantized/cpu/*.h',
10491058
'include/ATen/quantized/*.h',
1050-
'include/caffe2/utils/*.h',
1051-
'include/caffe2/utils/**/*.h',
1059+
'include/caffe2/serialize/*.h',
10521060
'include/c10/*.h',
10531061
'include/c10/macros/*.h',
10541062
'include/c10/core/*.h',
@@ -1062,7 +1070,6 @@ def main():
10621070
'include/c10/cuda/impl/*.h',
10631071
'include/c10/hip/*.h',
10641072
'include/c10/hip/impl/*.h',
1065-
'include/caffe2/**/*.h',
10661073
'include/torch/*.h',
10671074
'include/torch/csrc/*.h',
10681075
'include/torch/csrc/api/include/torch/*.h',
@@ -1147,6 +1154,13 @@ def main():
11471154
'utils/model_dump/code.js',
11481155
'utils/model_dump/*.mjs',
11491156
]
1157+
1158+
if get_cmake_cache_vars()['BUILD_CAFFE2']:
1159+
torch_package_data.extend([
1160+
'include/caffe2/**/*.h',
1161+
'include/caffe2/utils/*.h',
1162+
'include/caffe2/utils/**/*.h',
1163+
])
11501164
torchgen_package_data = [
11511165
# Recursive glob doesn't work in setup.py,
11521166
# https://github.com/pypa/setuptools/issues/1806

0 commit comments

Comments
 (0)