@@ -5,274 +5,6 @@ set -ex
55SOURCE_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null && pwd ) "
66
77
8- # Require only one python installation
9- if [[ -z " $DESIRED_PYTHON " ]]; then
10- echo " Need to set DESIRED_PYTHON env variable"
11- exit 1
12- fi
13- if [[ -n " $BUILD_PYTHONLESS " && -z " $LIBTORCH_VARIANT " ]]; then
14- echo " BUILD_PYTHONLESS is set, so need LIBTORCH_VARIANT to also be set"
15- echo " LIBTORCH_VARIANT should be one of shared-with-deps shared-without-deps static-with-deps static-without-deps"
16- exit 1
17- fi
18-
19- # Function to retry functions that sometimes timeout or have flaky failures
20- retry () {
21- $* || (sleep 1 && $* ) || (sleep 2 && $* ) || (sleep 4 && $* ) || (sleep 8 && $* )
22- }
23-
24- # TODO move this into the Docker images
25- OS_NAME=$( awk -F= ' /^NAME/{print $2}' /etc/os-release)
26- if [[ " $OS_NAME " == * " CentOS Linux" * ]]; then
27- retry yum install -q -y zip openssl
28- elif [[ " $OS_NAME " == * " AlmaLinux" * ]]; then
29- retry yum install -q -y zip openssl
30- elif [[ " $OS_NAME " == * " Red Hat Enterprise Linux" * ]]; then
31- retry dnf install -q -y zip openssl
32- elif [[ " $OS_NAME " == * " Ubuntu" * ]]; then
33- # TODO: Remove this once nvidia package repos are back online
34- # Comment out nvidia repositories to prevent them from getting apt-get updated, see https://github.com/pytorch/pytorch/issues/74968
35- # shellcheck disable=SC2046
36- sed -i ' s/.*nvidia.*/# &/' $( find /etc/apt/ -type f -name " *.list" )
37-
38- retry apt-get update
39- retry apt-get -y install zip openssl
40- fi
41-
42- # We use the package name to test the package by passing this to 'pip install'
43- # This is the env variable that setup.py uses to name the package. Note that
44- # pip 'normalizes' the name first by changing all - to _
45- if [[ -z " $TORCH_PACKAGE_NAME " ]]; then
46- TORCH_PACKAGE_NAME=' torch'
47- fi
48-
49- if [[ -z " $TORCH_NO_PYTHON_PACKAGE_NAME " ]]; then
50- TORCH_NO_PYTHON_PACKAGE_NAME=' torch_no_python'
51- fi
52-
53- TORCH_PACKAGE_NAME=" $( echo $TORCH_PACKAGE_NAME | tr ' -' ' _' ) "
54- TORCH_NO_PYTHON_PACKAGE_NAME=" $( echo $TORCH_NO_PYTHON_PACKAGE_NAME | tr ' -' ' _' ) "
55- echo " Expecting the built wheels to all be called '$TORCH_PACKAGE_NAME ' or '$TORCH_NO_PYTHON_PACKAGE_NAME '"
56-
57- # Version: setup.py uses $PYTORCH_BUILD_VERSION.post$PYTORCH_BUILD_NUMBER if
58- # PYTORCH_BUILD_NUMBER > 1
59- build_version=" $PYTORCH_BUILD_VERSION "
60- build_number=" $PYTORCH_BUILD_NUMBER "
61- if [[ -n " $OVERRIDE_PACKAGE_VERSION " ]]; then
62- # This will be the *exact* version, since build_number<1
63- build_version=" $OVERRIDE_PACKAGE_VERSION "
64- build_number=0
65- fi
66- if [[ -z " $build_version " ]]; then
67- build_version=1.0.0
68- fi
69- if [[ -z " $build_number " ]]; then
70- build_number=1
71- fi
72- if [[ " $BUILD_LIGHTWEIGHT " == " 1" ]]; then
73- build_version=" ${build_version} .lw"
74- fi
75-
76- if [[ -z " $PYTORCH_ROOT " ]]; then
77- echo " Need to set PYTORCH_ROOT env variable"
78- exit 1
79- fi
80- # Always append the pytorch commit to the build_version by querying Git
81- pushd " $PYTORCH_ROOT "
82- PYTORCH_COMMIT=$( git rev-parse HEAD)
83- popd
84-
85- # Append the commit as a ".git<shortsha>" suffix
86- # This yields versions like: torch-2.5.0+rocm6.2.0.lw.gitabcd1234
87- short_commit=$( echo " $PYTORCH_COMMIT " | cut -c1-8)
88- build_version=" ${build_version} .git${short_commit} "
89-
90- echo " Final build_version: $build_version "
91-
92- export PYTORCH_BUILD_VERSION=$build_version
93- export PYTORCH_BUILD_NUMBER=$build_number
94-
95- export CMAKE_LIBRARY_PATH=" /opt/intel/lib:/lib:$CMAKE_LIBRARY_PATH "
96- export CMAKE_INCLUDE_PATH=" /opt/intel/include:$CMAKE_INCLUDE_PATH "
97-
98- if [[ -e /opt/openssl ]]; then
99- export OPENSSL_ROOT_DIR=/opt/openssl
100- export CMAKE_INCLUDE_PATH=" /opt/openssl/include" :$CMAKE_INCLUDE_PATH
101- fi
102-
103- # If given a python version like 3.6m or 2.7mu, convert this to the format we
104- # expect. The binary CI jobs pass in python versions like this; they also only
105- # ever pass one python version, so we assume that DESIRED_PYTHON is not a list
106- # in this case
107- if [[ -n " $DESIRED_PYTHON " && " $DESIRED_PYTHON " != cp* ]]; then
108- python_nodot=" $( echo $DESIRED_PYTHON | tr -d m.u) "
109- DESIRED_PYTHON=" cp${python_nodot} -cp${python_nodot} "
110- fi
111-
112- if [[ ${python_nodot} -ge 310 ]]; then
113- py_majmin=" ${DESIRED_PYTHON: 2: 1} .${DESIRED_PYTHON: 3: 2} "
114- else
115- py_majmin=" ${DESIRED_PYTHON: 2: 1} .${DESIRED_PYTHON: 3: 1} "
116- fi
117-
118-
119- pydir=" /opt/python/$DESIRED_PYTHON "
120- export PATH=" $pydir /bin:$PATH "
121- echo " Will build for Python version: ${DESIRED_PYTHON} with ${python_installation} "
122-
123- mkdir -p /tmp/$WHEELHOUSE_DIR
124-
125- export PATCHELF_BIN=/usr/local/bin/patchelf
126- patchelf_version=$( $PATCHELF_BIN --version)
127- echo " patchelf version: " $patchelf_version
128- if [[ " $patchelf_version " == " patchelf 0.9" ]]; then
129- echo " Your patchelf version is too old. Please use version >= 0.10."
130- exit 1
131- fi
132-
133- # #######################################################
134- # Compile wheels as well as libtorch
135- # ######################################################
136-
137- pushd " $PYTORCH_ROOT "
138- python setup.py clean
139- retry pip install -r requirements.txt
140- ver () {
141- printf " %3d%03d%03d%03d" $( echo " $1 " | tr ' .' ' ' ) ;
142- }
143- case ${DESIRED_PYTHON} in
144- cp38* )
145- retry pip install -q numpy==1.15
146- ;;
147- cp31* )
148- # CIRCLE_TAG contains the PyTorch version such as "1.13.0"
149- if [[ $( ver ${CIRCLE_TAG} ) -ge $( ver 2.4) ]]; then
150- retry pip install -q --pre numpy==2.0.2
151- else
152- retry pip install -q " numpy<2.0.0"
153- fi
154- ;;
155- # Should catch 3.9+
156- * )
157- if [[ $( ver ${CIRCLE_TAG} ) -ge $( ver 2.4) ]]; then
158- retry pip install -q --pre numpy==2.0.2
159- else
160- retry pip install -q " numpy<2.0.0"
161- fi
162- ;;
163- esac
164-
165- # ROCm RHEL8 packages are built with cxx11 abi symbols
166- if [[ " $DESIRED_DEVTOOLSET " == * " cxx11-abi" * || " $DESIRED_CUDA " == * " rocm" * ]]; then
167- export _GLIBCXX_USE_CXX11_ABI=1
168- else
169- export _GLIBCXX_USE_CXX11_ABI=0
170- fi
171-
172- if [[ " $DESIRED_CUDA " == * " rocm" * ]]; then
173- echo " Calling build_amd.py at $( date) "
174- python tools/amd_build/build_amd.py
175- fi
176-
177- # This value comes from binary_linux_build.sh (and should only be set to true
178- # for master / release branches)
179- BUILD_DEBUG_INFO=${BUILD_DEBUG_INFO:= 0}
180-
181- if [[ $BUILD_DEBUG_INFO == " 1" ]]; then
182- echo " Building wheel and debug info"
183- else
184- echo " BUILD_DEBUG_INFO was not set, skipping debug info"
185- fi
186-
187- if [[ " $DISABLE_RCCL " = 1 ]]; then
188- echo " Disabling NCCL/RCCL in pyTorch"
189- USE_RCCL=0
190- USE_NCCL=0
191- USE_KINETO=0
192- else
193- USE_RCCL=1
194- USE_NCCL=1
195- USE_KINETO=1
196- fi
197-
198- echo " Calling setup.py bdist at $( date) "
199-
200- if [[ " $USE_SPLIT_BUILD " == " true" ]]; then
201- echo " Calling setup.py bdist_wheel for split build (BUILD_LIBTORCH_WHL)"
202- time EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]} \
203- BUILD_LIBTORCH_WHL=1 BUILD_PYTHON_ONLY=0 \
204- BUILD_LIBTORCH_CPU_WITH_DEBUG=$BUILD_DEBUG_INFO \
205- USE_NCCL=${USE_NCCL} USE_RCCL=${USE_RCCL} USE_KINETO=${USE_KINETO} \
206- python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR
207- echo " Finished setup.py bdist_wheel for split build (BUILD_LIBTORCH_WHL)"
208- echo " Calling setup.py bdist_wheel for split build (BUILD_PYTHON_ONLY)"
209- time EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]} \
210- BUILD_LIBTORCH_WHL=0 BUILD_PYTHON_ONLY=1 \
211- BUILD_LIBTORCH_CPU_WITH_DEBUG=$BUILD_DEBUG_INFO \
212- USE_NCCL=${USE_NCCL} USE_RCCL=${USE_RCCL} USE_KINETO=${USE_KINETO} \
213- python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR --cmake
214- echo " Finished setup.py bdist_wheel for split build (BUILD_PYTHON_ONLY)"
215- else
216- time CMAKE_ARGS=${CMAKE_ARGS[@]} \
217- EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]} \
218- BUILD_LIBTORCH_CPU_WITH_DEBUG=$BUILD_DEBUG_INFO \
219- USE_NCCL=${USE_NCCL} USE_RCCL=${USE_RCCL} USE_KINETO=${USE_KINETO} \
220- python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR
221- fi
222- echo " Finished setup.py bdist at $( date) "
223-
224- # Build libtorch packages
225- if [[ -n " $BUILD_PYTHONLESS " ]]; then
226- # Now build pythonless libtorch
227- # Note - just use whichever python we happen to be on
228- python setup.py clean
229-
230- if [[ $LIBTORCH_VARIANT = * " static" * ]]; then
231- STATIC_CMAKE_FLAG=" -DTORCH_STATIC=1"
232- fi
233-
234- mkdir -p build
235- pushd build
236- echo " Calling tools/build_libtorch.py at $( date) "
237- time CMAKE_ARGS=${CMAKE_ARGS[@]} \
238- EXTRA_CAFFE2_CMAKE_FLAGS=" ${EXTRA_CAFFE2_CMAKE_FLAGS[@]} $STATIC_CMAKE_FLAG " \
239- python ../tools/build_libtorch.py
240- echo " Finished tools/build_libtorch.py at $( date) "
241- popd
242-
243- mkdir -p libtorch/{lib,bin,include,share}
244- cp -r build/build/lib libtorch/
245-
246- # for now, the headers for the libtorch package will just be copied in
247- # from one of the wheels (this is from when this script built multiple
248- # wheels at once)
249- ANY_WHEEL=$( ls /tmp/$WHEELHOUSE_DIR /torch* .whl | head -n1)
250- unzip -d any_wheel $ANY_WHEEL
251- if [[ -d any_wheel/torch/include ]]; then
252- cp -r any_wheel/torch/include libtorch/
253- else
254- cp -r any_wheel/torch/lib/include libtorch/
255- fi
256- cp -r any_wheel/torch/share/cmake libtorch/share/
257- rm -rf any_wheel
258-
259- echo $PYTORCH_BUILD_VERSION > libtorch/build-version
260- echo " $( pushd $PYTORCH_ROOT && git rev-parse HEAD) " > libtorch/build-hash
261-
262- mkdir -p /tmp/$LIBTORCH_HOUSE_DIR
263-
264- if [[ " $DESIRED_DEVTOOLSET " == * " cxx11-abi" * ]]; then
265- LIBTORCH_ABI=" cxx11-abi-"
266- else
267- LIBTORCH_ABI=
268- fi
269-
270- zip -rq /tmp/$LIBTORCH_HOUSE_DIR /libtorch-$LIBTORCH_ABI$LIBTORCH_VARIANT -$PYTORCH_BUILD_VERSION .zip libtorch
271- cp /tmp/$LIBTORCH_HOUSE_DIR /libtorch-$LIBTORCH_ABI$LIBTORCH_VARIANT -$PYTORCH_BUILD_VERSION .zip \
272- /tmp/$LIBTORCH_HOUSE_DIR /libtorch-$LIBTORCH_ABI$LIBTORCH_VARIANT -latest.zip
273- fi
274-
275- popd
2768
2779# ######################################################################
27810# ADD DEPENDENCIES INTO THE WHEEL
@@ -332,32 +64,16 @@ replace_needed_sofiles() {
33264 done
33365}
33466
335- echo ' Built this wheel:'
336- ls /tmp/$WHEELHOUSE_DIR
337- mkdir -p " /$WHEELHOUSE_DIR "
338- mv /tmp/$WHEELHOUSE_DIR /torch* linux* .whl /$WHEELHOUSE_DIR /
339-
340- if [[ " $USE_SPLIT_BUILD " == " true" ]]; then
341- mv /tmp/$WHEELHOUSE_DIR /torch_no_python* .whl /$WHEELHOUSE_DIR / || true
342- fi
34367
344- if [[ -n " $BUILD_PYTHONLESS " ]]; then
345- mkdir -p /$LIBTORCH_HOUSE_DIR
346- mv /tmp/$LIBTORCH_HOUSE_DIR /* .zip /$LIBTORCH_HOUSE_DIR
347- rm -rf /tmp/$LIBTORCH_HOUSE_DIR
348- fi
349- rm -rf /tmp/$WHEELHOUSE_DIR
35068rm -rf /tmp_dir
35169mkdir /tmp_dir
35270pushd /tmp_dir
353-
354- for pkg in /$WHEELHOUSE_DIR /torch_no_python* .whl /$WHEELHOUSE_DIR /torch* linux* .whl /$LIBTORCH_HOUSE_DIR /libtorch* .zip; do
71+ for pkg in /$WHEELHOUSE_DIR /torch_no_python* .whl /$WHEELHOUSE_DIR /${WHEELNAME_MARKER} /torch* linux* .whl /$LIBTORCH_HOUSE_DIR /libtorch* .zip; do
35572
35673 # if the glob didn't match anything
35774 if [[ ! -e $pkg ]]; then
35875 continue
35976 fi
360-
36177 rm -rf tmp
36278 mkdir -p tmp
36379 cd tmp
@@ -366,6 +82,15 @@ for pkg in /$WHEELHOUSE_DIR/torch_no_python*.whl /$WHEELHOUSE_DIR/torch*linux*.w
36682 unzip -q $( basename $pkg )
36783 rm -f $( basename $pkg )
36884
85+ dist_info_dir=" $( ls -d * dist-info) "
86+ if [[ -n " ${WHEELNAME_MARKER} " ]]; then
87+ # Replace "Version: " entry in METADATA file with WHEELNAME_MARKER
88+ sed -i -e " /Version: /s/.git/${WHEELNAME_MARKER} .git/" ${dist_info_dir} /METADATA
89+ # Rename dist-info directory to contain WHEELNAME_MARKER
90+ new_dist_info_dir=$( echo " ${dist_info_dir} " | sed -e " s/.git/${WHEELNAME_MARKER} .git/" )
91+ mv ${dist_info_dir} ${new_dist_info_dir}
92+ fi
93+
36994 if [[ -d torch ]]; then
37095 PREFIX=torch
37196 else
@@ -429,7 +154,13 @@ for pkg in /$WHEELHOUSE_DIR/torch_no_python*.whl /$WHEELHOUSE_DIR/torch*linux*.w
429154 done
430155
431156 # regenerate the RECORD file with new hashes
432- record_file=$( echo $( basename $pkg ) | sed -e ' s/-cp.*$/.dist-info\/RECORD/g' )
157+ # record_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/RECORD/g')
158+ if [[ -n " ${WHEELNAME_MARKER} " ]]; then
159+ record_file=$( ls ${new_dist_info_dir} /RECORD)
160+ else
161+ record_file=$( ls ${dist_info_dir} /RECORD)
162+ fi
163+
433164 if [[ -e $record_file ]]; then
434165 echo " Generating new record file $record_file "
435166 : > " $record_file "
@@ -473,6 +204,11 @@ for pkg in /$WHEELHOUSE_DIR/torch_no_python*.whl /$WHEELHOUSE_DIR/torch*linux*.w
473204 # replace original wheel
474205 rm -f $pkg
475206 mv $( basename $pkg ) $pkg
207+ # Rename wheel to reflect lightweight/heavyweight
208+ if [[ -n " ${WHEELNAME_MARKER} " ]]; then
209+ # Rename wheel to match metadata in dist-info
210+ mv $pkg $( echo $pkg | sed -e " s/\.git/${WHEELNAME_MARKER} .git/" )
211+ fi
476212 cd ..
477213 rm -rf tmp
478214done
@@ -483,7 +219,7 @@ if [[ -n "$PYTORCH_FINAL_PACKAGE_DIR" ]]; then
483219 if [[ -n " $BUILD_PYTHONLESS " ]]; then
484220 cp /$LIBTORCH_HOUSE_DIR /libtorch* .zip " $PYTORCH_FINAL_PACKAGE_DIR "
485221 else
486- cp / $ WHEELHOUSE_DIR/ torch* .whl " $PYTORCH_FINAL_PACKAGE_DIR "
222+ cp " / ${ WHEELHOUSE_DIR} / ${WHEELNAME_MARKER} " / torch* .whl " ${ PYTORCH_FINAL_PACKAGE_DIR} "
487223 fi
488224fi
489225
@@ -507,10 +243,10 @@ if [[ -z "$BUILD_PYTHONLESS" ]]; then
507243 pip uninstall -y " $TORCH_PACKAGE_NAME "
508244
509245 if [[ " $USE_SPLIT_BUILD " == " true" ]]; then
510- pip install " $TORCH_NO_PYTHON_PACKAGE_NAME " --no-index -f /$WHEELHOUSE_DIR --no-dependencies -v
246+ pip install " $TORCH_NO_PYTHON_PACKAGE_NAME " --no-index -f /$WHEELHOUSE_DIR / ${WHEELNAME_MARKER} --no-dependencies -v
511247 fi
512248
513- pip install " $TORCH_PACKAGE_NAME " --no-index -f /$WHEELHOUSE_DIR --no-dependencies -v
249+ pip install " $TORCH_PACKAGE_NAME " --no-index -f /$WHEELHOUSE_DIR / ${WHEELNAME_MARKER} --no-dependencies -v
514250
515251 # Print info on the libraries installed in this wheel
516252 # Rather than adjust find command to skip non-library files with an embedded *.so* in their name,
0 commit comments