Skip to content

[PyBindings] Torch-free follow-ups: reused inputs, error reasons, bfloat16 shape, dtype names, tests, docs - #24209

Open
pytorchbot wants to merge 1 commit into
release/1.6from
cherry-pick-24146-by-pytorch_bot_bot_
Open

pytorchbot wants to merge 1 commit into
release/1.6from
cherry-pick-24146-by-pytorch_bot_bot_

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

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:

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.

…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)
@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔗 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 Failures

As of commit f146df6 with merge base 4db778e (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2026

This branch was successfully deployed

1 active deployment
cadence — f146df67 Deployed Oct 27, 2026 by pytorchbot via hifi5s-op-test / hifi5s #34879
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants