Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pkg 6001 win #52

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6392ecb
Build for windows
ELundby45 Dec 22, 2024
5cb7864
Add win specific missing_dso_whitelist
ELundby45 Dec 22, 2024
72bacd7
Pin setuptools
ELundby45 Dec 22, 2024
fb490d4
Try to fix test command on windows
ELundby45 Dec 22, 2024
618fbd3
Stage channel no longer needed.
ELundby45 Dec 22, 2024
74258de
Cleanup libgtorch files when building torch
ELundby45 Dec 22, 2024
2781c34
Update bld.bat
ELundby45 Dec 22, 2024
177e4a2
Fix patches on windows.
ELundby45 Dec 23, 2024
5fd2413
Remove pins, causing resolution error on windows,
ELundby45 Dec 23, 2024
f163074
Temporarily disable pip check on windows.
ELundby45 Dec 27, 2024
325177c
Simplify bld.bat
ELundby45 Jan 3, 2025
3a1044c
Re-enable pip check
ELundby45 Jan 3, 2025
d6e5b8f
Try to build in parallel
ELundby45 Jan 3, 2025
ac741b2
White space.
ELundby45 Jan 3, 2025
a4c7fb1
Temporarily skip non windows.
ELundby45 Jan 3, 2025
f3d270c
Stick with single job
ELundby45 Jan 4, 2025
6a25649
Re-vendor protobuf for now.
ELundby45 Jan 4, 2025
6a7ebc1
Fix windows split build.
ELundby45 Jan 6, 2025
fc109ce
Address overlinking and fix several tests.
ELundby45 Jan 6, 2025
e17fbc2
Test other platforms too.
ELundby45 Jan 6, 2025
14bf984
Fix typo in path.
ELundby45 Jan 7, 2025
121378a
Revert "Test other platforms too."
ELundby45 Jan 7, 2025
ed9022b
Unvendor protobuf
ELundby45 Jan 7, 2025
7b53796
Unvendor sleef
ELundby45 Jan 7, 2025
e02b47d
Remove unneeded flags.
ELundby45 Jan 7, 2025
7bfde6d
Clean between runs.
ELundby45 Jan 8, 2025
58b281e
Try more aggressive clean.
ELundby45 Jan 9, 2025
fe50aa4
Grammer
ELundby45 Jan 11, 2025
0662f6a
Try removing build command
ELundby45 Jan 11, 2025
a3d51b2
Build all architectures.
ELundby45 Jan 11, 2025
c3cb07a
Revert "Try removing build command"
ELundby45 Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions abs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 52 additions & 7 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@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.
:: (no current symlinks being packaged. Leaving this information here as it took some months to find the issue. Look out
:: for a failure with error message: "conda_package_handling.exceptions.ArchiveCreationError: <somefile> Cannot stat
:: while writing file")

set TH_BINARY_BUILD=1
set PYTORCH_BUILD_VERSION=%PKG_VERSION%
set PYTORCH_BUILD_NUMBER=%PKG_BUILDNUM%

Expand All @@ -21,6 +21,12 @@ if "%pytorch_variant%" == "gpu" (
set USE_CUDA=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"

:: =============================== CUDA FLAGS> ======================================
if "%build_with_cuda%" == "" goto cuda_flags_end

Expand All @@ -41,6 +47,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%
Expand All @@ -64,9 +71,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%
Expand All @@ -81,10 +91,45 @@ set BLAS=MKL
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"
set "USE_SYSTEM_SLEEF=ON"

:: Use our protobuf
set "BUILD_CUSTOM_PROTOBUF=OFF"
set "USE_LITE_PROTO=ON"

:: 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" (
:: 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

%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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like there might be some patching/contribution upstream to do? also with the linking problems

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.
:: set BUILD_PYTHON_ONLY=1

:: NOTE: Passing --cmake is necessary here since the torch frontend has it's
ELundby45 marked this conversation as resolved.
Show resolved Hide resolved
:: own cmake files that it needs to generate
cmake -DPython_EXECUTABLE="%PYTHON%" --build build --target clean
Copy link
Contributor

@danpetry danpetry Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this. you seem to be mixing setting a configuration variable and running a build step. Try removing -DPython_EXECUTABLE="%PYTHON%". This would then be a change from using pytorch's clean to using cmake's build stage clean. (i.e., it would clean build artifacts without regenerating a build system)

Copy link
Author

@ELundby45 ELundby45 Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I brought that over straight from the conda-forge PR. I'll try removing the-DPython_EXECUTABLE and make sure it still solves the problem of the 3.12 not getting fully built.

The setup.py clean wasn't ever actually doing anything since it relies on the .gitignore file being present (it's not present in the tarball we are pulling down)

https://github.com/pytorch/pytorch/blob/main/setup.py#L874-L892

%PYTHON% setup.py bdist_wheel --cmake
%PYTHON% -m pip install --find-links=dist torch --no-build-isolation --no-deps
)

%PYTHON% -m pip install . --no-deps --no-build-isolation -vv
if errorlevel 1 exit /b 1

4 changes: 4 additions & 0 deletions recipe/build_pytorch.bat
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
@echo On
setlocal enabledelayedexpansion

call %RECIPE_DIR%\bld.bat
if errorlevel 1 exit /b 1
56 changes: 39 additions & 17 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ build:
- python * # [megabuild]
- numpy * # [megabuild]
skip: True # [py<39]
skip: True # [win]
skip: True # [not win]

requirements:
# Keep this list synchronized (except for python*, numpy*) in outputs
Expand Down Expand Up @@ -114,12 +114,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
Expand Down Expand Up @@ -147,15 +148,15 @@ requirements:
# other requirements
- python 3.12 # [megabuild]
- python # [not megabuild]
- numpy 2.*
- numpy 2
- pip
- setuptools
- setuptools <=72.1.0
- wheel
- pyyaml
- 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"]
Expand All @@ -167,8 +168,8 @@ requirements:
- intel-openmp {{ mkl }} # [blas_impl == "mkl"]
- llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")]
- libabseil
- libprotobuf {{ libprotobuf }} # [not win]
- sleef 3.5.1 # [not win]
- libprotobuf {{ libprotobuf }}
- sleef 3.5.1
- typing
- libuv
- pkg-config # [unix]
Expand All @@ -180,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
Expand All @@ -199,6 +201,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:
Expand All @@ -210,13 +219,19 @@ 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:
- {{ 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]
Expand Down Expand Up @@ -256,8 +271,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
Expand All @@ -283,15 +298,15 @@ outputs:
{% endif %}
# other requirements
- python
- numpy 2.*
- numpy 2
- pip
- setuptools
- setuptools <=72.1.0
- wheel
- pyyaml
- 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"]
Expand All @@ -303,8 +318,8 @@ outputs:
- intel-openmp {{ mkl }} # [blas_impl == "mkl"]
- llvm-openmp 14.0.6 # [osx and not (blas_impl == "mkl")]
- libabseil
- libprotobuf {{ libprotobuf }} # [not win]
- sleef 3.5.1 # [not win]
- libprotobuf {{ libprotobuf }}
- sleef 3.5.1
- typing
- libuv
- pkg-config # [unix]
Expand Down Expand Up @@ -371,6 +386,8 @@ outputs:
- pytest-rerunfailures
- pytest-flakefinder
- pytest-xdist
# Needed for test_autograd.py
- pybind11
imports:
- torch
source_files:
Expand All @@ -379,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)]
Expand Down Expand Up @@ -411,7 +430,10 @@ 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]
# Hack to fix test_autograd.py so it can find pybind11
- 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,
# which we don't have.)
Expand Down