Repository navigation
[PyBindings] Torch-free follow-ups: reused inputs, error reasons, bfloat16 shape, dtype names, tests, docs - #24209
Open
pytorchbot wants to merge 1 commit into
Open
pytorchbot wants to merge 1 commit into
pytorchbot wants to merge 1 commit into
Conversation
…oat16 shape, dtype names, tests, docs (#24146) ## 1. Stop reusing overwritten inputs **Problem.** Export lets later values reuse an input's planned memory, so a second run without new inputs gave wrong numbers silently: ```python method.set_inputs([x, y]); method.execute() # right method.execute() # wrong, silently ``` So did `Module.plan_execute()` and partial input lists. **Change.** `Method` installs memory-planned inputs again from what the caller passed at every `execute()`; `Module` does the same for kept inputs a call omits. So inputs are read at each run: in-place edits are seen, a storage change raises "pass it again", and an input the method writes in place (`state.add_(x)`) no longer carries over, unlike repeated `Method::execute()` in C++. The README notes the limits for DLPack producers and `clone_outputs=False` results passed back in. ## 2. Say why a call was refused The runtime logs why it refused a call but returns only a code, so exceptions said just `error 0x10` or `error: 0x22`. Now they include the error lines the runtime logged during the call: ``` RuntimeError: Failed to load method forward, error: 0x22: Failed to load /tmp/executorch_cuda_..._0.so with error: libgomp.so.1: cannot open shared object file ... ``` ## 3. Keep the shape of bfloat16 results A (2, 3) bfloat16 result showed up in the buffer protocol as 12 flat bytes. Now dtypes without a buffer format show as same-width integers in the real shape; DLPack still carries the real dtype. Pass a bfloat16 result back in as the result or its bytes, not `np.asarray(result)`. ## 4. Report a dtype by its name `ExecuTorchResult.dtype` now returns a string such as `"bfloat16"` instead of a NumPy dtype (which raised for bfloat16), and the new `TensorInfo.dtype_name()` returns the same name. The experimental `dtype_name` property is removed. `TensorInfo.dtype()` still returns the integer; its repr prints `dtype=float32`. ## 5. Docs The API reference keeps torch tensors in and out as the main example. A short "Without PyTorch" section shows the fallback: NumPy arrays in, `ExecuTorchResult` values out, and DLPack (for example CuPy) for GPU data. The `Method.execute` docstring follows the same order. ## Testing On Linux x86_64 with an NVIDIA GPU: - Two new tests in `test_pybindings.py` (inputs installed again at each run, and the reason in error messages), plus small edits to existing tests for the bfloat16 buffer view and dtype names. Both new tests, and most of the edited ones, fail on the base branch; all of them pass here. - The existing pybindings tests, including the no-ATen file as CI runs it and the CUDA DLPack tests in both output modes: no new failures. A few tests fail here because a library is missing (quantized ops, pandas); this change does not touch them. - Without PyTorch and libgomp, the CUDA load error now names the missing library. - The basic torch example and the "Without PyTorch" example on the API reference page print the documented output. The second one, and its CuPy steps, also ran with PyTorch imports blocked. - Not tested: the ATen build, macOS, and Windows. (cherry picked from commit 5b14a2f)
pytorchbot
requested review from
JacobSzwejbka,
larryliu0820 and
mergennachin
as code owners
October 27, 2026 19:14
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24209
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit f146df6 with merge base 4db778e ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This branch was successfully 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.
1. Stop reusing overwritten inputs
Problem. Export lets later values reuse an input's planned memory, so a second run without new inputs gave wrong numbers silently:
So did
Module.plan_execute()and partial input lists.Change.
Methodinstalls memory-planned inputs again from what the caller passed at everyexecute();Moduledoes the same for kept inputs a call omits. So inputs are read at each run: in-place edits are seen, a storage change raises "pass it again", and an input the method writes in place (state.add_(x)) no longer carries over, unlike repeatedMethod::execute()in C++. The README notes the limits for DLPack producers andclone_outputs=Falseresults passed back in.2. Say why a call was refused
The runtime logs why it refused a call but returns only a code, so exceptions said just
error 0x10orerror: 0x22. Now they include the error lines the runtime logged during the call:3. Keep the shape of bfloat16 results
A (2, 3) bfloat16 result showed up in the buffer protocol as 12 flat bytes. Now dtypes without a buffer format show as same-width integers in the real shape; DLPack still carries the real dtype. Pass a bfloat16 result back in as the result or its bytes, not
np.asarray(result).4. Report a dtype by its name
ExecuTorchResult.dtypenow returns a string such as"bfloat16"instead of a NumPy dtype (which raised for bfloat16), and the newTensorInfo.dtype_name()returns the same name. The experimentaldtype_nameproperty is removed.TensorInfo.dtype()still returns the integer; its repr printsdtype=float32.5. Docs
The API reference keeps torch tensors in and out as the main example. A short "Without PyTorch" section shows the fallback: NumPy arrays in,
ExecuTorchResultvalues out, and DLPack (for example CuPy) for GPU data. TheMethod.executedocstring follows the same order.Testing
On Linux x86_64 with an NVIDIA GPU:
test_pybindings.py(inputs installed again at each run, and the reason in error messages), plus small edits to existing tests for the bfloat16 buffer view and dtype names. Both new tests, and most of the edited ones, fail on the base branch; all of them pass here.