From 6392ecbb12721ea82561f6c4ede897e6c3ee7b3b Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:51:55 -0700 Subject: [PATCH 01/31] Build for windows --- recipe/meta.yaml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 638bdcc..ed95700 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -75,7 +75,6 @@ build: - python * # [megabuild] - numpy * # [megabuild] skip: True # [py<39] - skip: True # [win] requirements: # Keep this list synchronized (except for python*, numpy*) in outputs @@ -114,12 +113,13 @@ requirements: # This has a strong run_export so we don't need to put it in `host` or `run` # We use llvm-openmp for openblas variants on osx. - llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")] + - libuv # [win] - cmake - ninja-base # Keep libprotobuf here so that a compatibile version # of protobuf is installed between build and host - - libprotobuf # [not win] - - protobuf # [not win] + - libprotobuf + - protobuf - make # [linux] # Uncomment to use ccache, see README and build_pytorch.sh # - ccache @@ -167,7 +167,7 @@ requirements: - intel-openmp {{ mkl }} # [blas_impl == "mkl"] - llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")] - libabseil - - libprotobuf {{ libprotobuf }} # [not win] + - libprotobuf {{ libprotobuf }} - sleef 3.5.1 # [not win] - typing - libuv @@ -216,7 +216,6 @@ outputs: - {{ pin_subpackage('pytorch', max_pin='x.x') }} - {{ pin_subpackage('libtorch', max_pin='x.x') }} skip: True # [py<39] - skip: True # [win] script: build_pytorch.sh # [unix] script: build_pytorch.bat # [win] @@ -256,8 +255,8 @@ outputs: - ninja-base # Keep libprotobuf here so that a compatibile version # of protobuf is installed between build and host - - libprotobuf # [not win] - - protobuf # [not win] + - libprotobuf + - protobuf - make # [linux] # Uncomment to use ccache, see README and build_pytorch.sh # - ccache @@ -303,7 +302,7 @@ outputs: - intel-openmp {{ mkl }} # [blas_impl == "mkl"] - llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")] - libabseil - - libprotobuf {{ libprotobuf }} # [not win] + - libprotobuf {{ libprotobuf }} - sleef 3.5.1 # [not win] - typing - libuv From 5cb7864446f3813c665a64769bb2784ec3d41b0c Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:52:25 -0700 Subject: [PATCH 02/31] Add win specific missing_dso_whitelist --- recipe/meta.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index ed95700..5041caa 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -199,6 +199,13 @@ outputs: - name: libtorch build: missing_dso_whitelist: + # The are dynamically loaded from %SP_DIR%\torch\lib\ + - "**/asmjit.dll" # [win] + - "**/c10.dll" # [win] + - "**/fbgemm.dll" # [win] + - "**/shm.dll" # [win] + - "**/torch_cpu.dll" # [win] + - "**/torch_python.dll" # [win] - $RPATH/ld64.so.1 # [s390x] - name: pytorch build: @@ -210,6 +217,13 @@ outputs: ignore_run_exports: # [osx] - libuv # [osx] missing_dso_whitelist: + # The are dynamically loaded from %SP_DIR%\torch\lib\ + - "**/asmjit.dll" # [win] + - "**/c10.dll" # [win] + - "**/fbgemm.dll" # [win] + - "**/shm.dll" # [win] + - "**/torch_cpu.dll" # [win] + - "**/torch_python.dll" # [win] - $RPATH/ld64.so.1 # [s390x] detect_binary_files_with_prefix: false run_exports: From 72bacd74bae1f57368c4b53552afff7935c77b2f Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:53:40 -0700 Subject: [PATCH 03/31] Pin setuptools See https://github.com/pytorch/pytorch/issues/136541 --- recipe/meta.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 5041caa..41d1cc3 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -149,7 +149,7 @@ requirements: - python # [not megabuild] - numpy 2.* - pip - - setuptools + - setuptools <=72.1.0 - wheel - pyyaml - requests @@ -298,7 +298,7 @@ outputs: - python - numpy 2.* - pip - - setuptools + - setuptools <=72.1.0 - wheel - pyyaml - requests From fb490d4a2b69dcab2128996975922922cf6da207 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:53:55 -0700 Subject: [PATCH 04/31] Try to fix test command on windows --- recipe/meta.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 41d1cc3..4d10fb9 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -424,7 +424,8 @@ outputs: # Note that the `|| true` expression will make the build continue even if the whole script falls over completely # (for example, in the case of missing imports). There doesn't seem to be a way of making a script exception return # non-zero but failing tests return zero. - - python ./test/run_test.py --core --continue-through-error || true + - python ./test/run_test.py --core --continue-through-error || true # [not win] + - cmd.exe /c "python ./test/run_test.py --core --continue-through-error" || ver > nul 2> nul # [win] # The inductor tests test the torch.compile backend. Using the options below avoids running distributed tests, # which would be run if we used the --inductor option. (Distributed tests would only be correctly run on a multi-gpu test platform, # which we don't have.) From 618fbd30be0341d542212fc6b1b8922915d42783 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:54:16 -0700 Subject: [PATCH 05/31] Stage channel no longer needed. --- abs.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/abs.yaml b/abs.yaml index 8e1871b..963f96f 100644 --- a/abs.yaml +++ b/abs.yaml @@ -2,7 +2,4 @@ # variant, so it's specified for both. extra_labels_for_os: osx-arm64: [ventura] -aggregate_check: false - -channels: - - https://staging.continuum.io/prefect/fs/sympy-feedstock/pr10/3afd78c +aggregate_check: false \ No newline at end of file From 74258dea13200c4585501ba87416597d099a374d Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:54:40 -0700 Subject: [PATCH 06/31] Cleanup libgtorch files when building torch --- recipe/build_pytorch.bat | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/recipe/build_pytorch.bat b/recipe/build_pytorch.bat index 88ba130..7bee6ad 100644 --- a/recipe/build_pytorch.bat +++ b/recipe/build_pytorch.bat @@ -1 +1,19 @@ +@echo On +setlocal enabledelayedexpansion + call %RECIPE_DIR%\bld.bat +if errorlevel 1 exit /b 1 + +rmdir /s /q %SP_DIR%\torch\bin +rmdir /s /q %SP_DIR%\torch\share +for %%f in (ATen caffe2 torch c10) do ( + rmdir /s /q %SP_DIR%\torch\include\%%f +) + +@REM Delete all files from the lib directory that do not start with torch_python +for %%f in (%SP_DIR%\torch\lib\*) do ( + set "FILENAME=%%~nf" + if "!FILENAME:~0,12!" neq "torch_python" ( + del %%f + ) +) \ No newline at end of file From 2781c342f16925c0cc255ede40d1602890b4e87c Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 08:56:03 -0700 Subject: [PATCH 07/31] Update bld.bat --- recipe/bld.bat | 105 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 5 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index c4221a7..b0a35cd 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -1,4 +1,5 @@ @echo On +setlocal enabledelayedexpansion :: The PyTorch test suite includes some symlinks, which aren't resolved on Windows, leading to packaging errors. :: ATTN! These change and have to be updated manually, often with each release. @@ -21,6 +22,50 @@ if "%pytorch_variant%" == "gpu" ( set USE_CUDA=0 ) +:: TODO(baszalmstra): Figure out if we need these flags +SET "USE_NUMA=0" +SET "USE_ITT=0" + +:: KINETO seems to require CUPTI and will look quite hard for it. +:: CUPTI seems to cause trouble when users install a version of +:: cudatoolkit different than the one specified at compile time. +:: https://github.com/conda-forge/pytorch-cpu-feedstock/issues/135 +set "USE_KINETO=OFF" + +if "%PKG_NAME%" == "pytorch" ( + set "PIP_ACTION=install" + :: We build libtorch for a specific python version. + :: This ensures its only build once. However, when that version changes + :: we need to make sure to update that here. + :: Get the full python version string + for /f "tokens=2" %%a in ('python --version 2^>^&1') do set PY_VERSION_FULL=%%a + + :: Replace Python312 or python312 with ie Python311 or python311 + sed "s/\([Pp]ython\)312/\1%CONDA_PY%/g" build/CMakeCache.txt.orig > build/CMakeCache.txt + + :: Replace version string v3.12.8() with ie v3.11.11() + sed -i.bak -E "s/v3\.12\.[0-9]+/v%PY_VERSION_FULL%/g" build/CMakeCache.txt + + :: Replace interpreter properties Python;3;12;8;64 with ie Python;3;11;11;64 + sed -i.bak -E "s/Python;3;12;[0-9]+;64/Python;%PY_VERSION_FULL:.=;%;64/g" build/CMakeCache.txt + + :: Replace cp312-win_amd64 with ie cp311-win_amd64 + sed -i.bak "s/cp312/cp%CONDA_PY%/g" build/CMakeCache.txt + + :: We use a fan-out build to avoid the long rebuild of libtorch + :: However, the location of the numpy headers changes between python 3.8 + :: and 3.9+ since numpy 2.0 only exists for 3.9+ + if "%PY_VER%" == "3.8" ( + sed -i.bak "s#numpy\\\\_core\\\\include#numpy\\\\core\\\\include#g" build/CMakeCache.txt + ) else ( + sed -i.bak "s#numpy\\\\core\\\\include#numpy\\\\_core\\\\include#g" build/CMakeCache.txt + ) +) else ( + :: For the main script we just build a wheel for so that the C++/CUDA + :: parts are built. Then they are reused in each python version. + set "PIP_ACTION=wheel" +) + :: =============================== CUDA FLAGS> ====================================== if "%build_with_cuda%" == "" goto cuda_flags_end @@ -41,6 +86,7 @@ set USE_MKLDNN=1 set USE_TENSORPIPE=0 set DISTUTILS_USE_SDK=1 set BUILD_TEST=0 +set INSTALL_TEST=0 :: Don't increase MAX_JOBS to NUMBER_OF_PROCESSORS, as it will run out of heap set CPU_COUNT=1 set MAX_JOBS=%CPU_COUNT% @@ -64,9 +110,12 @@ set CUDNN_INCLUDE_DIR=%LIBRARY_PREFIX%\include :: =============================== CUDA< ====================================== set CMAKE_GENERATOR=Ninja +set "CMAKE_GENERATOR_TOOLSET=" set "CMAKE_GENERATOR_PLATFORM=" set "CMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" -set CMAKE_BUILD_TYPE=Release +set "CMAKE_INCLUDE_PATH=%LIBRARY_INC%" +set "CMAKE_LIBRARY_PATH=%LIBRARY_LIB%" +set "CMAKE_BUILD_TYPE=Release" :: This is so that CMake finds the environment's Python, not another one set Python_EXECUTABLE=%PYTHON% set Python3_EXECUTABLE=%PYTHON% @@ -82,9 +131,55 @@ set INTEL_MKL_DIR=%LIBRARY_PREFIX% set "libuv_ROOT=%LIBRARY_PREFIX%" set "USE_SYSTEM_SLEEF=OFF" -:: Note that BUILD_CUSTOM_PROTOBUF=OFF (which would use our protobuf) doesn't work properly as of last testing, and results in -:: duplicate symbols at link time. -:: set "BUILD_CUSTOM_PROTOBUF=OFF" -%PYTHON% -m pip install . --no-deps --no-build-isolation -vv +:: Use our protobuf +set "BUILD_CUSTOM_PROTOBUF=OFF" +set "USE_LITE_PROTO=ON" + +:: Clear the build from any remaining artifacts. +cmake --build build --target clean + +%PYTHON% -m pip install . --no-deps --no-build-isolation -vvv --no-clean if errorlevel 1 exit /b 1 + +:: Here we split the build into two parts. +:: +:: Both the packages libtorch and pytorch use this same build script. +:: - The output of the libtorch package should just contain the binaries that are +:: not related to Python. +:: - The output of the pytorch package contains everything except for the +:: non-python specific binaries. +:: +:: This ensures that a user can quickly switch between python versions without the +:: need to redownload all the large CUDA binaries. + +if "%PKG_NAME%" == "libtorch" ( + :: Extract the compiled wheel into a temporary directory + if not exist "%SRC_DIR%/dist" mkdir %SRC_DIR%/dist + pushd %SRC_DIR%/dist + for %%f in (../torch-*.whl) do ( + wheel unpack %%f + ) + + :: Navigate into the unpacked wheel + pushd torch-* + + :: Move the binaries into the packages site-package directory + robocopy /NP /NFL /NDL /NJH /E torch\bin %SP_DIR%\torch\bin\ + robocopy /NP /NFL /NDL /NJH /E torch\lib %SP_DIR%\torch\lib\ + robocopy /NP /NFL /NDL /NJH /E torch\share %SP_DIR%\torch\share\ + for %%f in (ATen caffe2 torch c10) do ( + robocopy /NP /NFL /NDL /NJH /E torch\include\%%f %SP_DIR%\torch\include\%%f\ + ) + + :: Remove the python binary files, that are placed in the site-packages + :: directory by the specific python specific pytorch package. + del %SP_DIR%\torch\lib\torch_python.* + del %SP_DIR%\functorch\_C*.pyd + + popd + popd + + :: Keep the original backed up to sed later + copy build\CMakeCache.txt build\CMakeCache.txt.orig +) \ No newline at end of file From 177e4a2158d747c6eefc7b90dad4e85a38ace148 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 19:20:52 -0700 Subject: [PATCH 08/31] Fix patches on windows. --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 22636f9..18f114a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,6 @@ * text=auto -*.patch text +*.patch binary *.diff binary meta.yaml text eol=lf build.sh text eol=lf From 5fd24132b591056501ba12013e3140273d82ac0a Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 22 Dec 2024 19:21:15 -0700 Subject: [PATCH 09/31] Remove pins, causing resolution error on windows, --- recipe/meta.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 4d10fb9..f37e07f 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -147,7 +147,7 @@ requirements: # other requirements - python 3.12 # [megabuild] - python # [not megabuild] - - numpy 2.* + - numpy 2 - pip - setuptools <=72.1.0 - wheel @@ -155,7 +155,7 @@ requirements: - requests - future - six - - mkl-devel {{ mkl }}.* # [blas_impl == "mkl"] + - mkl-devel {{ mkl }} # [blas_impl == "mkl"] - openblas-devel {{ openblas }} # [blas_impl == "openblas"] # - libcblas * *_mkl # [blas_impl == "mkl"] # - libcblas # [blas_impl != "mkl"] @@ -296,7 +296,7 @@ outputs: {% endif %} # other requirements - python - - numpy 2.* + - numpy 2 - pip - setuptools <=72.1.0 - wheel @@ -304,7 +304,7 @@ outputs: - requests - future - six - - mkl-devel {{ mkl }}.* # [blas_impl == "mkl"] + - mkl-devel {{ mkl }} # [blas_impl == "mkl"] - openblas-devel {{ openblas }} # [blas_impl == "openblas"] # - libcblas * *_mkl # [blas_impl == "mkl"] # - libcblas # [blas_impl != "mkl"] From f163074e92ea870f73479fa522da1720fd7b3a16 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 27 Dec 2024 11:30:15 -0700 Subject: [PATCH 10/31] Temporarily disable pip check on windows. --- recipe/meta.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index f37e07f..13f83bd 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -434,7 +434,8 @@ outputs: - python ./test/run_test.py --mps --continue-through-error || true # [(gpu_variant == "metal")] # Run pip check so as to ensure that all pytorch packages are installed # https://github.com/conda-forge/pytorch-cpu-feedstock/issues/24 - - pip check + # TODO: re-enable on windows. + - pip check # [not win] - python -c "import torch; print(torch.__version__)" # We have had issues with openmp .dylibs being doubly loaded in certain cases. These two tests catch those issues - python -c "import torch; import numpy" From 325177c461802a5bf6b04fbcd13dc4b96b90ffce Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 3 Jan 2025 15:07:05 -0700 Subject: [PATCH 11/31] Simplify bld.bat --- recipe/bld.bat | 89 ++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 69 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index b0a35cd..57a98b2 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -32,40 +32,6 @@ SET "USE_ITT=0" :: https://github.com/conda-forge/pytorch-cpu-feedstock/issues/135 set "USE_KINETO=OFF" -if "%PKG_NAME%" == "pytorch" ( - set "PIP_ACTION=install" - :: We build libtorch for a specific python version. - :: This ensures its only build once. However, when that version changes - :: we need to make sure to update that here. - :: Get the full python version string - for /f "tokens=2" %%a in ('python --version 2^>^&1') do set PY_VERSION_FULL=%%a - - :: Replace Python312 or python312 with ie Python311 or python311 - sed "s/\([Pp]ython\)312/\1%CONDA_PY%/g" build/CMakeCache.txt.orig > build/CMakeCache.txt - - :: Replace version string v3.12.8() with ie v3.11.11() - sed -i.bak -E "s/v3\.12\.[0-9]+/v%PY_VERSION_FULL%/g" build/CMakeCache.txt - - :: Replace interpreter properties Python;3;12;8;64 with ie Python;3;11;11;64 - sed -i.bak -E "s/Python;3;12;[0-9]+;64/Python;%PY_VERSION_FULL:.=;%;64/g" build/CMakeCache.txt - - :: Replace cp312-win_amd64 with ie cp311-win_amd64 - sed -i.bak "s/cp312/cp%CONDA_PY%/g" build/CMakeCache.txt - - :: We use a fan-out build to avoid the long rebuild of libtorch - :: However, the location of the numpy headers changes between python 3.8 - :: and 3.9+ since numpy 2.0 only exists for 3.9+ - if "%PY_VER%" == "3.8" ( - sed -i.bak "s#numpy\\\\_core\\\\include#numpy\\\\core\\\\include#g" build/CMakeCache.txt - ) else ( - sed -i.bak "s#numpy\\\\core\\\\include#numpy\\\\_core\\\\include#g" build/CMakeCache.txt - ) -) else ( - :: For the main script we just build a wheel for so that the C++/CUDA - :: parts are built. Then they are reused in each python version. - set "PIP_ACTION=wheel" -) - :: =============================== CUDA FLAGS> ====================================== if "%build_with_cuda%" == "" goto cuda_flags_end @@ -136,12 +102,6 @@ set "USE_SYSTEM_SLEEF=OFF" set "BUILD_CUSTOM_PROTOBUF=OFF" set "USE_LITE_PROTO=ON" -:: Clear the build from any remaining artifacts. -cmake --build build --target clean - -%PYTHON% -m pip install . --no-deps --no-build-isolation -vvv --no-clean -if errorlevel 1 exit /b 1 - :: Here we split the build into two parts. :: :: Both the packages libtorch and pytorch use this same build script. @@ -154,32 +114,23 @@ if errorlevel 1 exit /b 1 :: need to redownload all the large CUDA binaries. if "%PKG_NAME%" == "libtorch" ( - :: Extract the compiled wheel into a temporary directory - if not exist "%SRC_DIR%/dist" mkdir %SRC_DIR%/dist - pushd %SRC_DIR%/dist - for %%f in (../torch-*.whl) do ( - wheel unpack %%f - ) - - :: Navigate into the unpacked wheel - pushd torch-* - - :: Move the binaries into the packages site-package directory - robocopy /NP /NFL /NDL /NJH /E torch\bin %SP_DIR%\torch\bin\ - robocopy /NP /NFL /NDL /NJH /E torch\lib %SP_DIR%\torch\lib\ - robocopy /NP /NFL /NDL /NJH /E torch\share %SP_DIR%\torch\share\ - for %%f in (ATen caffe2 torch c10) do ( - robocopy /NP /NFL /NDL /NJH /E torch\include\%%f %SP_DIR%\torch\include\%%f\ - ) - - :: Remove the python binary files, that are placed in the site-packages - :: directory by the specific python specific pytorch package. - del %SP_DIR%\torch\lib\torch_python.* - del %SP_DIR%\functorch\_C*.pyd - - popd - popd - - :: Keep the original backed up to sed later - copy build\CMakeCache.txt build\CMakeCache.txt.orig -) \ No newline at end of file + :: For the main script we just build a wheel for so that the C++/CUDA + :: parts are built. Then they are reused in each python version. + set BUILD_LIBTORCH_WHL=1 + set BUILD_PYTHON_ONLY=0 + + %PYTHON% setup.py bdist_wheel + %PYTHON% -m pip install --find-links=dist torch_no_python --no-build-isolation --no-deps +) +else ( + set BUILD_LIBTORCH_WHL=0 + :: In theory we want BUILD_PYTHON_ONLY=1 but that ends up causing lots of linking problems. + :: set BUILD_PYTHON_ONLY=1 + + :: NOTE: Passing --cmake is necessary here since the torch frontend has it's + :: own cmake files that it needs to generate + %PYTHON% setup.py bdist_wheel --cmake +) + +if errorlevel 1 exit /b 1 + From 3a1044c9a36eb5ce6958722db5488687cb6a4a8a Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 3 Jan 2025 15:12:18 -0700 Subject: [PATCH 12/31] Re-enable pip check --- recipe/meta.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 13f83bd..f37e07f 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -434,8 +434,7 @@ outputs: - python ./test/run_test.py --mps --continue-through-error || true # [(gpu_variant == "metal")] # Run pip check so as to ensure that all pytorch packages are installed # https://github.com/conda-forge/pytorch-cpu-feedstock/issues/24 - # TODO: re-enable on windows. - - pip check # [not win] + - pip check - python -c "import torch; print(torch.__version__)" # We have had issues with openmp .dylibs being doubly loaded in certain cases. These two tests catch those issues - python -c "import torch; import numpy" From d6e5b8f3e0db75383fb8ea8ffa505b5c50bbb56a Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 3 Jan 2025 15:23:40 -0700 Subject: [PATCH 13/31] Try to build in parallel --- recipe/bld.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 57a98b2..856c7bb 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -54,7 +54,7 @@ set DISTUTILS_USE_SDK=1 set BUILD_TEST=0 set INSTALL_TEST=0 :: Don't increase MAX_JOBS to NUMBER_OF_PROCESSORS, as it will run out of heap -set CPU_COUNT=1 +set /a CPU_COUNT=CPU_COUNT/2 set MAX_JOBS=%CPU_COUNT% :: Use our Pybind11, Eigen set USE_SYSTEM_PYBIND11=1 @@ -130,6 +130,7 @@ else ( :: NOTE: Passing --cmake is necessary here since the torch frontend has it's :: own cmake files that it needs to generate %PYTHON% setup.py bdist_wheel --cmake + %PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps ) if errorlevel 1 exit /b 1 From ac741b2672799d42ccc6d72278924cbe2208f4e0 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 3 Jan 2025 16:26:13 -0700 Subject: [PATCH 14/31] White space. --- recipe/bld.bat | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 856c7bb..be3e200 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -25,7 +25,6 @@ if "%pytorch_variant%" == "gpu" ( :: TODO(baszalmstra): Figure out if we need these flags SET "USE_NUMA=0" SET "USE_ITT=0" - :: KINETO seems to require CUPTI and will look quite hard for it. :: CUPTI seems to cause trouble when users install a version of :: cudatoolkit different than the one specified at compile time. @@ -119,10 +118,9 @@ if "%PKG_NAME%" == "libtorch" ( set BUILD_LIBTORCH_WHL=1 set BUILD_PYTHON_ONLY=0 - %PYTHON% setup.py bdist_wheel - %PYTHON% -m pip install --find-links=dist torch_no_python --no-build-isolation --no-deps -) -else ( + %PYTHON% setup.py bdist_wheel + %PYTHON% -m pip install --find-links=dist torch_no_python --no-build-isolation --no-deps +) else ( set BUILD_LIBTORCH_WHL=0 :: In theory we want BUILD_PYTHON_ONLY=1 but that ends up causing lots of linking problems. :: set BUILD_PYTHON_ONLY=1 From a4c7fb1a7f9b4ac17f6aff0e193c55775aa24d54 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Fri, 3 Jan 2025 16:27:18 -0700 Subject: [PATCH 15/31] Temporarily skip non windows. --- recipe/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index f37e07f..308346f 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -75,6 +75,7 @@ build: - python * # [megabuild] - numpy * # [megabuild] skip: True # [py<39] + skip: True # [not win] requirements: # Keep this list synchronized (except for python*, numpy*) in outputs From f3d270c052d0bec37f99cc0d7b6d7485946e13cf Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sat, 4 Jan 2025 10:28:41 -0700 Subject: [PATCH 16/31] Stick with single job --- recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index be3e200..0ef25af 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -53,7 +53,7 @@ set DISTUTILS_USE_SDK=1 set BUILD_TEST=0 set INSTALL_TEST=0 :: Don't increase MAX_JOBS to NUMBER_OF_PROCESSORS, as it will run out of heap -set /a CPU_COUNT=CPU_COUNT/2 +set CPU_COUNT=1 set MAX_JOBS=%CPU_COUNT% :: Use our Pybind11, Eigen set USE_SYSTEM_PYBIND11=1 From 6a25649aef9109551db066863a8d4bd2a5de0164 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sat, 4 Jan 2025 10:28:53 -0700 Subject: [PATCH 17/31] Re-vendor protobuf for now. --- recipe/bld.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 0ef25af..a77b995 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -97,9 +97,9 @@ set INTEL_MKL_DIR=%LIBRARY_PREFIX% set "libuv_ROOT=%LIBRARY_PREFIX%" set "USE_SYSTEM_SLEEF=OFF" -:: Use our protobuf -set "BUILD_CUSTOM_PROTOBUF=OFF" -set "USE_LITE_PROTO=ON" +:: TODO: Use our protobuf +:: set "BUILD_CUSTOM_PROTOBUF=OFF" +:: set "USE_LITE_PROTO=ON" :: Here we split the build into two parts. :: From 6a7ebc13ecd04490bbce207e079b0c770d914162 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Mon, 6 Jan 2025 15:20:25 -0700 Subject: [PATCH 18/31] Fix windows split build. --- recipe/bld.bat | 3 +++ recipe/build_pytorch.bat | 16 +--------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index a77b995..34162d2 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -120,6 +120,9 @@ if "%PKG_NAME%" == "libtorch" ( %PYTHON% setup.py bdist_wheel %PYTHON% -m pip install --find-links=dist torch_no_python --no-build-isolation --no-deps + + :: building libtorch generates an empty __init__.py file. We don't want to package that, it should come from pytorch. + rm %SP_DIR%\torch\__init__.py ) else ( set BUILD_LIBTORCH_WHL=0 :: In theory we want BUILD_PYTHON_ONLY=1 but that ends up causing lots of linking problems. diff --git a/recipe/build_pytorch.bat b/recipe/build_pytorch.bat index 7bee6ad..5b75a8d 100644 --- a/recipe/build_pytorch.bat +++ b/recipe/build_pytorch.bat @@ -2,18 +2,4 @@ setlocal enabledelayedexpansion call %RECIPE_DIR%\bld.bat -if errorlevel 1 exit /b 1 - -rmdir /s /q %SP_DIR%\torch\bin -rmdir /s /q %SP_DIR%\torch\share -for %%f in (ATen caffe2 torch c10) do ( - rmdir /s /q %SP_DIR%\torch\include\%%f -) - -@REM Delete all files from the lib directory that do not start with torch_python -for %%f in (%SP_DIR%\torch\lib\*) do ( - set "FILENAME=%%~nf" - if "!FILENAME:~0,12!" neq "torch_python" ( - del %%f - ) -) \ No newline at end of file +if errorlevel 1 exit /b 1 \ No newline at end of file From fc109ce5371b2d5c9835cfc9a19c4cca385a70ba Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Mon, 6 Jan 2025 15:32:19 -0700 Subject: [PATCH 19/31] Address overlinking and fix several tests. --- recipe/meta.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 308346f..3cda638 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -181,6 +181,7 @@ requirements: # satisfy overlinking checks run: - {{ pin_compatible('intel-openmp') }} # [blas_impl == "mkl"] + - libuv # [win] # these tests are for the libtorch output below, but due to # a particularity of conda-build, that output is defined in @@ -385,6 +386,8 @@ outputs: - pytest-rerunfailures - pytest-flakefinder - pytest-xdist + # Needed for test_autograd.py + - pybind11 imports: - torch source_files: @@ -393,6 +396,8 @@ outputs: # as of pytorch=2.0.0, there is a bug when trying to run tests without the tools - tools - smoke_test + # See files needed: https://github.com/pytorch/pytorch/blob/main/test/test_ops.py#L271-L274 + - aten/src/ATen/native commands: # the smoke test script takes a bunch of env variables, defined below - set MATRIX_GPU_ARCH_VERSION="{{ '.'.join(cudatoolkit.split('.')[:2]) }}" # [(gpu_variant == "cuda-11") and (win)] @@ -426,6 +431,8 @@ outputs: # (for example, in the case of missing imports). There doesn't seem to be a way of making a script exception return # non-zero but failing tests return zero. - python ./test/run_test.py --core --continue-through-error || true # [not win] + # Hack to fix test_autograd.py so it can find pybind11 + - mv %PREFIX%/pybind11_global/pybind11 %PREFIX%/include # [win] - cmd.exe /c "python ./test/run_test.py --core --continue-through-error" || ver > nul 2> nul # [win] # The inductor tests test the torch.compile backend. Using the options below avoids running distributed tests, # which would be run if we used the --inductor option. (Distributed tests would only be correctly run on a multi-gpu test platform, From e17fbc2f8a5cc83f7155bd8ac3070f0770b77bea Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Mon, 6 Jan 2025 16:12:25 -0700 Subject: [PATCH 20/31] Test other platforms too. --- recipe/meta.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 3cda638..010012a 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -75,7 +75,6 @@ build: - python * # [megabuild] - numpy * # [megabuild] skip: True # [py<39] - skip: True # [not win] requirements: # Keep this list synchronized (except for python*, numpy*) in outputs From 14bf9841aab3a9148391fef55c92a261f2cf9a88 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Tue, 7 Jan 2025 12:46:06 -0700 Subject: [PATCH 21/31] Fix typo in path. --- recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 010012a..b1a4e98 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -431,7 +431,7 @@ outputs: # non-zero but failing tests return zero. - python ./test/run_test.py --core --continue-through-error || true # [not win] # Hack to fix test_autograd.py so it can find pybind11 - - mv %PREFIX%/pybind11_global/pybind11 %PREFIX%/include # [win] + - mv %PREFIX%/include/pybind11_global/pybind11 %PREFIX%/include # [win] - cmd.exe /c "python ./test/run_test.py --core --continue-through-error" || ver > nul 2> nul # [win] # The inductor tests test the torch.compile backend. Using the options below avoids running distributed tests, # which would be run if we used the --inductor option. (Distributed tests would only be correctly run on a multi-gpu test platform, From 121378a02ecf6dbebd3911eb07f96a5350814829 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Tue, 7 Jan 2025 12:46:19 -0700 Subject: [PATCH 22/31] Revert "Test other platforms too." This reverts commit e17fbc2f8a5cc83f7155bd8ac3070f0770b77bea. --- recipe/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index b1a4e98..170c236 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -75,6 +75,7 @@ build: - python * # [megabuild] - numpy * # [megabuild] skip: True # [py<39] + skip: True # [not win] requirements: # Keep this list synchronized (except for python*, numpy*) in outputs From ed9022bbf70ac4e3a9d97042d94baf8bb6929f9a Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Tue, 7 Jan 2025 14:56:03 -0700 Subject: [PATCH 23/31] Unvendor protobuf --- recipe/bld.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 34162d2..15a36d6 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -97,9 +97,9 @@ set INTEL_MKL_DIR=%LIBRARY_PREFIX% set "libuv_ROOT=%LIBRARY_PREFIX%" set "USE_SYSTEM_SLEEF=OFF" -:: TODO: Use our protobuf -:: set "BUILD_CUSTOM_PROTOBUF=OFF" -:: set "USE_LITE_PROTO=ON" +:: Use our protobuf +set "BUILD_CUSTOM_PROTOBUF=OFF" +set "USE_LITE_PROTO=ON" :: Here we split the build into two parts. :: From 7b537961070b09b8540db6bdab537c504b897eb6 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Tue, 7 Jan 2025 15:50:27 -0700 Subject: [PATCH 24/31] Unvendor sleef --- recipe/bld.bat | 2 +- recipe/meta.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 15a36d6..34799d4 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -95,7 +95,7 @@ set BLAS=MKL set INTEL_MKL_DIR=%LIBRARY_PREFIX% set "libuv_ROOT=%LIBRARY_PREFIX%" -set "USE_SYSTEM_SLEEF=OFF" +set "USE_SYSTEM_SLEEF=ON" :: Use our protobuf set "BUILD_CUSTOM_PROTOBUF=OFF" diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 170c236..7e30eb3 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -169,7 +169,7 @@ requirements: - llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")] - libabseil - libprotobuf {{ libprotobuf }} - - sleef 3.5.1 # [not win] + - sleef 3.5.1 - typing - libuv - pkg-config # [unix] @@ -319,7 +319,7 @@ outputs: - llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")] - libabseil - libprotobuf {{ libprotobuf }} - - sleef 3.5.1 # [not win] + - sleef 3.5.1 - typing - libuv - pkg-config # [unix] From e02b47dc289b1a370053303b9d4a6cfca662b167 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Tue, 7 Jan 2025 15:50:43 -0700 Subject: [PATCH 25/31] Remove unneeded flags. --- recipe/bld.bat | 4 ---- 1 file changed, 4 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 34799d4..8ef9f6e 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -7,7 +7,6 @@ setlocal enabledelayedexpansion :: for a failure with error message: "conda_package_handling.exceptions.ArchiveCreationError: Cannot stat :: while writing file") -set TH_BINARY_BUILD=1 set PYTORCH_BUILD_VERSION=%PKG_VERSION% set PYTORCH_BUILD_NUMBER=%PKG_BUILDNUM% @@ -22,9 +21,6 @@ if "%pytorch_variant%" == "gpu" ( set USE_CUDA=0 ) -:: TODO(baszalmstra): Figure out if we need these flags -SET "USE_NUMA=0" -SET "USE_ITT=0" :: KINETO seems to require CUPTI and will look quite hard for it. :: CUPTI seems to cause trouble when users install a version of :: cudatoolkit different than the one specified at compile time. From 7bfde6d4c9ff246505236bcd6aea1e38d93f846f Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Wed, 8 Jan 2025 13:35:20 -0700 Subject: [PATCH 26/31] Clean between runs. --- recipe/bld.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 8ef9f6e..12c8b86 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -109,7 +109,7 @@ set "USE_LITE_PROTO=ON" :: need to redownload all the large CUDA binaries. if "%PKG_NAME%" == "libtorch" ( - :: For the main script we just build a wheel for so that the C++/CUDA + :: For the main script we just build a wheel for libtorch so that the C++/CUDA :: parts are built. Then they are reused in each python version. set BUILD_LIBTORCH_WHL=1 set BUILD_PYTHON_ONLY=0 @@ -126,6 +126,7 @@ if "%PKG_NAME%" == "libtorch" ( :: NOTE: Passing --cmake is necessary here since the torch frontend has it's :: own cmake files that it needs to generate + %PYTHON% setup.py clean %PYTHON% setup.py bdist_wheel --cmake %PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps ) From 58b281e091816c0074e3754b31a8596f4e2ddaad Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Thu, 9 Jan 2025 09:54:17 -0700 Subject: [PATCH 27/31] Try more aggressive clean. --- recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 12c8b86..1c457d5 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -126,7 +126,7 @@ if "%PKG_NAME%" == "libtorch" ( :: NOTE: Passing --cmake is necessary here since the torch frontend has it's :: own cmake files that it needs to generate - %PYTHON% setup.py clean + cmake -DPython_EXECUTABLE="%PYTHON%" --build build --target clean %PYTHON% setup.py bdist_wheel --cmake %PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps ) From fe50aa40426829adcc91716cca42ec8867b88070 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sat, 11 Jan 2025 10:34:50 -0700 Subject: [PATCH 28/31] Grammer --- recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 1c457d5..62900cb 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -124,7 +124,7 @@ if "%PKG_NAME%" == "libtorch" ( :: In theory we want BUILD_PYTHON_ONLY=1 but that ends up causing lots of linking problems. :: set BUILD_PYTHON_ONLY=1 - :: NOTE: Passing --cmake is necessary here since the torch frontend has it's + :: NOTE: Passing --cmake is necessary here since the torch frontend has its :: own cmake files that it needs to generate cmake -DPython_EXECUTABLE="%PYTHON%" --build build --target clean %PYTHON% setup.py bdist_wheel --cmake From 0662f6a4a1b9c94d43ae70bb5db2a4fe435698c7 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sat, 11 Jan 2025 10:35:29 -0700 Subject: [PATCH 29/31] Try removing build command --- recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 62900cb..c5aa8e7 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -126,7 +126,7 @@ if "%PKG_NAME%" == "libtorch" ( :: NOTE: Passing --cmake is necessary here since the torch frontend has its :: own cmake files that it needs to generate - cmake -DPython_EXECUTABLE="%PYTHON%" --build build --target clean + cmake --build build --target clean %PYTHON% setup.py bdist_wheel --cmake %PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps ) From a3d51b2551ce5b39ca8aad8a8f211e2617d07d81 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sat, 11 Jan 2025 10:36:01 -0700 Subject: [PATCH 30/31] Build all architectures. --- recipe/meta.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7e30eb3..6032139 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -75,7 +75,6 @@ build: - python * # [megabuild] - numpy * # [megabuild] skip: True # [py<39] - skip: True # [not win] requirements: # Keep this list synchronized (except for python*, numpy*) in outputs From c3cb07a0c9ae99d96c812e6b0f075523b3540a60 Mon Sep 17 00:00:00 2001 From: Eric Lundby Date: Sun, 12 Jan 2025 11:16:35 -0700 Subject: [PATCH 31/31] Revert "Try removing build command" This reverts commit 0662f6a4a1b9c94d43ae70bb5db2a4fe435698c7. --- recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index c5aa8e7..62900cb 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -126,7 +126,7 @@ if "%PKG_NAME%" == "libtorch" ( :: NOTE: Passing --cmake is necessary here since the torch frontend has its :: own cmake files that it needs to generate - cmake --build build --target clean + cmake -DPython_EXECUTABLE="%PYTHON%" --build build --target clean %PYTHON% setup.py bdist_wheel --cmake %PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps )