Skip to content

Commit daefabb

Browse files
malfetkulinseth
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 ecd09e1 commit daefabb

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
@@ -145,7 +145,7 @@ python -c "import os, glob; os.system('python -mpip install ' + glob.glob('dist/
145145
if "%BUILD_ENVIRONMENT%"=="" (
146146
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.
147147
) else (
148-
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%\"
148+
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%\"
149149
if errorlevel 1 exit /b
150150
if not errorlevel 0 exit /b
151151

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,
@@ -1055,8 +1064,7 @@ def main():
10551064
'include/ATen/native/quantized/*.h',
10561065
'include/ATen/native/quantized/cpu/*.h',
10571066
'include/ATen/quantized/*.h',
1058-
'include/caffe2/utils/*.h',
1059-
'include/caffe2/utils/**/*.h',
1067+
'include/caffe2/serialize/*.h',
10601068
'include/c10/*.h',
10611069
'include/c10/macros/*.h',
10621070
'include/c10/core/*.h',
@@ -1070,7 +1078,6 @@ def main():
10701078
'include/c10/cuda/impl/*.h',
10711079
'include/c10/hip/*.h',
10721080
'include/c10/hip/impl/*.h',
1073-
'include/caffe2/**/*.h',
10741081
'include/torch/*.h',
10751082
'include/torch/csrc/*.h',
10761083
'include/torch/csrc/api/include/torch/*.h',
@@ -1158,6 +1165,13 @@ def main():
11581165
'utils/model_dump/code.js',
11591166
'utils/model_dump/*.mjs',
11601167
]
1168+
1169+
if get_cmake_cache_vars()['BUILD_CAFFE2']:
1170+
torch_package_data.extend([
1171+
'include/caffe2/**/*.h',
1172+
'include/caffe2/utils/*.h',
1173+
'include/caffe2/utils/**/*.h',
1174+
])
11611175
torchgen_package_data = [
11621176
# Recursive glob doesn't work in setup.py,
11631177
# https://github.com/pypa/setuptools/issues/1806

0 commit comments

Comments
 (0)