Skip to content

Commit 2ace94d

Browse files
Accept Python buffer inputs (pytorch#23088) (pytorch#23088)
Summary: ## PR stack 1. **[pytorch#23088 — Accept Python buffer inputs](pytorch#23088 ← current 2. [pytorch#23089 — Remove ATen dependency from portable bindings](pytorch#23089) 3. [pytorch#23090 — Add zero-copy DLPack interchange](pytorch#23090) - accept NumPy arrays and other CPU objects implementing the Python buffer protocol directly, without a new public tensor type - alias dense buffer storage for execution and retain the exporter for the full runtime input lifetime - preserve shapes, strides, and dimension order, including channels-last layouts - treat a bare buffer as one input instead of iterating its first dimension - reject calls that mix buffer-backed and torch tensor inputs - keep the existing torch output behavior in ATen-enabled builds Test Plan: - `cmake --build cmake-out-pr1 --target portable_lib -- -j4` - focused tests for NumPy inputs, bare single-buffer dispatch, mixed-protocol rejection, and non-dense views - `python3 -m py_compile extension/pybindings/test/test_pybindings.py extension/pybindings/pybindings.pyi` - `git diff --check` Authored with Codex. Differential Revision: D123775944 Pulled By: JacobSzwejbka
1 parent 4fe4d86 commit 2ace94d

7 files changed

Lines changed: 779 additions & 48 deletions

File tree

‎extension/pybindings/README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" ./install_executorch.sh
2828
## Classes
2929
### ExecuTorchModule
3030
- `plan_execute()`: Plan and execute.
31-
- `run_method()`: Run method.
32-
- `forward()`: Forward. This takes a pytree-flattend PyTorch-tensor-based input.
31+
- `run_method()`: Run a method with either PyTorch tensors or objects that
32+
implement Python's buffer protocol, such as NumPy arrays. A call must use a
33+
single tensor protocol; PyTorch tensors and buffers cannot be mixed.
34+
- `forward()`: Forward. A single buffer may be passed directly; multiple
35+
inputs are passed as a flat sequence.
3336
- `has_etdump()`: Check if etdump is available.
3437
- `write_etdump_result_to_file()`: Write etdump result to a file.
3538
- `__call__()`: Call method.

0 commit comments

Comments
 (0)