Repository navigation
Commit 0720451
[PyBindings] Torch-free follow-ups: reused inputs, error reasons, bfloat16 shape, dtype names, tests, docs (#24209)
## 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.
Co-authored-by: Anthony Shoumikhin <anthony@shoumikh.in>1 parent f76d027 commit 0720451
9 files changed
Lines changed: 343 additions & 153 deletions
File tree
- docs/source
- extension/pybindings
- test
- runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
82 | 94 | | |
83 | 95 | | |
84 | 96 | | |
| |||
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
157 | 174 | | |
158 | 175 | | |
159 | 176 | | |
| |||
0 commit comments