Skip to content

sci-libs/pytorch: fix python build with >=setuptools-59.6#1130

Closed
littlewu2508 wants to merge 1 commit intogentoo:masterfrom
littlewu2508:pytorch
Closed

sci-libs/pytorch: fix python build with >=setuptools-59.6#1130
littlewu2508 wants to merge 1 commit intogentoo:masterfrom
littlewu2508:pytorch

Conversation

@littlewu2508
Copy link
Copy Markdown
Contributor

Backport an upstream PR: pytorch/pytorch#69904

Bug: #1123 (comment)
Package-Manager: Portage-3.0.22, Repoman-3.0.3
Signed-off-by: Yiyang Wu [email protected]

Backport an upstream PR: pytorch/pytorch#69904

Bug: gentoo#1123 (comment)
Package-Manager: Portage-3.0.22, Repoman-3.0.3
Signed-off-by: Yiyang Wu <[email protected]>
@Nowa-Ammerlaan
Copy link
Copy Markdown
Member

Thanks 👍

@Nowa-Ammerlaan
Copy link
Copy Markdown
Member

There is still something strange happening here:

andrew@andrew-gentoo-pc ~ % python3.8
Python 3.8.12 (default, Dec 14 2021, 21:16:01)
[GCC 11.2.1 20211127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/site-packages/torch/__init__.py", line 197, in <module>
from torch._C import *  # noqa: F403
ImportError: /usr/lib64/libtorch_python.so: undefined symbol: PyCMethod_New
>>>
andrew@andrew-gentoo-pc ~ % python3.9
Python 3.9.9 (main, Nov 22 2021, 16:39:27)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
zsh: segmentation fault (core dumped)  python3.9
andrew@andrew-gentoo-pc ~ % python3.10
Python 3.10.1 (main, Dec 18 2021, 12:34:29) [GCC 11.2.1 20211127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>

It appears we aren't properly compiling pytorch for every enable python target, only the version for the highest python target is installed and works. We either need to fix this or set DISTUTILS_SINGLE_IMPL=1 in the ebuild.

@littlewu2508
Copy link
Copy Markdown
Contributor Author

Exactly, I will try to come up with a solution. It's a bit tricky because src_compile is using cmake.eclass so the compilation runs only once. Complete recompile for every python target is also a bad idea because that means tons of redundant work.

@Nowa-Ammerlaan
Copy link
Copy Markdown
Member

Exactly, I will try to come up with a solution. It's a bit tricky because src_compile is using cmake.eclass so the compilation runs only once. Complete recompile for every python target is also a bad idea because that means tons of redundant work.

Replacing:

src_compile() {
	cmake_src_compile

	if use python; then
		USE_SYSTEM_LIBS=ON CMAKE_BUILD_DIR=${BUILD_DIR} distutils-r1_src_compile
	fi
}

with e.g.:

python_compile() {
	cmake_src_compile
       	if use python; then
	      USE_SYSTEM_LIBS=ON CMAKE_BUILD_DIR=${BUILD_DIR} distutils-r1_python_compile
         fi
}

(and equivalent for the other phases) should to the trick. (The default distutils-r1 src_compile will run python_compile for each python target if defined, we then also call the default distutils-r1 python_compile if USE=python). However, this will triple compile time (if all three targets are enabled), and to be honest I'm not sure that is worth it since the compile time is already rather long. Is there a use case for installing this package for multiple python versions, if not then I suggest to just keep pytorch single implementation only.

@littlewu2508
Copy link
Copy Markdown
Contributor Author

@AndrewAmmerlaan Thanks for changing pytorch to single python target. I've investigated the possibility of compiling multiple python target bindings without recompile python-independent parts like libtorch. It seems too complicated. The CMakeLists.txt in pytorch and caffe2 are not intended to configure multiple targets, so there would be too much hack to achieve multi-target support. Just single python implementation is enough since no one has wanted multi-target pytorch yet.

@heroxbd
Copy link
Copy Markdown
Contributor

heroxbd commented Jan 10, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants