Skip to content

Take external tensor pointers untyped so ATen mode works (#22554) - #22554

Open
aforster wants to merge 1 commit into
pytorch:mainfrom
aforster:export-D117853393
Open

Take external tensor pointers untyped so ATen mode works (#22554)#22554
aforster wants to merge 1 commit into
pytorch:mainfrom
aforster:export-D117853393

Conversation

@aforster

@aforster aforster commented Sep 4, 2026

Copy link
Copy Markdown

Summary:

XNNExecutor reaches into tensors through typed accessors in two places, and
both explicitly name the scalar type:

  • prepare_args fills xnn_external_value.data (a void*) via
    mutable_data_ptr<float>(), but a quantized delegate boundary hands XNNPACK
    int8 externals.
  • convert_outputs widens XNNPACK's int32 argmax indices in place by taking an
    int64_t* and an int32_t* view of the same Long tensor buffer, so the
    second view asks a Long tensor for const_data_ptr<int32_t>().

In portable mode torch::executor::Tensor's typed accessor is unchecked, so
both slide through. In ATen mode at::Tensor validates the requested scalar
type and throws expected scalar type Float but found Char at the quantized
boundary, expected scalar type Int but found Long in convert_outputs.

Both sites only ever wanted the raw address (the XNNPACK field is void*; the
int32 view deliberately aliases the int64 buffer), so the scalar type in the
call bought nothing but a check that was wrong. Switched to the untyped
mutable_data_ptr() overload.

Reviewed By: JakeStevens

Differential Revision: D117853393

@pytorch-bot

pytorch-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 3 New Failures

As of commit 1cad08f with merge base 9036d84 (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 4, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 4, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: aforster / name: Andreas Forster (7d92c46)

@meta-codesync

meta-codesync Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Sep 4, 2026

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.

@meta-codesync meta-codesync Bot changed the title Take external tensor pointers untyped so ATen mode works Take external tensor pointers untyped so ATen mode works (#22554) Sep 4, 2026
aforster added a commit to aforster/executorch that referenced this pull request Sep 4, 2026
Summary:

`XNNExecutor` reaches into tensors through typed accessors in two places, and
both explicitly name the scalar type:

- `prepare_args` fills `xnn_external_value.data` (a `void*`) via
  `mutable_data_ptr<float>()`, but a quantized delegate boundary hands XNNPACK
  int8 externals.
- `convert_outputs` widens XNNPACK's int32 argmax indices in place by taking an
  `int64_t*` and an `int32_t*` view of the same Long tensor buffer, so the
  second view asks a Long tensor for `const_data_ptr<int32_t>()`.

In portable mode `torch::executor::Tensor`'s typed accessor is unchecked, so
both slide through. In ATen mode `at::Tensor` validates the requested scalar
type and throws `expected scalar type Float but found Char` at the quantized
boundary, `expected scalar type Int but found Long` in `convert_outputs`.

Both sites only ever wanted the raw address (the XNNPACK field is `void*`; the
int32 view deliberately aliases the int64 buffer), so the scalar type in the
call bought nothing but a check that was wrong. Switched to the untyped
`mutable_data_ptr()` overload.

Reviewed By: JakeStevens

Differential Revision: D117853393
Summary:

`XNNExecutor` reaches into tensors through typed accessors in two places, and
both explicitly name the scalar type:

- `prepare_args` fills `xnn_external_value.data` (a `void*`) via
  `mutable_data_ptr<float>()`, but a quantized delegate boundary hands XNNPACK
  int8 externals.
- `convert_outputs` widens XNNPACK's int32 argmax indices in place by taking an
  `int64_t*` and an `int32_t*` view of the same Long tensor buffer, so the
  second view asks a Long tensor for `const_data_ptr<int32_t>()`.

In portable mode `torch::executor::Tensor`'s typed accessor is unchecked, so
both slide through. In ATen mode `at::Tensor` validates the requested scalar
type and throws `expected scalar type Float but found Char` at the quantized
boundary, `expected scalar type Int but found Long` in `convert_outputs`.

Both sites only ever wanted the raw address (the XNNPACK field is `void*`; the
int32 view deliberately aliases the int64 buffer), so the scalar type in the
call bought nothing but a check that was wrong. Switched to the untyped
`mutable_data_ptr()` overload.

Reviewed By: JakeStevens

Differential Revision: D117853393

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using the untyped address is correct at both sites because the scalar type was never part of the contract: XNNPACK externals are void*, and the output conversion deliberately aliases an int32 producer view over Long storage. The new ATen-mode target is important because portable mode would not catch the invalid typed accessor. Reverse-order widening remains safe here because each int32 element is consumed before its overlapping int64 slot is written.

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