Skip to content

Commit

Permalink
Merge pull request conda-forge#339 from h-vetinari/cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Jan 31, 2025
2 parents 4f1b584 + 8591bb6 commit 0819140
Show file tree
Hide file tree
Showing 24 changed files with 578 additions and 55 deletions.
53 changes: 23 additions & 30 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ if "%blas_impl%" == "generic" (
SET BLAS=MKL
)

@REM TODO(baszalmstra): Figure out if we need these flags
SET "USE_NUMA=0"
SET "USE_ITT=0"

if "%PKG_NAME%" == "pytorch" (
set "PIP_ACTION=install"
@REM We build libtorch for a specific python version.
Expand Down Expand Up @@ -64,49 +60,53 @@ if "%PKG_NAME%" == "pytorch" (
set "PIP_ACTION=wheel"
)

if not "%cuda_compiler_version%" == "None" (
set USE_CUDA=1
set "BUILD_CUSTOM_PROTOBUF=OFF"
set "USE_LITE_PROTO=ON"

@REM set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%desired_cuda%
@REM set CUDA_BIN_PATH=%CUDA_PATH%\bin
@REM TODO(baszalmstra): Figure out if we need these flags
SET "USE_ITT=0"
SET "USE_NUMA=0"

set TORCH_CUDA_ARCH_LIST=5.0;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0+PTX
@REM TODO(baszalmstra): There are linker errors because of mixing Intel OpenMP (iomp) and Microsoft OpenMP (vcomp)
set "USE_OPENMP=OFF"

set TORCH_NVCC_FLAGS=-Xfatbin -compress-all
@REM Use our Pybind11, Eigen, sleef
set USE_SYSTEM_EIGEN_INSTALL=1
set USE_SYSTEM_PYBIND11=1
set USE_SYSTEM_SLEEF=1

if not "%cuda_compiler_version%" == "None" (
set USE_CUDA=1
set USE_STATIC_CUDNN=0
set MAGMA_HOME=%PREFIX%

@REM NCCL is not available on windows
set USE_NCCL=0
set USE_STATIC_NCCL=0

set MAGMA_HOME=%LIBRARY_PREFIX%
@REM set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%desired_cuda%
@REM set CUDA_BIN_PATH=%CUDA_PATH%\bin

set "PATH=%CUDA_BIN_PATH%;%PATH%"
set "TORCH_CUDA_ARCH_LIST=5.0;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0+PTX"
set "TORCH_NVCC_FLAGS=-Xfatbin -compress-all"

set MAGMA_HOME=%LIBRARY_PREFIX%
set "PATH=%CUDA_BIN_PATH%;%PATH%"
set CUDNN_INCLUDE_DIR=%LIBRARY_PREFIX%\include

) else (
set USE_CUDA=0
@REM MKLDNN is an Apache-2.0 licensed library for DNNs and is used
@REM for CPU builds. Not to be confused with MKL.
set "USE_MKLDNN=1"

@REM On windows, env vars are case-insensitive and setup.py
@REM passes all env vars starting with CUDA_*, CMAKE_* to
@REM to cmake
set "cuda_compiler_version="
set "cuda_compiler="
set "CUDA_VERSION="

@REM MKLDNN is an Apache-2.0 licensed library for DNNs and is used
@REM for CPU builds. Not to be confused with MKL.
set "USE_MKLDNN=1"
)

set DISTUTILS_USE_SDK=1

@REM Use our Pybind11, Eigen
set USE_SYSTEM_PYBIND11=1
set USE_SYSTEM_EIGEN_INSTALL=1

set CMAKE_INCLUDE_PATH=%LIBRARY_PREFIX%\include
set LIB=%LIBRARY_PREFIX%\lib;%LIB%

Expand All @@ -126,17 +126,10 @@ set "INSTALL_TEST=0"
set "BUILD_TEST=0"

set "libuv_ROOT=%LIBRARY_PREFIX%"
set "USE_SYSTEM_SLEEF=ON"

@REM uncomment to debug cmake build
@REM set "CMAKE_VERBOSE_MAKEFILE=1"

set "BUILD_CUSTOM_PROTOBUF=OFF"
set "USE_LITE_PROTO=ON"

@REM TODO(baszalmstra): There are linker errors because of mixing Intel OpenMP (iomp) and Microsoft OpenMP (vcomp)
set "USE_OPENMP=OFF"

@REM The activation script for cuda-nvcc doesnt add the CUDA_CFLAGS on windows.
@REM Therefore we do this manually here. See:
@REM https://github.com/conda-forge/cuda-nvcc-feedstock/issues/47
Expand Down
21 changes: 15 additions & 6 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ source:
- patches/0017-Add-conda-prefix-to-inductor-include-paths.patch
- patches/0018-make-ATEN_INCLUDE_DIR-relative-to-TORCH_INSTALL_PREF.patch
- patches/0019-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch # [win]
- patches/0020-make-library-name-in-test_mutable_custom_op_fixed_la.patch
- patches/0021-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch
- patches_submodules/0001-remove-DESTINATION-lib-from-CMake-install-directives.patch # [win]

build:
number: {{ build }}
# cuda 11.8 was dropped due to maintenance effort, see discussion in #177
skip: true # [cuda_compiler_version == "11.8"]
# temporary skip to avoid wasting resources while unbreak CUDA builds
skip: true # [cuda_compiler_version == "None"]
# This logic allows two rc variants to be defined in the conda_build_config, but only one to actually be built.
# We want to be able to define two variants in the cbc so we can assign different labels to each in the upload channel
# (by zipping is_rc with channel_targets). This prevents rc builds being used unless specifically requested.
Expand Down Expand Up @@ -177,6 +181,7 @@ requirements:
- typing_extensions
- pybind11
- eigen
- zlib
run:
# GPU requirements without run_exports
- {{ pin_compatible('cudnn') }} # [cuda_compiler_version != "None"]
Expand Down Expand Up @@ -450,7 +455,9 @@ outputs:
"test/test_nn.py",
"test/test_torch.py",
"test/test_xnnpack_integration.py",
] + (cuda_compiler_version != "None") * ["test/inductor/test_torchinductor.py"]) %}
]) %}
# test_torchinductor adds >4h in test runtime in emulation; not supported yet for 3.13
{% set tests = tests ~ " test/inductor/test_torchinductor.py" %} # [py<313 and not aarch64]

{% set skips = "(TestTorch and test_print)" %}
# tolerance violation with openblas
Expand All @@ -472,16 +479,17 @@ outputs:
# may crash spuriously
{% set skips = skips ~ " or (TestAutograd and test_profiler_seq_nr)" %}
{% set skips = skips ~ " or (TestAutograd and test_profiler_propagation)" %}
# tests that fail due to resource clean-up issues (non-unique temporary libraries), see
# https://github.com/conda-forge/pytorch-cpu-feedstock/pull/318#issuecomment-2620080859
{% set skips = skips ~ " or test_mutable_custom_op_fixed_layout" %} # [cuda_compiler_version != "None"]
# trivial accuracy problems
{% set skips = skips ~ " or test_BCELoss_weights_no_reduce_cuda" %} # [unix and cuda_compiler_version != "None"]
{% set skips = skips ~ " or test_ctc_loss_cudnn_tensor_cuda " %} # [unix and cuda_compiler_version != "None"]
{% set skips = skips ~ " or (TestTorch and test_index_add_correctness)" %} # [unix and cuda_compiler_version != "None"]
# These tests require higher-resource or more recent GPUs than the CI provides
{% set skips = skips ~ " or (TritonCodeGenTests and test_sdpa_inference_mode_aot_compile)" %} # [unix and cuda_compiler_version != "None"]
{% set skips = skips ~ " or (TestNN and test_grid_sample)" %} # [unix and cuda_compiler_version != "None"]
{% set skips = skips ~ " or test_sdpa_inference_mode_aot_compile" %} # [linux and cuda_compiler_version != "None"]
{% set skips = skips ~ " or (TestNN and test_grid_sample)" %} # [linux and cuda_compiler_version != "None"]
# don't mess with tests that rely on GPU failure handling
{% set skips = skips ~ " or test_indirect_device_assert" %} # [linux and cuda_compiler_version != "None"]
# test that fails to find temporary resource
{% set skips = skips ~ " or (GPUTests and test_scatter_reduce2)" %} # [linux and cuda_compiler_version != "None"]
# MKL problems
{% set skips = skips ~ " or (TestLinalgCPU and test_inverse_errors_large_cpu)" %} # [unix and blas_impl == "mkl" and cuda_compiler_version != "None"]
# these tests are failing with low -n values
Expand Down Expand Up @@ -546,6 +554,7 @@ about:
license_file:
- LICENSE
- NOTICE
- third_party/CMake/Copyright.txt
summary: PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.
description: |
PyTorch is a Python package that provides two high-level features:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f3a0f9aab6dce56eea590b946f60256014b61bf7 Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
Date: Sun, 1 Sep 2024 17:35:40 -0400
Subject: [PATCH 01/19] Force usage of python 3 and error without numpy
Subject: [PATCH 01/21] Force usage of python 3 and error without numpy

---
cmake/Dependencies.cmake | 6 +++---
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0002-Help-find-numpy.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 21c30036b5b86f403c0cf4426165d9a6a50edb1a Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
Date: Tue, 1 Oct 2024 00:28:40 -0400
Subject: [PATCH 02/19] Help find numpy
Subject: [PATCH 02/21] Help find numpy

---
tools/setup_helpers/cmake.py | 6 ++++++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d1826af525db41eda5020a1404f5d5521d67a5dc Mon Sep 17 00:00:00 2001
From: Jeongseok Lee <jeongseok@meta.com>
Date: Sat, 19 Oct 2024 04:26:01 +0000
Subject: [PATCH 03/19] Add USE_SYSTEM_NVTX option (#138287)
Subject: [PATCH 03/21] Add USE_SYSTEM_NVTX option (#138287)

## Summary

Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0004-Update-sympy-version.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e3219c5fe8834753b0cf9e92be4d1ef1e874f370 Mon Sep 17 00:00:00 2001
From: Jeongseok Lee <jeongseok@meta.com>
Date: Thu, 17 Oct 2024 15:04:05 -0700
Subject: [PATCH 04/19] Update sympy version
Subject: [PATCH 04/21] Update sympy version

---
setup.py | 2 +-
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0005-Fix-duplicate-linker-script.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 08a1f44fbc81324aa98d720dfb7b87a261923ac2 Mon Sep 17 00:00:00 2001
From: Jeongseok Lee <jeongseok@meta.com>
Date: Sun, 3 Nov 2024 01:12:36 -0700
Subject: [PATCH 05/19] Fix duplicate linker script
Subject: [PATCH 05/21] Fix duplicate linker script

---
setup.py | 4 +++-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 15df314a41c69a31c0443254d5552aa1b39d708d Mon Sep 17 00:00:00 2001
From: William Wen <williamwen@meta.com>
Date: Fri, 13 Sep 2024 13:02:33 -0700
Subject: [PATCH 06/19] fix 3.13 pickle error in serialization.py (#136034)
Subject: [PATCH 06/21] fix 3.13 pickle error in serialization.py (#136034)

Error encountered when adding dynamo 3.13 support.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136034
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 655f694854c3eafdd631235b60bc6c1b279218ed Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
Date: Thu, 3 Oct 2024 22:49:56 -0400
Subject: [PATCH 07/19] Allow users to overwrite ld with environment variables
Subject: [PATCH 07/21] Allow users to overwrite ld with environment variables

This should help in the case of cross compilation.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f03bf82d9da9cccb2cf4d4833c1a6349622dc37d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Wed, 27 Nov 2024 13:47:23 +0100
Subject: [PATCH 08/19] Allow overriding CUDA-related paths
Subject: [PATCH 08/21] Allow overriding CUDA-related paths

---
cmake/Modules/FindCUDAToolkit.cmake | 2 +-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 4b1faf6ba142953ce2730766db44f8d98d161ef0 Mon Sep 17 00:00:00 2001
From: Haifeng Jin <haifeng-jin@users.noreply.github.com>
Date: Tue, 1 Oct 2024 07:53:24 +0000
Subject: [PATCH 09/19] Fix test/test_linalg.py for NumPy 2 (#136800)
Subject: [PATCH 09/21] Fix test/test_linalg.py for NumPy 2 (#136800)

Related to #107302.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 032b9be9ca7f9ae174e75554cecc82600ea3ef54 Mon Sep 17 00:00:00 2001
From: Haifeng Jin <haifeng-jin@users.noreply.github.com>
Date: Sat, 12 Oct 2024 02:40:17 +0000
Subject: [PATCH 10/19] Fixes NumPy 2 test failures in test_torch.py (#137740)
Subject: [PATCH 10/21] Fixes NumPy 2 test failures in test_torch.py (#137740)

Related to #107302

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 56f1528fa072023fb2724d5abf8790f2f6cc3aaa Mon Sep 17 00:00:00 2001
From: Isuru Fernando <ifernando@quansight.com>
Date: Wed, 18 Dec 2024 03:59:00 +0000
Subject: [PATCH 11/19] Use BLAS_USE_CBLAS_DOT for OpenBLAS builds
Subject: [PATCH 11/21] Use BLAS_USE_CBLAS_DOT for OpenBLAS builds

There are two calling conventions for *dotu functions

Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0012-fix-issue-142484.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From beba58d724cc1bd7ca73660b0a5ad9e61ae0c562 Mon Sep 17 00:00:00 2001
From: "Zheng, Zhaoqiong" <zhaoqiong.zheng@intel.com>
Date: Fri, 27 Dec 2024 13:49:36 +0800
Subject: [PATCH 12/19] fix issue 142484
Subject: [PATCH 12/21] fix issue 142484

From https://github.com/pytorch/pytorch/pull/143894
---
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0013-Fix-FindOpenBLAS.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 816a248a4425a97350959e412666e6db9012a52e Mon Sep 17 00:00:00 2001
From: Bas Zalmstra <bas@prefix.dev>
Date: Thu, 16 May 2024 10:46:49 +0200
Subject: [PATCH 13/19] Fix FindOpenBLAS
Subject: [PATCH 13/21] Fix FindOpenBLAS

---
cmake/Modules/FindOpenBLAS.cmake | 15 +++++++++------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From db896f927403f55a18f931b18a6469cb4e37d322 Mon Sep 17 00:00:00 2001
From: atalman <atalman@fb.com>
Date: Tue, 12 Nov 2024 12:28:10 +0000
Subject: [PATCH 14/19] CD Enable Python 3.13 on windows (#138095)
Subject: [PATCH 14/21] CD Enable Python 3.13 on windows (#138095)

Adding CD windows. Part of: https://github.com/pytorch/pytorch/issues/130249
Builder PR landed with smoke test: https://github.com/pytorch/builder/pull/2035
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 33790dfbf966e7d8ea4ff6798d2ff92474d84079 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Thu, 23 Jan 2025 22:46:58 +1100
Subject: [PATCH 15/19] simplify torch.utils.cpp_extension.include_paths; use
Subject: [PATCH 15/21] simplify torch.utils.cpp_extension.include_paths; use
it in cpp_builder

The /TH headers have not existed since pytorch 1.11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 799f6fa59dac93dabbbcf72d46f4e1334e3d65d9 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Thu, 23 Jan 2025 22:58:14 +1100
Subject: [PATCH 16/19] point include paths to $PREFIX/include
Subject: [PATCH 16/21] point include paths to $PREFIX/include

---
torch/utils/cpp_extension.py | 9 +++++++++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 9f73a02bacf9680833ac64657fde6762d33ab200 Mon Sep 17 00:00:00 2001
From: Daniel Petry <dpetry@anaconda.com>
Date: Tue, 21 Jan 2025 17:45:23 -0600
Subject: [PATCH 17/19] Add conda prefix to inductor include paths
Subject: [PATCH 17/21] Add conda prefix to inductor include paths

Currently inductor doesn't look in conda's includes and libs. This results in
errors when it tries to compile, if system versions are being used of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b0cfa0f728e96a3a9d6f7434e2c02d74d6daa9a9 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Tue, 28 Jan 2025 14:15:34 +1100
Subject: [PATCH 18/19] make ATEN_INCLUDE_DIR relative to TORCH_INSTALL_PREFIX
Subject: [PATCH 18/21] make ATEN_INCLUDE_DIR relative to TORCH_INSTALL_PREFIX

we cannot set CMAKE_INSTALL_PREFIX without the pytorch build complaining, but we can
use TORCH_INSTALL_PREFIX, which is set correctly relative to our CMake files already:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f7db4cbfb0af59027ed8bdcd0387dba6fbcb1192 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Tue, 28 Jan 2025 10:58:29 +1100
Subject: [PATCH 19/19] remove `DESTINATION lib` from CMake `install(TARGETS`
Subject: [PATCH 19/21] remove `DESTINATION lib` from CMake `install(TARGETS`
directives

Suggested-By: Silvio Traversaro <silvio@traversaro.it>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 79ee5dcac30f2eba891af961f7649d15dfc6ce63 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Thu, 30 Jan 2025 13:23:14 +1100
Subject: [PATCH 20/21] make library name in
`test_mutable_custom_op_fixed_layout{,2}` unique

Suggested-By: Daniel Petry <dpetry@anaconda.com>
---
test/inductor/test_torchinductor.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/test/inductor/test_torchinductor.py b/test/inductor/test_torchinductor.py
index 610f5d27332..28f85e228d2 100644
--- a/test/inductor/test_torchinductor.py
+++ b/test/inductor/test_torchinductor.py
@@ -10628,7 +10628,8 @@ class CommonTemplate:
@requires_gpu()
@config.patch(implicit_fallbacks=True)
def test_mutable_custom_op_fixed_layout2(self):
- with torch.library._scoped_library("mylib", "DEF") as lib:
+ unique_lib_name = f"mylib_{id(self)}" # Make unique name using test instance id
+ with torch.library._scoped_library(unique_lib_name, "DEF") as lib:
mod = nn.Conv2d(3, 128, 1, stride=1, bias=False).to(device=GPU_TYPE)
inp = torch.rand(2, 3, 128, 128, device=GPU_TYPE)
expected_stride = mod(inp).clone().stride()
@@ -10681,7 +10682,8 @@ class CommonTemplate:

@config.patch(implicit_fallbacks=True)
def test_mutable_custom_op_fixed_layout(self):
- with torch.library._scoped_library("mylib", "DEF") as lib:
+ unique_lib_name = f"mylib_{id(self)}" # Make unique name using test instance id
+ with torch.library._scoped_library(unique_lib_name, "DEF") as lib:
lib.define(
"copy_(Tensor(a!) dst, Tensor src) -> ()",
tags=torch.Tag.needs_fixed_stride_order,
Loading

0 comments on commit 0819140

Please sign in to comment.