Repository navigation
Conversation
_tensor_spec_to_evalue reads a constant's bytes by casting spec.storage.data_ptr() to a host pointer. For CUDA storage that is a device address, so to_executorch() segfaults with no Python exception (pytorch#21545). Check the storage device first and raise an InternalError that names the device and asks the user to move the constants to CPU.
Constants consumed by a delegate do not reach this check, so telling every user to move the model to CPU is wrong for flows that delegate to a device backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24202
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_tensor_spec_to_evaluereads a constant's bytes by castingspec.storage.data_ptr()to a host pointer. When the storage is on CUDA, that pointer is a device address, soto_executorch()segfaults (exit 139) with no Python exception. This PR checks the storage device first and raises anInternalError, as @shoumikhin suggested in #21545, that names the device and says how to fix the export. As discussed in the issue, lowering a CUDA module onto the portable path is not supported; only the way it fails changes. The check applies only to non-empty constants that the emitter serializes itself and whose storage is not on CPU, which are exactly the cases that reach the host read of a device pointer.Fixes #21545
Test plan
New test
test_emit_non_cpu_constant_raisesinexir/emit/test/test_emit.py. It usesmetastorage, which is not host-readable either and needs no accelerator. Without the guard, that case already fails with a wrapped "NULL pointer access"InternalError, so the test matches on the device name in the message.Built and installed from this branch after merging main at d6abe23 (
pip install . --no-build-isolationon Ubuntu 24.04, Python 3.12, torch 2.14.0+cpu):70 passed, 2 skipped, as before the merge. With
_emitter.pyreplaced by main's, the new test fails on the "NULL pointer access" message.lintrunner --skip MYPYreports no issues on the two files.I also ran the reproducer from #21545 on CUDA (RTX 3060 under WSL), with the same package and torch replaced by the cu130 build of the same version (2.14.0+cu130). With main's
_emitter.pyit segfaults in_tensor_spec_to_evalue(exit 139). With this branch it raisesInternalError: ... Constant tensor storage is on device 'cuda:0', ...(exit 1).I used Claude Code to write this PR.
cc @JacobSzwejbka @angelayi @nil-is-all @Gasoonjia @digantdesai