repo/gentoo:master commit in: sci-ml/pytorch/files/, sci-ml/pytorch/

"Alfredo Tupone" <[email protected]> Tue, 04 Aug 2026 18:51:07 +0000 (UTC)
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1785869325.1ecb7f75309cb3d0fbf87f3e5950575cb6460c75.tupone@gentoo>
commit:     1ecb7f75309cb3d0fbf87f3e5950575cb6460c75
Author:     Sv. Lockal <lockalsash <AT> gmail <DOT> com>
AuthorDate: Tue Aug  4 18:22:47 2026 +0000
Commit:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
CommitDate: Tue Aug  4 18:48:45 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1ecb7f75

sci-ml/pytorch: fix rocm flash/memefficient builds

pytorch 2.13.0 requires aotriton==0.13b

Also:
- cpp-extension-multilib.patch was applied incorrectly
- glog patch relies on glog>=0.6
- QA_SED fixes

Closes: https://bugs.gentoo.org/980364
Bug: https://bugs.gentoo.org/980355
Signed-off-by: Sv. Lockal <lockalsash <AT> gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/46645
Closes: https://github.com/gentoo/gentoo/pull/46645
Signed-off-by: Alfredo Tupone <tupone <AT> gentoo.org>

 .../files/pytorch-2.13.0-aotriton-fixes.patch      | 46 ++++++++++++++++++++++
 ...orch-2.13.0.ebuild => pytorch-2.13.0-r1.ebuild} | 18 ++-------
 2 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/sci-ml/pytorch/files/pytorch-2.13.0-aotriton-fixes.patch b/sci-ml/pytorch/files/pytorch-2.13.0-aotriton-fixes.patch
new file mode 100644
index 000000000000..cb2b7ffd106b
--- /dev/null
+++ b/sci-ml/pytorch/files/pytorch-2.13.0-aotriton-fixes.patch
@@ -0,0 +1,46 @@
+Fix installation with aotriton
+
+Upstream bug: https://github.com/pytorch/pytorch/issues/158109
+--- a/cmake/External/aotriton.cmake
++++ b/cmake/External/aotriton.cmake
+@@ -56,7 +56,8 @@ if(NOT __AOTRITON_INCLUDED)
+   set(__AOTRITON_Z "gz")
+   # Set the default __AOTRITON_LIB path
+   if(NOT WIN32)
+-    set(__AOTRITON_LIB "lib/libaotriton_v2.so")
++    include(GNUInstallDirs)
++    set(__AOTRITON_LIB "${CMAKE_INSTALL_LIBDIR}/libaotriton_v2.so")
+   else()
+     set(__AOTRITON_LIB "lib/aotriton_v2.lib")
+   endif()
+@@ -240,10 +241,6 @@ if(NOT __AOTRITON_INCLUDED)
+ 
+   # Note it is INSTALL"ED"
+   if(DEFINED ENV{AOTRITON_INSTALLED_PREFIX})
+-    install(DIRECTORY
+-            $ENV{AOTRITON_INSTALLED_PREFIX}/lib
+-            $ENV{AOTRITON_INSTALLED_PREFIX}/include
+-            DESTINATION ${__AOTRITON_INSTALL_DIR})
+     set(__AOTRITON_INSTALL_DIR "$ENV{AOTRITON_INSTALLED_PREFIX}")
+     message(STATUS "Using Preinstalled AOTriton at ${__AOTRITON_INSTALL_DIR}")
+   elseif(DEFINED ENV{AOTRITON_INSTALL_FROM_SOURCE})
+@@ -280,19 +277,4 @@ if(NOT __AOTRITON_INCLUDED)
+   target_link_libraries(__caffe2_aotriton INTERFACE "${__AOTRITON_INSTALL_DIR}/${__AOTRITON_LIB}")
+   target_include_directories(__caffe2_aotriton INTERFACE ${__AOTRITON_INSTALL_DIR}/include)
+   set(AOTRITON_FOUND TRUE)
+-  # Install libaotriton_v2.so into the cmake install tree so it ends up in
+-  # site-packages/torch/lib/ when building with scikit-build-core.
+-  # aotriton's ExternalProject puts the library directly in the source tree
+-  # (${PROJECT_SOURCE_DIR}/torch/lib/) without a cmake install() rule, so it
+-  # is absent from the installed wheel and causes link failures in downstream
+-  # cmake builds (e.g., custom op builds) that link against installed torch.
+-  install(DIRECTORY "${__AOTRITON_INSTALL_DIR}/lib/"
+-    DESTINATION "lib"
+-    FILES_MATCHING PATTERN "libaotriton_v2*.so*"
+-  )
+-  # Install aotriton GPU kernel images (compressed ISA blobs) into the wheel.
+-  install(DIRECTORY "${__AOTRITON_INSTALL_DIR}/lib/aotriton.images"
+-    DESTINATION "lib"
+-    OPTIONAL
+-  )
+ endif() # __AOTRITON_INCLUDED

diff --git a/sci-ml/pytorch/pytorch-2.13.0.ebuild b/sci-ml/pytorch/pytorch-2.13.0-r1.ebuild
similarity index 96%
rename from sci-ml/pytorch/pytorch-2.13.0.ebuild
rename to sci-ml/pytorch/pytorch-2.13.0-r1.ebuild
index 960a676020f5..9014ee301cc8 100644
--- a/sci-ml/pytorch/pytorch-2.13.0.ebuild
+++ b/sci-ml/pytorch/pytorch-2.13.0-r1.ebuild
@@ -66,7 +66,7 @@ RDEPEND="
 	!sci-ml/caffe2
 	dev-cpp/abseil-cpp:=
 	dev-cpp/gflags:=
-	>=dev-cpp/glog-0.5.0:=
+	>=dev-cpp/glog-0.6.0:=
 	>=dev-libs/cpuinfo-2025.11.14
 	dev-libs/libfmt:=
 	dev-libs/protobuf:=
@@ -119,7 +119,7 @@ RDEPEND="
 		>=sci-libs/rocBLAS-6.3:=   <sci-libs/rocBLAS-7.3:=
 		>=sci-libs/rocRAND-6.3:=   <sci-libs/rocRAND-7.3:=
 		>=sci-libs/rocSOLVER-6.3:= <sci-libs/rocSOLVER-7.3:=
-		memefficient? ( =sci-libs/aotriton-bin-0.11*:= )
+		memefficient? ( =sci-libs/aotriton-bin-0.13*:= )
 		distributed? (
 			>=dev-util/rocm-smi-6.3:= <dev-util/rocm-smi-7.3:=
 			>=dev-util/amdsmi-6.3:= <dev-util/amdsmi-7.3:=
@@ -160,7 +160,7 @@ DEPEND="
 BDEPEND="dev-build/cmake"
 
 PATCHES=(
-	"${FILESDIR}"/${PN}-2.10.0-cpp-extension-multilib.patch
+	"${FILESDIR}"/${P}-aotriton-fixes.patch
 	"${FILESDIR}"/${P}-glog.patch
 	"${FILESDIR}"/${P}-removekineto-pr178960.patch
 	"${FILESDIR}"/${P}-unbundle_fbgemm.patch
@@ -179,14 +179,11 @@ src_prepare() {
 	fi
 	filter-lto #bug 862672
 
+	eapply "${FILESDIR}/${PN}-2.10.0-cpp-extension-multilib.patch"
 	# Replace placeholders added by cpp-extension.patch
 	sed -e "s|%LIB_DIR%|$(get_libdir)|g" \
 		-i torch/utils/cpp_extension.py || die
 
-	# Drop legacy from pyproject.toml
-	sed -e "/build-backend/s|:__legacy__||" \
-		-i pyproject.toml || die
-
 	# Unbundle fmt
 	sed -i \
 		-e 's|::fmt-header-only||' \
@@ -207,13 +204,6 @@ src_prepare() {
 		aten/src/ATen/CMakeLists.txt \
 		|| die
 
-	# Change libaotriton path
-	sed -i \
-		-e "s|}/lib|}/\${CMAKE_INSTALL_LIBDIR}|g" \
-		-e "/set(__AOTRITON_LIB/s|lib/|\${CMAKE_INSTALL_LIBDIR}/|g" \
-		cmake/External/aotriton.cmake \
-		|| die
-
 	# Add needed file for cutlass as symbolic link
 	ln -sf /usr/share/cutlass/examples third_party/cutlass/examples || die