Take external tensor pointers untyped so ATen mode works (#22554) - #22554
Take external tensor pointers untyped so ATen mode works (#22554)#22554aforster wants to merge 1 commit into
Conversation
🔗 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 FailuresAs of commit 1cad08f with merge base 9036d84 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@aforster has exported this pull request. If you are a Meta employee, you can view the originating Diff in D117853393. |
This PR needs a
|
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
7d92c46 to
5f53ca6
Compare
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
5f53ca6 to
1cad08f
Compare
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
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.
Summary:
XNNExecutorreaches into tensors through typed accessors in two places, andboth explicitly name the scalar type:
prepare_argsfillsxnn_external_value.data(avoid*) viamutable_data_ptr<float>(), but a quantized delegate boundary hands XNNPACKint8 externals.
convert_outputswidens XNNPACK's int32 argmax indices in place by taking anint64_t*and anint32_t*view of the same Long tensor buffer, so thesecond view asks a Long tensor for
const_data_ptr<int32_t>().In portable mode
torch::executor::Tensor's typed accessor is unchecked, soboth slide through. In ATen mode
at::Tensorvalidates the requested scalartype and throws
expected scalar type Float but found Charat the quantizedboundary,
expected scalar type Int but found Longinconvert_outputs.Both sites only ever wanted the raw address (the XNNPACK field is
void*; theint32 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