Repository navigation
Expand file tree
/
Copy pathpython-torch.spec
More file actions
334 lines (319 loc) · 14.2 KB
/
Copy pathpython-torch.spec
File metadata and controls
334 lines (319 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# Official PyTorch source bundle, compiled here. Never install a
# PyPI manylinux wheel: those are libstdc++ and rpm will not own them.
%undefine _debugsource_packages
# LTO of libtorch_cpu + 1.2G libdnnl OOMs linkers on 64G hosts.
# Imperative build (not declarative python) so CFLAGS are not
# re-injected with flto from distro optflags.
%global _lto_cflags %{nil}
# Strip flto tokens from optflags (no rpm-conditional '?' in sed).
%global torch_cflags %(printf '%%s' '%{optflags}' | sed -e 's/-flto=thin//g' -e 's/-flto//g')
# gfx9xx (Vega20 / MI50 / MI200 / MI300) + RDNA2/3/4.
# Skip gfx803 (Polaris): PyTorch 2.14 has no real Polaris kernels;
# ggml / hipBLAS still cover RX 550. hipBLASLt only has navi3x/4x.
%global torch_rocm_arch gfx906;gfx908;gfx90a;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1200;gfx1201
Name: python-torch
Version: 2.14.1
Release: 3
Summary: PyTorch machine learning framework
License: BSD-3-Clause
Group: Development/Python
URL: https://pytorch.org
# Full source bundle from the PyTorch project. The GitHub tag archive
# omits third_party submodules needed to compile.
Source0: https://github.com/pytorch/pytorch/releases/download/v%{version}/pytorch-v%{version}.tar.gz
# Walks every vendored CK copy (mslk / flash-attn / aiter) after Patch5.
Source1: pytorch-2.14.0-ck-clang23.py
# LLD/mold: skip GNU-ld-only --stub-group-size; prioritized-text
# uses --symbol-ordering-file instead of a BFD -T script.
Patch0: pytorch-2.14.0-lld-compat.patch
# TheRock 10.0 has no roctracer libroctx64. ROCTx markers are optional.
Patch1: pytorch-2.14.0-optional-roctx.patch
# cmake_dependent_option ignores USE_FLASH_ATTENTION=0 from the env
# and git-clones aotriton_runtime (no network on ABF).
Patch2: pytorch-2.14.0-no-aotriton-fetch.patch
# HIP 7.15 reports as ROCm >= 7.14, so upstream requires hipfile.
# OMV does not ship that early-access GPU-direct I/O library yet.
# USE_CUFILE=1 below; this turns it back off when hipfile is missing.
Patch3: pytorch-2.14.0-optional-hipfile.patch
# 2.14 has no USE_SYSTEM_FMT; always builds third_party/fmt.
Patch4: pytorch-2.14.0-system-fmt.patch
# Clang 23 raw_buffer_* builtins are unsigned; CK still uses int32xN.
# Same class of fix as python-xformers 0001-ck-tile-clang23-rdna.patch.
Patch5: pytorch-2.14.0-ck-clang23.patch
# FHS ROCM_HOME=/usr must not add -L/usr/lib. That directory's libc.so
# linker script forces OUTPUT_FORMAT(elf32-i386) and rejects 64-bit objects.
Patch6: pytorch-2.14.1-skip-usr-lib.patch
BuildRequires: python
# find_package(Python COMPONENTS Development.Module) — without
# this cmake silently sets BUILD_PYTHON=OFF and the wheel has no
# torch/_C*.so (xformers 656372: Failed to load PyTorch C extensions).
BuildRequires: pkgconfig(python3)
BuildRequires: cmake
BuildRequires: ninja
BuildRequires: binutils
# 2.14's PEP 517 backend is scikit-build-core (setup.py is a shim).
BuildRequires: python%{pyver}dist(scikit-build-core)
BuildRequires: python%{pyver}dist(setuptools)
BuildRequires: python%{pyver}dist(wheel)
BuildRequires: python%{pyver}dist(pip)
BuildRequires: python%{pyver}dist(packaging)
BuildRequires: python%{pyver}dist(six)
BuildRequires: python%{pyver}dist(numpy)
BuildRequires: python%{pyver}dist(pyyaml)
BuildRequires: python%{pyver}dist(typing-extensions)
BuildRequires: python%{pyver}dist(jinja2)
BuildRequires: python%{pyver}dist(networkx)
BuildRequires: python%{pyver}dist(sympy)
BuildRequires: python%{pyver}dist(fsspec)
BuildRequires: python%{pyver}dist(filelock)
# 2.14 vendors fmt 12.2; 11.2 headers may compile but are untested.
BuildRequires: cmake(fmt) >= 12
# TheRock 10.0 (FHS /usr, not /opt/rocm). HIP language/ABI is 7.15.
BuildRequires: hipcc
# clang-linker-wrapper looks this up on PATH; hipcc only Requires clang.
BuildRequires: /usr/bin/clang-offload-bundler
BuildRequires: cmake(hip)
BuildRequires: cmake(hipblas)
BuildRequires: cmake(rocblas)
BuildRequires: cmake(miopen)
BuildRequires: cmake(hipfft)
BuildRequires: cmake(hiprand)
BuildRequires: cmake(hipsparse)
BuildRequires: cmake(hipsolver)
BuildRequires: cmake(rocsolver)
BuildRequires: cmake(hipblaslt)
BuildRequires: cmake(hiprtc)
BuildRequires: cmake(hipcub)
BuildRequires: cmake(rocprim)
BuildRequires: cmake(rocthrust)
BuildRequires: cmake(rocrand)
BuildRequires: cmake(amd_comgr)
BuildRequires: rocm-runtime-devel
BuildRequires: cmake(rocm_smi)
# rocm_smi-config.cmake does pkg_check_modules(libdrm REQUIRED).
BuildRequires: pkgconfig(libdrm)
# c10d/symm_mem/intra_node_comm.cpp includes <amd_smi/amdsmi.h>
BuildRequires: cmake(amd_smi)
# RCCL is the HIP NCCL. USE_RCCL depends on USE_NCCL; ROCm forces
# USE_SYSTEM_NCCL and find_package(rccl).
BuildRequires: cmake(rccl)
# Kineto on ROCm 7 links librocprofiler-sdk. The .so lives in lib64;
# find_library still searches the default lib dirs.
BuildRequires: cmake(rocprofiler-sdk)
# c10d MPI backend. OpenMPI lives under %{_libdir}/openmpi, not PATH.
BuildRequires: pkgconfig(ompi-cxx)
# ATen Vulkan (desktop): system loader + glslc for shader codegen.
BuildRequires: pkgconfig(vulkan)
BuildRequires: glslc
Requires: python%{pyver}dist(numpy)
Requires: python%{pyver}dist(typing-extensions)
Requires: python%{pyver}dist(filelock)
Requires: python%{pyver}dist(jinja2)
Requires: python%{pyver}dist(networkx)
Requires: python%{pyver}dist(fsspec)
Requires: python%{pyver}dist(sympy)
# c10 / torch.csrc headers include <fmt/...>; cpp_extension builds
# need the system headers (we no longer install bundled fmt).
Requires: cmake(fmt) >= 12
# HIP/Vulkan .so deps come from the ELF generator. Recommend the
# pieces that are useful at runtime but not always DT_NEEDED.
Recommends: miopen%{?_isa}
Recommends: hipblaslt%{?_isa}
%description
Tensors and dynamic neural networks in Python. Compiled from the
official pytorch-v%{version} source tarball (not a PyPI wheel).
2.14 brings NVGEMM (CuTeDSL CUTLASS kernels in Inductor), a new
nccl2 distributed backend, first-class c10d fault tolerance,
torch.switch / CUDA-graphable while_loop, @dynamic_spec dynamic
shapes, and experimental torch.compile for complex tensors.
Official wheels target ROCm 7.14 via TheRock; this package is
built against TheRock 10.0 (HIP 7.15).
GPU:
* ROCm/HIP — AMD (gfx906, gfx908, gfx90a, gfx942, gfx1030,
gfx1100–1102, gfx1200–1201). This is torch.cuda on Radeon /
Instinct (ComfyUI, Krita AI).
* Vulkan — ATen compute backend (Intel / AMD / wherever a
Vulkan 1.x driver exists). Not the Intel XPU/SYCL stack.
CUDA is off. Flash-attention/AOTriton is off (it downloads
prebuilt images; ABF has no network). LTO is off (libtorch
link OOMs with full LTO on 64G builders). Distributed is
on (Gloo + RCCL + MPI). Kineto (ROCm profiler) is on.
Bundled CK GEMM/SDPA/MSLK are on (Clang 23 raw_buffer_*
signedness patched). hipFile is not packaged: USE_CUFILE
is requested and then turned off at configure if hipfile
is missing.
%prep
%autosetup -C -n pytorch-v%{version} -p1
# Patch5 covers third_party/composable_kernel. Other vendored CK
# trees (mslk, flash-attn, aiter, fbgemm) get the same rewrite.
python %{SOURCE1} .
%build
# HIP fat binaries × 10 gfx* are RAM-heavy.
# MAX_JOBS is setup.py-era; 2.14's scikit-build-core runs
# cmake --build, which honours CMAKE_BUILD_PARALLEL_LEVEL
# (otherwise ninja uses every core and ABF x86_64 OOMs).
export MAX_JOBS=4
export CMAKE_BUILD_PARALLEL_LEVEL=4
# HIP offload-bundler temps for 10 arches overflow a 32G /tmp tmpfs
# ("No space left on device"). Keep scratch on the build disk.
export TMPDIR=%{_builddir}/.torch-tmp
export TEMP="$TMPDIR"
export TMP="$TMPDIR"
mkdir -p "$TMPDIR"
export CFLAGS='%{torch_cflags}'
export CXXFLAGS='%{torch_cflags}'
# --no-undefined is in distro ldflags. libtorch_python is a Python
# extension: CPython symbols resolve at import time, so LLD must
# allow them. --allow-shlib-undefined is the inverse.
export LDFLAGS="$(printf '%s' '%{?__global_ldflags}' | sed -e 's/-flto=thin//g' -e 's/-flto//g' -e 's/-Wl,--no-undefined//g' -e 's/--no-undefined//g') -Wl,--allow-shlib-undefined"
# OpenMPI wrappers are not on the default PATH.
export PATH=%{_libdir}/openmpi/bin${PATH:+:$PATH}
export MPI_HOME=%{_libdir}/openmpi
export USE_DISTRIBUTED=1
export USE_GLOO=1
export USE_MPI=1
export USE_MKLDNN=1
export USE_NNPACK=0
export USE_QNNPACK=0
export USE_XNNPACK=1
export USE_FBGEMM=0
export USE_KINETO=1
export BUILD_TEST=0
export USE_ITT=0
export USE_OBSERVERS=0
export USE_CUDA=0
export USE_CUDNN=0
# NCCL is the API name; RCCL is the HIP implementation.
# cmake_dependent_option(USE_RCCL) requires USE_NCCL.
# ROCm then forces USE_SYSTEM_NCCL and find_package(rccl).
export USE_NCCL=1
export USE_SYSTEM_NCCL=1
export USE_RCCL=1
export USE_ROCM=1
export USE_VULKAN=1
# Clang 23 signedness of raw_buffer_* is patched (Patch5 + Source1).
export USE_ROCM_CK_GEMM=1
export USE_ROCM_CK_SDPA=1
export USE_MSLK=1
# AOTriton is fetched from GitHub; builders are offline.
export USE_FLASH_ATTENTION=0
export USE_MEM_EFF_ATTENTION=0
# Requested; Patch3 turns this off when hipfile is not installed.
export USE_CUFILE=1
export USE_HIPSPARSELT=0
# Distro fmt 11 (fmt::fmt-header-only); skip third_party/fmt.
export USE_SYSTEM_FMT=1
# OMV ROCm is FHS, not /opt/rocm. hipcc / clang++ live in /usr/bin.
export ROCM_PATH=%{_prefix}
export HIP_CLANG_PATH=%{_bindir}
export HIP_DEVICE_LIB_PATH=%{_libdir}/amdgcn/bitcode
export PYTORCH_ROCM_ARCH='%{torch_rocm_arch}'
export CMAKE_FRESH=1
# hipcub/rocthrust/rccl *-config.cmake hardcode ${prefix}/lib/cmake
# (Fedora lib) instead of lib64. 2.14's EnvVarForwarding prepends
# Python sys.prefix (/usr) onto CMAKE_PREFIX_PATH, so the system
# /usr/lib64/cmake/hipcub/config wins and then dies looking for
# /usr/lib/cmake/hipcub/targets. Force find_package onto a shadow
# whose config includes the real lib64 targets file.
_cmpre=%{_builddir}/rocm-prefix
mkdir -p "$_cmpre/include"
# Hipify rewrites nvToolsExt.h to roctracer/roctx.h. ROCTx now lives in
# rocprofiler-sdk-roctx/roctx.h, which already macros the unsuffixed names.
mkdir -p "$_cmpre/include/roctracer"
printf '%s\n' '#include <rocprofiler-sdk-roctx/roctx.h>' > "$_cmpre/include/roctracer/roctx.h"
for pkg in hipcub rocthrust rccl; do
mkdir -p "$_cmpre/%{_lib}/cmake/${pkg}"
/bin/cp -f /usr/%{_lib}/cmake/${pkg}/${pkg}-config.cmake \
/usr/%{_lib}/cmake/${pkg}/${pkg}-config-version.cmake \
"$_cmpre/%{_lib}/cmake/${pkg}/"
for f in /usr/%{_lib}/cmake/${pkg}/${pkg}-targets*.cmake; do
[ -f "$f" ] || continue
ln -sfn "$f" "$_cmpre/%{_lib}/cmake/${pkg}/"
done
sed -i -e "s|\${PACKAGE_PREFIX_DIR}/lib/cmake/${pkg}/|\${CMAKE_CURRENT_LIST_DIR}/|g" \
"$_cmpre/%{_lib}/cmake/${pkg}/${pkg}-config.cmake"
done
# rccl-targets.cmake sets IMPORTED_LOCATION to ${_IMPORT_PREFIX}/lib/librccl.so.*.
# The shadow makes that prefix rocm-prefix, and the real library is in lib64.
mkdir -p "$_cmpre/lib"
for so in %{_libdir}/librccl.so*; do
[ -e "$so" ] || continue
ln -sfn "$so" "$_cmpre/lib/${so##*/}"
done
export hipcub_DIR="$_cmpre/%{_lib}/cmake/hipcub"
export rocthrust_DIR="$_cmpre/%{_lib}/cmake/rocthrust"
export rccl_DIR="$_cmpre/%{_lib}/cmake/rccl"
# scikit-build-core 1.0 prepends /usr via sys.prefix; CMAKE_ARGS
# is the reliable way to pin PackageName_DIR past that.
# LoadHIP caches ROCM_VERSION_HEADER_PATH at hip/hip_version.h
# (HIP_VERSION_*). Kineto reuses that cache and only accepts
# ROCM_VERSION_*, so pin it to the stub below.
export ROCM_VERSION_HEADER_PATH="$_cmpre/include/rocm-core/rocm_version.h"
export CMAKE_ARGS="${CMAKE_ARGS:+$CMAKE_ARGS }-Dhipcub_DIR=$hipcub_DIR -Drocthrust_DIR=$rocthrust_DIR -Drccl_DIR=$rccl_DIR -DROCM_VERSION_HEADER_PATH=$ROCM_VERSION_HEADER_PATH -DCMAKE_CXX_SCAN_FOR_MODULES=OFF"
ln -sfn %{_includedir}/hipcub "$_cmpre/include/hipcub"
ln -sfn %{_includedir}/thrust "$_cmpre/include/thrust"
ln -sfn %{_includedir}/rocprim "$_cmpre/include/rocprim"
# HIP host_defines.h sets `#define __noinline__` (empty) for host C++.
# libstdc++ 16 / libc++ then break: [[__gnu__::__noinline__]] and
# __has_attribute(__noinline__). Copy the hip headers (quoted
# #include "host_defines.h" ignores a shadow) and undo the empty
# macro for host TUs only.
cp -a %{_includedir}/hip "$_cmpre/include/hip"
cat >> "$_cmpre/include/hip/amd_detail/host_defines.h" <<'EOF'
#if !defined(__HIP__)
#ifdef __noinline__
#undef __noinline__
#endif
#endif
EOF
# TheRock 10.0 OMV packages do not ship rocm-core/rocm_version.h
# (only a leftover /opt/rocm-*). TunableOp includes it on Linux.
# Report the HIP API level (7.15), not the TheRock package number,
# so feature checks stay on the ABI we actually have.
mkdir -p "$_cmpre/include/rocm-core"
cat > "$_cmpre/include/rocm-core/rocm_version.h" <<'EOF'
/* OMV FHS stub — TheRock 10.0 packaging stream, HIP 7.15 ABI. */
#ifndef _ROCM_VERSION_H_
#define _ROCM_VERSION_H_
#define ROCM_VERSION_MAJOR 7
#define ROCM_VERSION_MINOR 15
#define ROCM_VERSION_PATCH 0
#define ROCM_BUILD_INFO "10.0.0-openmandriva"
#endif
EOF
export CMAKE_PREFIX_PATH="$_cmpre${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"
# Release tarball is not a git checkout; without these, setup.py /
# scikit-build-core names the dist 2.14.0a0+gitunknown.
export PYTORCH_BUILD_VERSION=%{version}
export PYTORCH_BUILD_NUMBER=%{release}
if [ -f version.txt ]; then
echo "%{version}" > version.txt
fi
# Official ROCm step: hipify CUDA → HIP in-place (THC→THH,
# aten/src/ATen/hip/HIPConfig.h.in, c10/hip, …) before cmake.
python tools/amd_build/build_amd.py
test -d aten/src/THH
test -f aten/src/ATen/hip/HIPConfig.h.in
mkdir -p ../RPMBUILD_wheels
CFLAGS='%{torch_cflags}' CXXFLAGS='%{torch_cflags}' \
pip wheel --wheel-dir ../RPMBUILD_wheels --no-deps --no-build-isolation --verbose .
%install
pip install --root=%{buildroot} --no-deps --verbose --ignore-installed \
--no-warn-script-location --no-index --no-cache-dir \
--find-links ../RPMBUILD_wheels ../RPMBUILD_wheels/*.whl
# cmake writes gitignored torch/version.py; the wheel may omit it.
# Without it `import torch` dies (xformers 655854).
python -m tools.generate_torch_version --is-debug=0 \
--hip-version=7.15 --rocm-version=10.0.0
install -m 644 torch/version.py %{buildroot}%{python_sitearch}/torch/version.py
%files
%license LICENSE
%doc README.md NOTICE
%{_bindir}/torchrun
%{_bindir}/torchfrtrace
# With BUILD_PYTHON=ON the wheel also installs the compat functorch/
# package (earlier HIP builds omitted it; 2.13.0-5 then failed %files).
%{python_sitearch}/functorch
%{python_sitearch}/torch
%{python_sitearch}/torchgen
%{python_sitearch}/torch-%{version}*.dist-info