Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194880
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 640426a with merge base cb538a5 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
1209884 to
1302e27
Compare
14cbeae to
0d29537
Compare
|
@yuzibo Can we validate this PR on our riscv64 CI pipeline? |
| @@ -0,0 +1,172 @@ | |||
| #!/usr/bin/env python3 | |||
| """Check that a built wheel is self-consistent about its extension module ABI. | |||
There was a problem hiding this comment.
Lets move it to be general, implement it for all wheels.
0d29537 to
d010d5b
Compare
|
Rebased onto viable/strict after GitHub flagged the PR as conflicting. Drafted with an AI assistant, checked by me.
@isuruf, I'll add that this may also be useful for the conda-forge build, where we achieve that effect currently with a sed command. (cc @mgorny) |
| # build, scikit-build-core, packaging and six are pure Python and come from PyPI; | ||
| # they run in the cross environment because its interpreter is the host one with | ||
| # the target's sysconfig. numpy needs a target wheel, which PIP_EXTRA_INDEX_URL | ||
| # supplies; 1.26.4 matches the Python 3.12 pin in .ci/docker/requirements-ci.txt |
There was a problem hiding this comment.
Should we add a reference back to this file to requirements-ci.txt to update both at the same time?
There was a problem hiding this comment.
Yes, done in 07a36a3: the numpy block in requirements-ci.txt now points back here, so whoever bumps the 3.12 pin sees the cross image.
The riscv64 cross build has not taken its own code path since pytorch#187821. That PR renamed the docker image to pytorch-linux-noble-riscv64-py3.12-gcc14-cross-build and narrowed the guards from *riscv* to *riscv*cross*, but the guards in .ci/docker/build.sh test the image name while the ones in .ci/pytorch/build.sh test BUILD_ENVIRONMENT -- and only the image name gained the "cross" marker. BUILD_ENVIRONMENT stayed linux-noble-riscv64-py3.12-gcc14, so `[[ "$BUILD_ENVIRONMENT" == *riscv64*cross* ]]` has been false ever since. Everything in that block is skipped as a result: the crossenv at /opt/riscv-cross-env is never activated, so the build runs against the host interpreter; CMAKE_CROSSCOMPILING, CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR are never exported, so CMake never enters cross mode even though CC/CXX point at the riscv64 toolchain; and SLEEF_TARGET_EXEC_USE_QEMU and the workspace chown are missed too. pytorch#190887 later added an `elif *riscv64*` arm for the new native image, which is the branch this job has been taking. Aligning BUILD_ENVIRONMENT with the image name is the smaller of the two possible fixes and matches the intent of pytorch#187821. Widening the guards back to *riscv64* would work for this job but would pull the native image, which is genuinely named linux-noble-riscv64-py3.12-gcc14, onto the cross path -- and that path exits 1 when /opt/riscv-cross-env is absent. The string is only consumed as $BUILD_ENVIRONMENT and as the build artifact name, so renaming it is contained; no other pattern in .ci/pytorch/build.sh matches the added "-cross-build". This commit was authored with the assistance of an AI coding assistant. Test Plan: The job is opt-in, so this needs a ciflow/riscv64 run to verify. It has been red since 2025-10 and the last run predates both pytorch#190887 and the scikit-build-core migration, so this is expected to uncover further breakage rather than turn the job green on its own -- in particular the crossenv is provisioned with `setuptools pyyaml typing_extensions wheel` only, while the build now invokes `python -m build --wheel --no-isolation`. Fixing that needs to be informed by a real run, since crossenv splits host and target environments and build backends belong in the host one. Root cause confirmed from the last run's log (https://github.com/pytorch/pytorch/actions/runs/28817304405), which shows the guard evaluating false: ``` + [[ linux-noble-riscv64-py3.12-gcc14 == *riscv64*cross* ]] + [[ linux-noble-riscv64-py3.12-gcc14 == *vulkan* ]] ``` Checked that no other BUILD_ENVIRONMENT pattern in the build script starts matching once "-cross-build" is appended: ``` grep -on 'BUILD_ENVIRONMENT" [!=]= \*[^]]*\*' .ci/pytorch/build.sh \ | sed 's/.*== //;s/.*!= //' | sort -u ``` yields *aarch64* *clang* *-clang*-asan* *client* *cuda* *cuda13* *-debug* *-full-debug* *full-debug* *libtorch* *riscv64* *riscv64*cross* *rocm* *-tsan* *vulkan* *xla* *xpu*, of which only the two riscv64 patterns match, both intentionally. Lint: ``` lintrunner --paths-cmd='git diff --name-only origin/viable/strict' ```
…rements
With the routing fixed, the riscv64 cross job reaches the build and stops at
`python -m build`: the crossenv is provisioned with `setuptools pyyaml
typing_extensions wheel`, which was enough for `setup.py bdist_wheel` but not for
the scikit-build-core front end and backend. Run 32955566963 ends at
/opt/riscv-cross-env/cross/bin/python3: No module named build
Install the missing pieces into the crossenv. What goes where follows from what
crossenv actually is: its `cross` interpreter is the host CPython with sysconfig
patched to report the target's values, not a riscv64 binary -- the error above is
an x86_64 process raising a Python error. So pure-Python build tooling (build,
scikit-build-core, packaging, six) installs into the cross environment and runs
there natively, and it has to be reachable from that interpreter specifically:
driving the build from the host environment would hand the backend the host
sysconfig and produce a host-tagged wheel. cmake and ninja stay where they are,
on the host, because they are executed rather than imported; installing them into
the cross environment would fetch riscv64 wheels the host cannot run.
The install has to sit after the chown loop rather than beside the other exports.
The crossenv is root-owned in the image while the container runs as jenkins, so
until `sudo chown -R jenkins /opt/riscv-cross-env` has run the cross interpreter
cannot read `cross/pyvenv.cfg` and dies during startup, before `site` is
imported. Nothing else in the script makes that dependency visible -- the
existing `python -m build` call is far enough down that it never noticed -- so it
is called out in a comment.
numpy is the exception that needs a target wheel, and PyPI has none for riscv64.
The RISE project index does, and it is already a trusted host here -- pytorch#190887
wired it into the native riscv64 image the same way. 1.26.4 is chosen on two
counts: it matches the Python 3.12 pin in .ci/docker/requirements-ci.txt, and it
is the newest numpy published there under a plain linux_riscv64 tag, so it does
not depend on crossenv resolving manylinux glibc tags for the target. The pin is
load-bearing in a second way: with an extra index pip resolves the highest
version across both, and every newer numpy exists on PyPI without a riscv64
wheel, so leaving it unpinned would silently cross-build numpy from an sdist.
Provisioning belongs in the image rather than in this script, and moving it to
.ci/docker/ubuntu-cross-riscv/Dockerfile is the intended end state. It is
deliberately not done here: the job has been red since 2025-10 and there is
almost certainly more breakage past this point, while any change under .ci/docker
rehashes the directory and rebuilds every CI image. Doing that once, when the
whole path is known green, is cheaper than doing it per iteration.
Note that numpy may still not end up enabled. It satisfies the build-requires
check, which `build` performs through importlib.metadata rather than by importing
(build/_util.py), but FindPython's NumPy component discovers its include
directory by running `import numpy; numpy.get_include()`, and a riscv64 extension
module cannot be imported on an x86_64 host. FindPython swallows that in a bare
`except: pass`, so the expected outcome is a "NumPy could not be found" warning
from Dependencies.cmake and USE_NUMPY off -- no worse than the status quo. If
numpy is wanted for real, the follow-up is to set Python_NumPy_INCLUDE_DIR
directly instead of letting FindPython probe.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Needs a ciflow/riscv64 run; the job is opt-in and cannot be exercised locally.
Two runs on this branch informed this change.
32955566963 established the starting point -- the guard from the previous commit
resolves, the crossenv activates, and the build stops on the missing front end:
```
+ [[ linux-noble-riscv64-py3.12-gcc14-cross-build == *riscv64*cross* ]]
+ source /opt/riscv-cross-env/bin/activate
+ export CMAKE_CROSSCOMPILING=TRUE
...
+ python -m build --wheel --no-isolation
/opt/riscv-cross-env/cross/bin/python3: No module named build
```
32971278636 ran this install from the wrong place, before the chown, and is what
established the ownership constraint above:
```
Fatal Python error: init_import_site: Failed to import the site module
PermissionError: [Errno 13] Permission denied: '/opt/riscv-cross-env/cross/pyvenv.cfg'
```
Confirmed the RISE project index actually serves the wheel this pins, via the
simple repository API:
```
curl -sS https://pypi.riseproject.dev/simple/numpy/ \
| grep -o 'numpy-[^<]*cp312[^<]*\.whl' | sort -u
```
which lists numpy-1.26.4-cp312-cp312-linux_riscv64.whl among 16 cp312 riscv64
wheels; everything from 2.3.1 onward is published only under
manylinux_2_38/manylinux_2_39 tags. The same query against the index root shows
it carries numpy, pyyaml, ninja and cmake but not build, scikit-build-core,
packaging or six, which is why PyPI stays the primary index and this is an
--extra-index-url rather than an --index-url.
Checked that PIP_EXTRA_INDEX_URL is not already in effect for this image, so the
flag is not redundant: .ci/docker/build.sh sets it only for the native
pytorch-linux-noble-riscv64-py3.12-gcc14 tag, ubuntu-cross-riscv/Dockerfile
declares no matching ARG, and no PIP_* variable appears in the container
environment dumped by those runs.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
With the crossenv provisioned, the riscv64 cross job reaches the compiler and
builds the wrong architecture. Run 32978891209 configures with the host gcc:
-- The CXX compiler identification is GNU 13.3.0
-- Check for working CXX compiler: /usr/bin/g++ - skipped
and compiles against x86_64 headers
(/usr/include/x86_64-linux-gnu/bits/string_fortified.h), while AVX feature tests
succeed -- none of which belongs in a riscv64 build.
The image sets CC=riscv64-linux-gnu-gcc-14 and CXX=riscv64-linux-gnu-g++-14, but
.ci/pytorch/common.sh selects a compiler from the build environment name and
exports CC=gcc / CXX=g++ for anything matching *gcc*. This build environment,
linux-noble-riscv64-py3.12-gcc14-cross-build, matches on its gcc14 component, so
the cross toolchain is replaced with the host one. common.sh is sourced before
this block runs, so re-exporting here is enough; GCC_VERSION is already in the
image environment, so the toolchain name is derived rather than restated.
The result of the mismatch is a build that is half cross-compiled. CMAKE_SYSTEM_
PROCESSOR still says riscv64, so cpuinfo selects its RISC-V backend, and that
backend is then compiled by a compiler that does not define the RISC-V feature
macros its headers are guarded on:
FAILED: confu-deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/riscv/linux/init.c.o
third_party/cpuinfo/src/riscv/linux/api.h:55:90: error: array type has
incomplete element type 'struct cpuinfo_riscv_isa'
This is not fallout from the two preceding commits. The override arrived with
pytorch#179321 on 2026-04-07, and the previous build environment name contained gcc14
too, so it would have applied equally. It stayed invisible because the job never
got as far as compiling: before pytorch#187821 broke the routing it was already failing
at `python setup.py clean`, and after it, in the block this restores.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Needs a ciflow/riscv64 run; the job is opt-in and cannot be exercised locally.
Run 32978891209, on the parent commit, is the evidence above: it installs the
build requirements, passes the dependency check, configures, and gets 24 objects
into a 2472-target ninja build before cpuinfo stops it -- the furthest this job
has run since 2025-07. A run on this commit should configure with
riscv64-linux-gnu-gcc-14 and get past cpuinfo.
Confirmed GCC_VERSION is present in the container environment, so the derived
name resolves, from the environment dump in that same run:
```
GCC_VERSION=14
```
USE_NUMPY is expected to stay OFF for the reason given in the previous commit;
that run confirmed it, with Dependencies.cmake reporting "NumPy could not be
found" and the configuration summary showing USE_NUMPY : OFF even though
numpy-1.26.4 installed successfully from the RISE project index.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
With the cross toolchain restored, the build reaches onnx codegen and stops:
/bin/sh: 1: /__w/pytorch/pytorch/build/bin/protoc-3.21.12.0: Exec format error
protoc is a build-time code generator. Cross-compiling third_party/protobuf
produces a riscv64 protoc, and the x86_64 build host cannot run it.
This used to work by emulation. The riscv64 job ran on the EC2 path of
_linux-build.yml, which mounted binfmt_misc, registered qemu-riscv64 via
multiarch/qemu-user-static, and ran the build container privileged. pytorch#189113
deleted that path on 2026-07-06 when the OSDC/ARC migration was wrapped up, and
the OSDC path it left behind has no equivalent -- no binfmt, qemu or privileged
anywhere in the workflow today. That is also what the image's QEMU_LD_PREFIX and
this block's SLEEF_TARGET_EXEC_USE_QEMU have always been assuming: the image has
never installed qemu itself, because the host used to provide it.
Rather than restore emulation, which needs privileged containers that may not be
available on OSDC at all, supply a protoc built for the host. cmake/ProtoBuf.cmake
documents CAFFE2_CUSTOM_PROTOC_EXECUTABLE for precisely this case, and
Dependencies.cmake forwards it to ONNX_CUSTOM_PROTOC_EXECUTABLE, so it covers the
codegen that fails here. conda-forge solves the same problem the same way: their
recipe repoints protobuf's imported target at the build-prefix protoc, with the
comment "It helps cross compiled builds without emulation support to complete".
The version has to track third_party/protobuf, currently v21.12, since generated
sources must stay compatible with the libprotobuf built for the target. conda-forge
publishes libprotobuf 3.21.12, which is an exact match.
The variable needs the passthrough entry to have any effect. It does not start with
BUILD_, USE_ or CMAKE_, so without being listed it would never reach the CMake
cache, and ProtoBuf.cmake gates on if(EXISTS ...) -- an unforwarded value would
silently fall back to the vendored protoc and fail exactly as before. It is a
genuine cross-compilation knob, so forwarding it helps any cross build, not only
this job.
The pixi bootstrap is deliberately temporary, and stage 2 replaces it. Ubuntu noble
ships protobuf-compiler at 3.21.12, the same version, so the eventual form is an
apt install in .ci/docker/ubuntu-cross-riscv/Dockerfile with no bootstrap at all.
It is not done here because any change under .ci/docker rehashes the directory and
rebuilds every CI image, and this build has more unexplored ground ahead of it --
SLEEF_TARGET_EXEC_USE_QEMU=ON still asks to execute target binaries, so protoc is
unlikely to be the last thing emulation was covering.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Needs a ciflow/riscv64 run; the job is opt-in and cannot be exercised locally.
Run 33059855491, on the parent commit, is the failure above. It configured with
riscv64-linux-gnu-gcc-14, compiled cpuinfo's RISC-V backend, and reached 395 of
2351 targets before protoc stopped it -- the furthest since 2025-07.
Verified locally that the pinned package supplies a matching protoc, using an
isolated PIXI_HOME so as not to touch an existing pixi installation:
```
PIXI_HOME=$(mktemp -d) pixi global install "libprotobuf==3.21.12"
"$PIXI_HOME/bin/protoc" --version
```
prints `libprotoc 3.21.12`, against `git -C third_party/protobuf describe --tags`
reporting `v21.12`.
Checked the bootstrap's requirements against the image: the pixi installer accepts
either curl or wget and unpacks a tar.gz on Linux, and the image provides wget and
tar but no curl. PIXI_HOME is kept outside the checkout because build.sh runs
assert_git_not_dirty, and PIXI_NO_PATH_UPDATE stops the installer rewriting shell
profiles.
Confirmed conda-forge publishes the matching version:
```
curl -sS https://api.anaconda.org/package/conda-forge/libprotobuf \
| python3 -c "import json,sys; print([v for v in json.load(sys.stdin)['versions'] if v.startswith('3.21')])"
```
lists 3.21.1 through 3.21.12.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
With protoc supplied from the host, the build clears onnx and reaches 701 of
2351 targets before SLEEF stops it the same way:
/bin/sh: 1: /__w/pytorch/pytorch/build/sleef/bin/mkrename: Exec format error
FAILED: sleef/src/libm/include/renamervvm1nofma.h
mkrename and its siblings are code generators that run during the build, so
cross-compiling them produces binaries the x86_64 host cannot execute.
Unlike protoc, this one is self-inflicted. SLEEF already has a cross path that
needs no emulation -- add_host_executable in third_party/sleef/CMakeLists.txt
imports the tools from NATIVE_BUILD_DIR when cross-compiling. It is not taken
here because SLEEF_TARGET_EXEC_USE_QEMU is set, which selects an earlier branch
that builds the tools for the target and runs them under emulation:
if (NOT CMAKE_CROSSCOMPILING)
add_executable(${TARGETNAME} ${ARGN})
elseif (DEFINED ENV{SLEEF_TARGET_EXEC_USE_QEMU})
if($ENV{SLEEF_TARGET_EXEC_USE_QEMU})
add_executable(${TARGETNAME} ${ARGN})
endif()
else()
add_executable(${TARGETNAME} IMPORTED GLOBAL)
set_property(TARGET ${TARGETNAME} PROPERTY
IMPORTED_LOCATION ${NATIVE_BUILD_DIR}/bin/${TARGETNAME})
endif()
That variable was correct when the workflow registered qemu-riscv64 with
binfmt_misc, and has been wrong since pytorch#189113 removed it along with the EC2 build
path. Drop it and provide NATIVE_BUILD_DIR instead, which is the same trade this
job already makes for protoc: substitute a host tool rather than emulate a target
one.
The native configure mirrors the option set in aten/src/ATen/CMakeLists.txt rather
than using SLEEF's defaults. SLEEF_BUILD_TESTS, SLEEF_BUILD_DFT and
SLEEF_BUILD_GNUABI_LIBS change which host executables exist at all, so a mismatch
between the two configurations would not fail here; it would surface much later as
an IMPORTED_LOCATION pointing at a binary that was never built.
NATIVE_BUILD_DIR is passed as a CMake define rather than added to _ENV_PASSTHROUGH
in cmake/EnvVarForwarding.cmake, unlike CAFFE2_CUSTOM_PROTOC_EXECUTABLE in the
preceding commit. The protoc variable is a documented PyTorch cross-compilation
knob that any cross build benefits from having forwarded; NATIVE_BUILD_DIR is a
generic SLEEF-internal name, and claiming it in PyTorch's environment namespace
seems worse than passing it explicitly. Happy to move it if reviewers disagree.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Needs a ciflow/riscv64 run; the job is opt-in and cannot be exercised locally.
Run 33062775136, on the parent commit, is the failure above. It also confirms the
protoc change worked: the vendored protoc is still linked
(`[237/2351] Linking CXX executable bin/protoc-3.21.12.0`) but never executed, and
the build passed onnx codegen to reach SLEEF.
The native SLEEF build was exercised locally with the same options, against the
checked-out submodule:
```
cmake -S third_party/sleef -B /tmp/sleef-native -G Ninja \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc \
-DSLEEF_BUILD_SHARED_LIBS=OFF -DSLEEF_BUILD_DFT=OFF \
-DSLEEF_BUILD_GNUABI_LIBS=OFF -DSLEEF_BUILD_TESTS=OFF \
-DSLEEF_BUILD_SCALAR_LIB=OFF -DSLEEF_DISABLE_OPENMP=ON
cmake --build /tmp/sleef-native
ls /tmp/sleef-native/bin/
```
completes in 99 targets and produces addSuffix, mkalias, mkdisp, mkmasked_gnuabi,
mkrename and mkrename_gnuabi; `/tmp/sleef-native/bin/mkrename` runs and prints its
usage. CMAKE_CXX_COMPILER is deliberately not passed, since SLEEF is C-only and
CMake warns that the variable is unused.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
Run 33068619401 completed the cross build: 2339 of 2339 targets, a
torch-2.15.0a0+git87bc595-cp312-cp312-linux_riscv64.whl produced and installed,
custom test artifacts linked with riscv64-linux-gnu-g++-14, and
assert_git_not_dirty clean. The job still failed, one step later:
/__w/_temp/....sh: 1: zip: not found
The artifact archive step needs zip, which the image does not have. That is a
Dockerfile change, so this takes the opportunity to move the rest of the
provisioning off the build script at the same time -- one image rebuild instead
of several, which is what the previous two commits were deferring.
Three things move. The crossenv gains the scikit-build-core build requirements it
was missing, replacing the runtime pip install. protobuf-compiler replaces the
pixi bootstrap for the host protoc: Ubuntu noble ships 3.21.12, matching the
vendored third_party/protobuf v21.12, so generated sources stay compatible with
the libprotobuf built for the target, and CAFFE2_CUSTOM_PROTOC_EXECUTABLE now
points at /usr/bin/protoc. zip is added for the step above.
The RISC-V wheel index is wired the way the native riscv64 image already does it,
as PIP_EXTRA_INDEX_URL and PIP_PREFER_BINARY build args set per tag in
.ci/docker/build.sh, rather than as an inline --extra-index-url. That keeps the
URL in one place per image and makes the pinning of numpy the only riscv-specific
detail left in the pip line. PIP_PREFER_BINARY additionally stops pip falling back
to an sdist, which for numpy would mean cross-building it from source.
The SLEEF native build stays in the build script. It compiles the checked-out
submodule, so it cannot be baked into an image that has no source tree.
Note this rebuilds every CI image, since .ci/docker is content-hashed as a whole.
That was the reason for keeping the previous two commits script-only while the
cross build still had unknown failures ahead of it; with the build itself green,
paying it once is the cheaper end of the trade.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Needs a ciflow/riscv64 run, and this one rebuilds the docker images first.
Run 33068619401, on the parent commit, is the evidence that everything before the
archive step works. Of note in that log, the provisioning this commit relocates
all succeeded at runtime first:
```
Downloading https://pypi.riseproject.dev/files/.../numpy-1.26.4-cp312-cp312-linux_riscv64.whl (9.8 MB)
Successfully installed build-1.5.0 numpy-1.26.4 pathspec-1.1.1 pyproject_hooks-1.2.0 scikit-build-core-1.0.3 six-1.17.0
...
[2339/2339] Linking CXX shared library lib/libnnapi_backend.so
*** Created torch-2.15.0a0+git87bc595-cp312-cp312-linux_riscv64.whl
```
so the package set and the index are already known good; what changes is only
where they are installed from.
Confirmed the apt package supplies a matching protoc: Ubuntu noble ships
protobuf-compiler 3.21.12-8.2ubuntu0.3, against
`git -C third_party/protobuf describe --tags` reporting v21.12.
Not verified here, and worth watching on the first run: that the crossenv pip
install resolves the same wheels non-interactively during the image build, where
PIP_EXTRA_INDEX_URL comes from the build arg rather than the command line.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
This job builds a wheel and never imports it -- the smoke test further down is gated on *full-debug*, which this build environment is not -- so an extension module named wrongly passes silently. That is not hypothetical: run 33078360947, on this branch two days ago, linked `torch/_C.so` untagged and went green. The cause was pytorchgh-189388, which has since landed: FindPython does not run the interpreter to compute Python_SOABI while cross-compiling, so WITH_SOABI composes a name with no ABI tag. Run 33243561273, on the rebase that picked the fix up, links `torch/_C.cpython-312-riscv64-linux-gnu.so` instead. Nothing in CI checks that, which is how the class went unnoticed long enough to be reported from conda-forge rather than found here. The check asks whether the wheel is self-consistent, rather than comparing it against the running interpreter. A wheel states its tags twice -- in the filename and in .dist-info/WHEEL -- and the extension module inside has to agree with both. So it verifies that those two agree, that exactly one torch/_C module is present, that it is not the untagged torch/_C.so, and that its ABI tag matches the wheel's, cp312 against cpython-312. Deriving the expectation from sysconfig instead, as a first draft did, makes the result depend on which interpreter happens to be active -- for a cross build that is the crossenv interpreter reporting the target's values, not the obvious one. That held here, but only by construction: it is a property of where the call sits relative to the crossenv activation, invisible at the call site, and it would silently become a false failure if either moved. Reading the wheel's own tags has no such coupling, and lets the check run under any interpreter. It also catches more. A wheel whose filename and metadata disagree, or whose module is tagged for a different Python than the wheel claims, are both real mis-builds that the sysconfig form would have passed whenever the checker happened to run under the matching interpreter. The checker lives in .ci/pytorch/check_wheel_soabi.py rather than inline: as a file it is linted and directly testable, which an embedded heredoc is not, and .ci/pytorch already holds print_sccache_log.py and rocm_preflight.py. It takes any number of wheels so the caller passes the glob directly -- dist/ is not guaranteed to hold exactly one, pip_install_whl in common_utils.sh already splits a multi-path argument for that reason, and an earlier draft using `$(echo dist/*.whl)` would have silently checked whichever wheel sorted first. It is gated on the riscv64 cross environment. A native build satisfies it trivially, and adding wheel inspection to every build job is a wider change than this branch should make; the check is cheap enough that generalising it later is worth considering. There is adjacent prior art. .ci/pytorch/smoke_test/check_wheel_tags.py, added in TARGET_OS -- answering "did we build for the target we meant to", which does need an external reference. It never inspects the extension module's filename, so an untagged torch/_C.so inside a correctly tagged wheel passes it cleanly; that is the gap pytorchgh-189388 fell through. It is also reachable only via smoke_test.py, which imports torch and therefore cannot run in a cross job. Folding the module-name check in there would cover every platform's binary builds rather than this one job, and is worth doing, but it is filed separately: that file is smoke-test-only, so the cross job would still need its own call site. This commit was authored with the assistance of an AI coding assistant. Test Plan: The assertion needs a ciflow/riscv64 run to exercise in place, and should pass: run 33243561273 already produced the tagged name it looks for. Because the check reads only the wheel, the riscv64 case is testable without a riscv64 toolchain -- a wheel is a zip. These were built to order and run under **host CPython 3.10 on x86_64**, deliberately neither the Python nor the architecture the wheels claim, which is the property the sysconfig form lacked: | wheel under test | exit | | --- | --- | | `cp312-cp312-linux_riscv64` shipping `_C.cpython-312-riscv64-linux-gnu.so` | 0 | | same, shipping untagged `torch/_C.so` (the pytorchgh-189388 regression) | 1 | | same, shipping no `torch/_C*` at all (the conda-forge symptom) | 1 | | filename says `cp312-...`, `.dist-info/WHEEL` says `cp310-...` | 1 | | declares `cp312`, ships `_C.cpython-310-riscv64-linux-gnu.so` | 1 | | ships both the tagged module and an untagged `torch/_C.so` | 1 | | a libtorch wheel plus a good torch wheel (former skipped) | 0 | | a libtorch wheel alone, so nothing was verified | 1 | Each failure names what it found and what it expected. Exit codes were read directly rather than through a pipe, since `head` would otherwise mask them. Lint: ``` lintrunner --paths-cmd='git diff --cached --name-only' bash -n .ci/pytorch/build.sh ```
Self-review finding on the SLEEF change earlier in this branch. scikit-build-core
reads SKBUILD_CMAKE_DEFINE as a ';'-separated list of KEY=VALUE pairs
(scikit_build_core/settings/sources.py), so assigning to it discards anything an
outer caller had already set.
Nothing sets it today -- this is the first use of SKBUILD_* anywhere in .ci/ --
so the assignment is correct as written. It is a landmine rather than a bug: the
next person to pass a define through this path, from a workflow or a wrapper
script, would find it silently dropped with no diagnostic, in a file that is
edited often.
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
Documentation of the separator is in scikit-build-core's own parsing:
```
grep -n 'item.split(";")' $(python -c 'import scikit_build_core.settings.sources as s; print(s.__file__)')
```
The expansion was checked directly for both cases:
```
SKBUILD_CMAKE_DEFINE="" SLEEF_NATIVE_BUILD_DIR=/tmp/sn \
bash -c 'echo "${SKBUILD_CMAKE_DEFINE:+${SKBUILD_CMAKE_DEFINE};}NATIVE_BUILD_DIR=${SLEEF_NATIVE_BUILD_DIR}"'
# -> NATIVE_BUILD_DIR=/tmp/sn
SKBUILD_CMAKE_DEFINE="FOO=bar" SLEEF_NATIVE_BUILD_DIR=/tmp/sn \
bash -c 'echo "${SKBUILD_CMAKE_DEFINE:+${SKBUILD_CMAKE_DEFINE};}NATIVE_BUILD_DIR=${SLEEF_NATIVE_BUILD_DIR}"'
# -> FOO=bar;NATIVE_BUILD_DIR=/tmp/sn
```
No separator is emitted when the variable is unset or empty, so the common case
is unchanged and the riscv64 job's behaviour is identical.
Lint:
```
lintrunner --paths-cmd='git diff --name-only origin/viable/strict'
bash -n .ci/pytorch/build.sh
```
Second self-review pass on the checker added earlier in this branch. Three corrections, none of which the riscv64 job would hit today, but all of which it would hit once the check is generalised to other wheels -- which is the filed follow-up. `torch/_C` was matched as a plain prefix. That is loose in two directions: `torch/_C/` is a real directory of .pyi stubs, and a sibling extension module named `torch/_C_something.so` would match while not being the module in question. A wheel shipping one alongside `_C` would have been rejected with "ships several torch/_C modules". Matching `torch/_C\.[^/]+` instead names the form exactly: `torch/_C.<abi>.<ext>`, or the untagged `torch/_C.<ext>`. `.dylib` was in the accepted suffix list. The suffixes CPython's import system recognises are those in importlib.machinery.EXTENSION_SUFFIXES -- `.so` on POSIX including macOS, `.pyd` on Windows -- implemented by _PyImport_DynLoadFiletab in Python/dynload_shlib.c, which macOS uses (configure.ac selects dynload_shlib.o wherever dlopen() exists). `.dylib` is not among them. It is not an idle distinction: macOS uses `.dylib` heavily for shared libraries, and torch's own macOS wheel ships seven of them next to the module, so accepting it widened what could be mistaken for an extension module on exactly the platform where the mistake was available. Comparing the filename's tags to the ``Tag:`` lines as strings is wrong for a compressed tag set. PEP 427 allows a filename to carry ``py2.py3-none-any`` while WHEEL lists each expansion on its own line, so the string compare fails on a correct wheel. The expansions are now compared as a set, and the ABI check accepts any member of a compressed ABI set. torch does not ship compressed tags, so this is latent rather than live. This commit was authored with the assistance of an AI coding assistant. Test Plan: Wheels built to order, run under host CPython 3.10 on x86_64 -- deliberately neither the Python nor the architecture they claim: | wheel | exit | why | | --- | --- | --- | | tagged module plus `torch/_C/*.pyi` stubs | 0 | the stub directory is not a module | | tagged module plus a sibling `torch/_C_foo.so` | 0 | **rejected before this commit** | | untagged `torch/_C.so` | 1 | the pytorchgh-189388 regression | | `cp312.cp313-abi3-linux_riscv64`, both Tag: lines present, ships `_C.abi3.so` | 0 | **rejected before this commit** | | same, one Tag: line missing from WHEEL | 1 | genuinely inconsistent | The earlier cases from the previous commit were re-run and are unchanged: correct wheel passes, missing module fails, filename/metadata mismatch fails, module tagged for another Python fails, two `torch/_C.*` modules fail, libtorch-only wheel is skipped, libtorch-only alone fails. Lint: ``` lintrunner --paths-cmd='git diff --name-only origin/viable/strict' ```
The cross image installs numpy into the crossenv by hand, with a version that has to match the Python 3.12 pin in requirements-ci.txt because the cross environment cannot install from that file. Nothing told the person bumping the pin about the second copy. Requested by isuruf in review. The comment sits in the numpy block next to the pin it mirrors. It costs no extra Docker rebuild: the image tag is the tree hash of .ci/docker, which this PR changes already. Test Plan: Comment-only change. Lint on the file passes; the CLANGTIDY adapter errors in a fresh worktree without a build directory, unrelated to this file. Authored with the help of Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
07a36a3 to
640426a
Compare
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
The riscv64 cross build has not taken its own code path since #187821. That PR renamed the docker image to pytorch-linux-noble-riscv64-py3.12-gcc14-cross-build and narrowed the guards from riscv to riscvcross*, but the guards in .ci/docker/build.sh test the image name while the ones in .ci/pytorch/build.sh test BUILD_ENVIRONMENT -- and only the image name gained the "cross" marker. BUILD_ENVIRONMENT stayed linux-noble-riscv64-py3.12-gcc14, so
[[ "$BUILD_ENVIRONMENT" == *riscv64*cross* ]]has been false ever since.Everything in that block is skipped as a result: the crossenv at /opt/riscv-cross-env is never activated, so the build runs against the host interpreter; CMAKE_CROSSCOMPILING, CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR are never exported, so CMake never enters cross mode even though CC/CXX point at the riscv64 toolchain; and SLEEF_TARGET_EXEC_USE_QEMU and the workspace chown are missed too. #190887 later added an
elif *riscv64*arm for the new native image, which is the branch this job has been taking.Aligning BUILD_ENVIRONMENT with the image name is the smaller of the two possible fixes and matches the intent of #187821. Widening the guards back to riscv64 would work for this job but would pull the native image, which is genuinely named linux-noble-riscv64-py3.12-gcc14, onto the cross path -- and that path exits 1 when /opt/riscv-cross-env is absent. The string is only consumed as $BUILD_ENVIRONMENT and as the build artifact name, so renaming it is contained; no other pattern in .ci/pytorch/build.sh matches the added "-cross-build".
This commit was authored with the assistance of an AI coding assistant.
Test Plan:
The job is opt-in, so this needs a ciflow/riscv64 run to verify. It has been red since 2025-10 and the last run predates both #190887 and the scikit-build-core migration, so this is expected to uncover further breakage rather than turn the job green on its own -- in particular the crossenv is provisioned with
setuptools pyyaml typing_extensions wheelonly, while the build now invokespython -m build --wheel --no-isolation. Fixing that needs to be informed by a real run, since crossenv splits host and target environments and build backends belong in the host one.Root cause confirmed from the last run's log
(https://github.com/pytorch/pytorch/actions/runs/28817304405), which shows the guard evaluating false:
Checked that no other BUILD_ENVIRONMENT pattern in the build script starts matching once "-cross-build" is appended:
yields aarch64 clang -clang-asan* client cuda cuda13 -debug -full-debug full-debug libtorch riscv64 riscv64cross* rocm -tsan vulkan xla xpu, of which only the two riscv64 patterns match, both intentionally.
Lint: