Skip to content

Accept Python buffer inputs (#23088) - #23088

Merged
JacobSzwejbka merged 1 commit into
mainfrom
codex/pybindings-lightweight-tensor
Oct 7, 2026
Merged

JacobSzwejbka merged 1 commit into
mainfrom
codex/pybindings-lightweight-tensor

Conversation

@JacobSzwejbka

@JacobSzwejbka JacobSzwejbka commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

PR stack

  1. https://github.com/pytorch/executorch/issues/23088 — Accept Python buffer inputs ← current
  2. https://github.com/pytorch/executorch/issues/23089 — Remove ATen dependency from portable bindings
  3. https://github.com/pytorch/executorch/issues/23090 — Add zero-copy DLPack interchange
  • 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

@pytorch-bot

pytorch-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23088

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 7 Pending

As of commit c86d6eb with merge base 27d124f (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 Sep 23, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
Comment thread extension/pybindings/pybindings.cpp Resolved
@JacobSzwejbka
JacobSzwejbka force-pushed the codex/pybindings-lightweight-tensor branch from aa799c3 to a5984ca Compare September 28, 2026 18:39
@JacobSzwejbka JacobSzwejbka changed the title [PyBindings] Add a lightweight tensor type [PyBindings] Accept Python buffer inputs Sep 28, 2026
@shoumikhin

This comment has been minimized.

@shoumikhin shoumikhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome improvement!
PTAL at the unresolved comments.

@meta-codesync

meta-codesync Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@JacobSzwejbka has imported this pull request. If you are a Meta employee, you can view this in D123775944.

@meta-codesync meta-codesync Bot changed the title [PyBindings] Accept Python buffer inputs Accept Python buffer inputs (#23088) Oct 7, 2026
meta-codesync Bot pushed a commit that referenced this pull request Oct 7, 2026
Summary:
## PR stack

1. **[#23088 — Accept Python buffer inputs](#23088 ← current
2. [#23089 — Remove ATen dependency from portable bindings](#23089)
3. [#23090 — Add zero-copy DLPack interchange](#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
@meta-codesync
meta-codesync Bot force-pushed the codex/pybindings-lightweight-tensor branch from a872db6 to a9d73d7 Compare October 7, 2026 03:46
@meta-codesync

meta-codesync Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@JacobSzwejbka has exported this pull request. If you are a Meta employee, you can view the originating Diff in D123775944.

Summary:
## PR stack

1. **[#23088 — Accept Python buffer inputs](#23088 ← current
2. [#23089 — Remove ATen dependency from portable bindings](#23089)
3. [#23090 — Add zero-copy DLPack interchange](#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
@shoumikhin

Copy link
Copy Markdown
Contributor

Heads up: the last change before the merge stopped validating torch inputs, and two tests now fail
on main. test_unsupported_dim_order aborts the test worker, and test_method_unsupported_dim_order
gets a RuntimeError instead of the ValueError it expects.

The abort is reachable from user code, and it is not about rank. In the portable build, forward()
now kills the process on a channels-last-3d torch tensor, even when the method was exported with
that same shape and layout:

x = torch.randn(1, 2, 3, 4, 5).to(memory_format=torch.channels_last_3d)
module.forward([x])   # aborts, whatever the method expects

The new channels-last-3d branch in run_method builds the tensor and then calls
alias_etensor_to_attensor. That function only accepts contiguous or 4-d channels-last tensors,
and it fails with a fatal check instead of an exception. Before this pull request, the same input
got the "should be contiguous or channels-last" error.

Restoring the rank check would make both tests pass, but it would hide the abort, not remove it.
The abort needs its own fix, for example dropping the channels-last-3d branch from the module path.
The method path does not call alias_etensor_to_attensor, and the ATen build passes torch tensors
straight through, so the strided ATen case would not be affected.

This branch was previously deployed

1 inactive deployment
cadence — c86d6eb7 Deployed Oct 7, 2026 by meta-codesync[bot]
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants