Сравнение pytorch-2.12.0 с pytorch-2.13.0-r3

/usr/portage/sci-ml/pytorch/pytorch-2.13.0-r3.ebuild 2026-08-13 20:03:04.539001838 +0300
4 4
EAPI=8
5 5

  
6 6
DISTUTILS_USE_PEP517=setuptools
7
PYTHON_COMPAT=( python3_{11..14} )
7
PYTHON_COMPAT=( python3_{12..14} )
8 8
DISTUTILS_SINGLE_IMPL=1
9 9
DISTUTILS_EXT=1
10
inherit distutils-r1 prefix
11 10

  
12
DESCRIPTION="Tensors and Dynamic neural networks in Python"
11
ROCM_VERSION=6.1
12
inherit distutils-r1 prefix cuda flag-o-matic rocm multiprocessing
13

  
14
# pytorch-2.13.0 depends on specific commit of composable kernel
15
# TODO: replace it with DEPEND in the future
16
CK_COMMIT=f1746955fdaf80a3414de814bf32437686dac347
17
CK_P=composable_kernel-${CK_COMMIT:0:8}
18

  
19
# Starting from 2.7.0 pytorch moved flash attention out-of-tree,
20
# but hardcoded it as third_party subproject
21
# TODO: unbundle
22
FLASH_PV=2.7.4
23
FLASH_PN=flash-attention
24
FLASH_P=${FLASH_PN}-${FLASH_PV}
25
FLASH_ATT_URI="https://github.com/Dao-AILab/${FLASH_PN}/archive/refs/tags/v${FLASH_PV}.tar.gz -> ${FLASH_P}.gh.tar.gz"
26

  
27
DESCRIPTION="Tensors and Dynamic neural networks in Python with strong GPU acceleration"
13 28
HOMEPAGE="https://pytorch.org/"
14 29
SRC_URI="https://github.com/pytorch/${PN}/archive/refs/tags/v${PV}.tar.gz
15
	-> ${P}.tar.gz"
30
	-> ${P}.tar.gz
31
	rocm? (
32
		https://github.com/ROCm/composable_kernel/archive/${CK_COMMIT}.tar.gz
33
		-> ${CK_P}.tar.gz
34
	)
35
	cuda? (
36
		flash? ( ${FLASH_ATT_URI} )
37
		memefficient? ( ${FLASH_ATT_URI} )
38
	)
39
"
16 40

  
17 41
LICENSE="BSD"
18 42
SLOT="0"
19 43
KEYWORDS="~amd64 ~arm64"
44
IUSE="cuda cusparselt distributed fbgemm flash gloo kineto memefficient
45
	mimalloc mkl mpi nccl nnpack +numpy onednn openblas opencl openmp qnnpack
46
	rocm xnnpack"
20 47
RESTRICT="test"
21 48

  
22
REQUIRED_USE=${PYTHON_REQUIRED_USE}
49
REQUIRED_USE="
50
	${PYTHON_REQUIRED_USE}
51
	mpi? ( distributed )
52
	gloo? ( distributed )
53
	?? ( cuda rocm )
54
	rocm? (
55
		|| ( ${ROCM_REQUIRED_USE} )
56
		memefficient? ( flash )
57
	)
58
	cusparselt? ( || ( cuda rocm ) )
59
	flash? ( || ( cuda rocm ) )
60
	memefficient? ( || ( cuda rocm ) )
61
	nccl? ( rocm )
62
"
63

  
23 64
RDEPEND="
24 65
	${PYTHON_DEPS}
25
	~sci-ml/caffe2-${PV}[${PYTHON_SINGLE_USEDEP}]
66
	!sci-ml/caffe2
67
	dev-cpp/abseil-cpp:=
68
	dev-cpp/gflags:=
69
	>=dev-cpp/glog-0.6.0:=
70
	>=dev-libs/cpuinfo-2025.11.14
71
	dev-libs/libfmt:=
72
	dev-libs/protobuf:=
73
	dev-libs/sleef
74
	sci-ml/onnx
26 75
	$(python_gen_cond_dep '
27 76
		dev-python/sympy[${PYTHON_USEDEP}]
28 77
		dev-python/typing-extensions[${PYTHON_USEDEP}]
29 78
	')
79
	!mkl? ( !openblas? ( virtual/blas ) )
80
	cuda? (
81
		dev-libs/cudnn
82
		>=sci-ml/cudnn-frontend-1.12.0:=
83
		>=dev-util/nvidia-cuda-toolkit-12.9:=[profiler]
84
		cusparselt? ( dev-libs/cusparselt )
85
	)
86
	distributed? (
87
		!rocm? ( sci-ml/tensorpipe[cuda?] )
88
		dev-cpp/cpp-httplib:=
89
	)
90
	fbgemm? ( >=sci-ml/FBGEMM-1.4 )
91
	gloo? ( >=sci-ml/gloo-2025.06.04[cuda?,rocm?] )
92
	kineto? ( ~sci-ml/kineto-0.4.0_p20260603 )
93
	mimalloc? ( dev-libs/mimalloc )
94
	mkl? ( sci-libs/mkl )
95
	mpi? ( virtual/mpi )
96
	nnpack? (
97
		sci-ml/NNPACK
98
		dev-libs/pthreadpool
99
	)
100
	numpy? ( $(python_gen_cond_dep '
101
		dev-python/numpy[${PYTHON_USEDEP}]
102
	') )
103
	onednn? ( sci-ml/oneDNN )
104
	openblas? ( sci-libs/openblas )
105
	opencl? ( virtual/opencl )
106
	qnnpack? (
107
		!sci-libs/QNNPACK
108
		sci-ml/gemmlowp
109
		dev-libs/pthreadpool
110
	)
111
	rocm? (
112
		nccl? ( >=dev-libs/rccl-6.3:= <dev-libs/rccl-7.3:= )
113
		>=dev-util/hip-6.3:=       <dev-util/hip-7.3:=
114
		>=dev-util/roctracer-6.3:= <dev-util/roctracer-7.3:=
115
		>=sci-libs/hipBLAS-6.3:=   <sci-libs/hipBLAS-7.3:=[rocsolver(+)]
116
		>=sci-libs/hipBLASLt-6.3:= <sci-libs/hipBLASLt-7.3:=
117
		>=sci-libs/hipFFT-6.3:=    <sci-libs/hipFFT-7.3:=
118
		>=sci-libs/hipRAND-6.3:=   <sci-libs/hipRAND-7.3:=
119
		>=sci-libs/hipSOLVER-6.3:= <sci-libs/hipSOLVER-7.3:=
120
		>=sci-libs/hipSPARSE-6.3:= <sci-libs/hipSPARSE-7.3:=
121
		>=sci-libs/miopen-6.3:=    <sci-libs/miopen-7.3:=
122
		>=sci-libs/rocBLAS-6.3:=   <sci-libs/rocBLAS-7.3:=
123
		>=sci-libs/rocRAND-6.3:=   <sci-libs/rocRAND-7.3:=
124
		>=sci-libs/rocSOLVER-6.3:= <sci-libs/rocSOLVER-7.3:=
125
		memefficient? ( =sci-libs/aotriton-bin-0.13*:= )
126
		distributed? (
127
			>=dev-util/rocm-smi-6.3:= <dev-util/rocm-smi-7.3:=
128
			>=dev-util/amdsmi-6.3:= <dev-util/amdsmi-7.3:=
129
		)
130
		cusparselt? ( >=sci-libs/hipsparselt-6.3:= <sci-libs/hipsparselt-7.3:= )
131
	)
132
	xnnpack? (
133
		>=sci-ml/XNNPACK-2024.11
134
		dev-libs/pthreadpool
135
	)
30 136
"
31
DEPEND="${RDEPEND}
137

  
138
DEPEND="
139
	${RDEPEND}
140
	dev-cpp/nlohmann_json
141
	dev-libs/flatbuffers
142
	dev-libs/FXdiv
143
	dev-libs/pocketfft
144
	dev-libs/psimd
145
	sci-ml/FP16
32 146
	$(python_gen_cond_dep '
147
		<dev-python/pybind11-3.0.5[${PYTHON_USEDEP}]
33 148
		dev-python/pyyaml[${PYTHON_USEDEP}]
149
		dev-python/typing-extensions[${PYTHON_USEDEP}]
34 150
	')
151
	cuda? ( ~dev-libs/cutlass-4.4.2[tools(+)] )
152
	onednn? ( sci-ml/ideep )
153
	rocm? (
154
		>=sci-libs/hipCUB-6.3:=    <sci-libs/hipCUB-7.3:=
155
		>=sci-libs/rocPRIM-6.3:=   <sci-libs/rocPRIM-7.3:=
156
		>=sci-libs/rocThrust-6.3:= <sci-libs/rocThrust-7.3:=
157
	)
158
	qnnpack? ( dev-libs/clog )
35 159
"
36 160

  
161
BDEPEND="dev-build/cmake"
162

  
37 163
PATCHES=(
38
	"${FILESDIR}"/${PN}-2.9.0-dontbuildagain.patch
39
	"${FILESDIR}"/${PN}-2.10.0-cpp-extension-multilib.patch
164
	"${FILESDIR}"/${P}-aotriton-fixes.patch
165
	"${FILESDIR}"/${P}-glog.patch
166
	"${FILESDIR}"/${P}-removekineto-pr178960.patch
167
	"${FILESDIR}"/${P}-rocm-assert-fix.patch
168
	"${FILESDIR}"/${P}-unbundle_fbgemm.patch
169
	"${FILESDIR}"/${P}-unbundle_flatbuffers.patch
170
	"${FILESDIR}"/${P}-unbundle_fmt.patch
171
	"${FILESDIR}"/${P}-unbundle_fxdiv.patch
172
	"${FILESDIR}"/${P}-unbundle_httplib.patch
173
	"${FILESDIR}"/${P}-unbundle_kineto.patch
174
	"${FILESDIR}"/${P}-unbundle_mkldnn.patch
175
	"${FILESDIR}"/${P}-unbundle_nnpack.patch
176
	"${FILESDIR}"/${P}-unbundle_pocketfft.patch
177
	"${FILESDIR}"/${P}-xnnpack.patch
40 178
)
41 179

  
42 180
src_prepare() {
181
	if use cuda && ( use flash || use memefficient ); then
182
		mv "${WORKDIR}"/${FLASH_P}/* third_party/${FLASH_PN}/ || die
183
	fi
184
	filter-lto #bug 862672
185

  
186
	eapply "${FILESDIR}/${PN}-2.10.0-cpp-extension-multilib.patch"
43 187
	# Replace placeholders added by cpp-extension.patch
44 188
	sed -e "s|%LIB_DIR%|$(get_libdir)|g" \
45 189
		-i torch/utils/cpp_extension.py || die
46 190

  
47
	# Set build dir for pytorch's setup
48
	sed -e "/BUILD_DIR/s|build|/var/lib/caffe2/|" \
49
		-i tools/setup_helpers/env.py || die
50

  
51
	# Drop legacy from pyproject.toml
52
	sed -e "/build-backend/s|:__legacy__||" \
53
		-i pyproject.toml || die
191
	# Unbundle fmt
192
	sed -i \
193
		-e 's|::fmt-header-only||' \
194
		c10/CMakeLists.txt \
195
		cmake/Dependencies.cmake \
196
		torch/CMakeLists.txt \
197
		|| die
198

  
199
	# tensorpipe is in system, not a build target of pytorch
200
	sed -e '/target_compile_options_if_supported(tensorpipe/d' -i cmake/Dependencies.cmake || die
201

  
202
	# Drop third_party from CMake tree
203
	sed -i \
204
		-e '/add_subdirectory.*third_party/d' \
205
		CMakeLists.txt \
206
		cmake/Dependencies.cmake \
207
		cmake/ProtoBuf.cmake \
208
		aten/src/ATen/CMakeLists.txt \
209
		|| die
210

  
211
	# Add needed file for cutlass as symbolic link
212
	ln -sf /usr/share/cutlass/examples third_party/cutlass/examples || die
213

  
214
	# cudnn_frontend is unbundled, but some targets still look for its
215
	# headers under third_party/cudnn_frontend/include.
216
	mkdir -p third_party/cudnn_frontend || die
217
	ln -sf /usr/include third_party/cudnn_frontend/include || die
54 218

  
55 219
	distutils-r1_src_prepare
56 220

  
57
	hprefixify tools/setup_helpers/env.py
221
	# Noisy warnings from Logging.h
222
	sed -i 's/-Wextra-semi//' cmake/public/utils.cmake || die
223

  
224
	pushd torch/csrc/jit/serialization > /dev/null || die
225
	flatc --cpp --gen-mutable --scoped-enums mobile_bytecode.fbs || die
226
	popd > /dev/null || die
227

  
228
	# prefixify the hardcoded paths, after all patches are applied
229
	hprefixify \
230
		aten/CMakeLists.txt \
231
		caffe2/CMakeLists.txt \
232
		cmake/Metal.cmake \
233
		cmake/Modules/*.cmake \
234
		cmake/Modules_CUDA_fix/FindCUDNN.cmake \
235
		cmake/Modules_CUDA_fix/upstream/FindCUDA/make2cmake.cmake \
236
		cmake/Modules_CUDA_fix/upstream/FindPackageHandleStandardArgs.cmake \
237
		cmake/public/LoadHIP.cmake \
238
		cmake/public/cuda.cmake \
239
		cmake/Dependencies.cmake \
240
		tools/setup_helpers/env.py \
241
		torch/CMakeLists.txt \
242
		CMakeLists.txt
243

  
244
	if use rocm; then
245
		# TODO: delete, when caffe2 depends on systemwide composable_kernel
246
		sed -e "s:third_party/composable_kernel:../composable_kernel-${CK_COMMIT}:g" \
247
			-i aten/src/ATen/CMakeLists.txt || die
248

  
249
		# Workaround for libc++ issue https://github.com/llvm/llvm-project/issues/100802
250
		sed -e 's/std::memcpy/memcpy/g' \
251
			-i torch/headeronly/util/Half.h \
252
			-i aten/src/ATen/native/cuda/int4mm.cu || die
253

  
254
		ebegin "HIPifying cuda sources"
255
		FBCODE_BUILD_TOOL="buck" ${EPYTHON} tools/amd_build/build_amd.py || die
256
		eend $?
257
	fi
58 258
}
59 259

  
60
python_compile() {
61
	PYTORCH_BUILD_VERSION=${PV} \
62
	PYTORCH_BUILD_NUMBER=0 \
63
	USE_SYSTEM_LIBS=ON \
64
	CMAKE_BUILD_DIR="${BUILD_DIR}" \
65
	distutils-r1_python_compile develop sdist
260
src_configure() {
261
	if use cuda && [[ -z ${TORCH_CUDA_ARCH_LIST} ]]; then
262
		ewarn "WARNING: pytorch is being built with its default CUDA compute capabilities: 3.5 and 7.0."
263
		ewarn "These may not be optimal for your GPU."
264
		ewarn ""
265
		ewarn "To configure pytorch with the CUDA compute capability that is optimal for your GPU,"
266
		ewarn "set TORCH_CUDA_ARCH_LIST in your make.conf, and re-emerge pytorch."
267
		ewarn "For example, to use CUDA capability 7.5 & 3.5, add: TORCH_CUDA_ARCH_LIST=7.5 3.5"
268
		ewarn "For a Maxwell model GPU, an example value would be: TORCH_CUDA_ARCH_LIST=Maxwell"
269
		ewarn ""
270
		ewarn "You can look up your GPU's CUDA compute capability at https://developer.nvidia.com/cuda-gpus"
271
		ewarn "or by running /opt/cuda/extras/demo_suite/deviceQuery | grep 'CUDA Capability'"
272
	fi
66 273
}
67 274

  
68
python_install() {
69
	USE_SYSTEM_LIBS=ON distutils-r1_python_install
275
python_compile() {
276
	local -x BUILD_TEST=OFF
277
	local -x CMAKE_BUILD_DIR="${BUILD_DIR}"
278
	local -x MAX_JOBS=$(makeopts_jobs)
279
	local -x PYTORCH_BUILD_VERSION=${PV}
280
	local -x PYTORCH_BUILD_NUMBER=0
281
	local -x USE_CCACHE=OFF
282
	local -x USE_CUDA=$(usex cuda)
283
	local -x USE_DISTRIBUTED=$(usex distributed)
284
	local -x USE_FBGEMM=$(usex fbgemm)
285
	local -x USE_FLASH_ATTENTION=$(usex flash)
286
	local -x USE_GFLAGS=ON
287
	local -x USE_GLOG=ON
288
	local -x USE_GLOO=$(usex gloo)
289
	local -x USE_ITT=OFF
290
	local -x USE_KINETO=$(usex kineto)
291
	local -x USE_KLEIDIAI=OFF # TODO
292
	local -x USE_MAGMA=OFF # TODO: In GURU as sci-libs/magma
293
	local -x USE_MEM_EFF_ATTENTION=$(usex memefficient)
294
	local -x USE_MIMALLOC=$(usex mimalloc)
295
	local -x USE_MKLDNN=$(usex onednn)
296
	local -x USE_MPI=$(usex mpi)
297
	local -x USE_NNPACK=$(usex nnpack)
298
	local -x USE_NUMA=OFF
299
	local -x USE_NUMPY=$(usex numpy)
300
	local -x USE_OPENCL=$(usex opencl)
301
	local -x USE_OPENMP=$(usex openmp)
302
	local -x USE_PYTORCH_QNNPACK=$(usex qnnpack)
303
	local -x USE_PYTORCH_METAL=OFF
304
	local -x USE_ROCM=$(usex rocm)
305
	local -x USE_SYSTEM_LIBS=ON
306
	local -x USE_SYSTEM_XNNPACK=$(usex xnnpack)
307
	local -x USE_TENSORPIPE=$(usex distributed $(usex !rocm))
308
	local -x DUSE_UCC=OFF
309
	local -x USE_VALGRIND=OFF
310
	local -x USE_XNNPACK=$(usex xnnpack)
311
	local -x USE_XPU=OFF
312

  
313
	if use mkl; then
314
		local -x USE_BLAS=ON
315
		local -x BLAS=MKL
316
	elif use openblas; then
317
		local -x USE_BLAS=ON
318
		local -x BLAS=OpenBLAS
319
	else
320
		# Note: USE_BLAS=OFF does not properly work, instead pytorch still searches for libraries.
321
		# Even though it is easy to patch pytorch to disable BLAS usage completely,
322
		# it is practically not useful, as it would render the library barely usable.
323
		local -x USE_BLAS=ON
324
		local -x BLAS=Generic
325
		local -x GENERIC_BLAS_LIBRARIES=cblas
326
	fi
327

  
328
	if use cuda; then
329
		# bug 867706 926116
330
		cuda_add_sandbox
331
		addpredict "/dev/char/"
332

  
333
		local -x CMAKE_CUDA_FLAGS="$(cuda_gccdir -f | tr -d \")"
334
		local -x TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST:-7.0}"
335
		local -x USE_CUDNN=ON
336
		local -x USE_FLASH_ATTENTION=OFF
337
		local -x USE_MEM_EFF_ATTENTION=OFF
338
		local -x USE_NCCL=OFF # TODO: NVIDIA Collective Communication Library
339

  
340
	elif use rocm; then
341
		export PYTORCH_ROCM_ARCH="$(get_amdgpu_flags)"
342

  
343
		if use memefficient; then
344
			export AOTRITON_INSTALLED_PREFIX="${ESYSROOT}/usr"
345
		fi
346

  
347
		local -x CMAKE_REQUIRE_FIND_PACKAGE_HIP=ON
348
		local -x USE_NCCL=$(usex nccl)
349
		local -x CMAKE_DISABLE_FIND_PACKAGE_hipsparselt=$(usex !cusparselt) # disable automagic
350
		local -x USE_ROCM_CK_SDPA=OFF # requires flash + aiter, works only on gfx90a/gfx942/gfx950
351
		local -x ROCM_PATH=/usr
352
		local -x HIP_CLANG_PATH=$(hipconfig --hipclangpath)
353

  
354
		# ROCm libraries produce too much warnings
355
		append-cxxflags -Wno-deprecated-declarations -Wno-unused-result -Wno-unused-value
356
	else
357
		local -x USE_NCCL=OFF
358
	fi
359

  
360
	distutils-r1_python_compile develop sdist
70 361
}
Спасибо!