Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTorch macosx-arm64 cross-build #1461

Closed
sbrunk opened this issue Jan 17, 2024 · 0 comments · Fixed by #1463
Closed

PyTorch macosx-arm64 cross-build #1461

sbrunk opened this issue Jan 17, 2024 · 0 comments · Fixed by #1463

Comments

@sbrunk
Copy link
Contributor

sbrunk commented Jan 17, 2024

TL;DR
Can we use the x86_64 Python interpreter for cross-compilation of PyTorch to macosx-arm64 or will it cause issues? If we can, what is a good way to configure it especially for CI builds? If not, what might be other options?

Background

We only have x86_64 machines in CI, so we currently have to cross-compile macosx-arm64 artifacts. With #1459 out of the way, I got cross-compilation PyTorch working locally for #1069. I can compile arm64 artifacts on x86_64 that are working fine on an arm64 machine.

What I'm not sure about though is the Python build dependency. One thing it's used for is to call the build:

"$PYTHON_BIN_PATH" setup.py build

Which means for cross-compilation we need an interpreter of the host arch (x86_64 here). It is also used for other things though, i.e. and for numpy stuff and in CFLAGS here:

export CFLAGS="-I$CPYTHON_PATH/include/ -I$PYTHON_LIB_PATH/include/python/ -L$CPYTHON_PATH/lib/ -L$CPYTHON_PATH/libs/"

The PyTorch build depends on cpython of its target arch though. Locally via

CPYTHON_PATH="$INSTALL_PATH/../../../cpython/cppbuild/$PLATFORM/"

For a maven build it seems BUILD_PATH is set and therefore CPYTHON_PATH is overwritten to use cpython cached from maven:

if [[ -n "${BUILD_PATH:-}" ]]; then
PREVIFS="$IFS"
IFS="$BUILD_PATH_SEPARATOR"
for P in $BUILD_PATH; do
if [[ $(find "$P" -name Python.h) ]]; then
CPYTHON_PATH="$P"

I'm not sure how CPYTHON_PATH is set exactly (maven plugin?) but I think it is coming in through the transitive maven-compiler-plugin dependency on cpython via numpy-platform in pom.xml:

<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>numpy-platform</artifactId>
<version>1.26.3-${project.parent.version}</version>
</dependency>

To get it working locally, I did a little hack: Build a native x86_64 cpython but put it into the cppbuild/macosx-arm64 directory so CPYTHON_PATH is set to it and we can actually run that Python interpreter for kicking off the PyTorch cross-compilation.

So the open question is: Can we use the x86_64 Python interpreter for cross-compilation of PyTorch or will it cause issues? If we can, what is a good way to configure it especially for CI builds? If not, what might be other options?

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

Successfully merging a pull request may close this issue.

2 participants