You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 77b687d
Browse filesBrowse the repository at this point in the historyBrowse files
Validate Method input layouts for non-contiguous tensors (#23820)
### Summary
Fixes#18562
`Method::set_input` now checks the source tensor's strides against the
method input's expected layout (after the input is resized, so the check
matches what kernels read in both portable and ATen mode). A source that
explicitly describes a different layout, such as a permuted view, padded
strides, or a mismatched dim order, is rejected with `InvalidArgument`
instead of being silently reinterpreted. A source with the default
contiguous layout is still accepted, with a log message, when the method
expects a different dim order: existing callers (plain `from_blob`,
`make_tensor_ptr`, Android `Tensor.fromBlob`, the Core ML example
runner) wrap data that is already in the model's layout in a default
tensor just to pass its shape, and the earlier check in #23358 was
backed out (#23595) for rejecting exactly those inputs.
Android `Tensor.fromBlob` also accepts an explicit dim order and plumbs
it through JNI, so channels-last inputs can be described correctly from
Kotlin/Java and callers have a path to stop relying on the contiguous
fallback. Native-created tensors report their dim order back, and
`toByteArray`/`fromByteArray` preserve it.
The pybindings layout conversion was dropped since main already handles
it (#23957).
Review order: the runtime validation commit first, then the Android
Tensor commit.
This PR was authored with AI assistance (Claude Code); the merge
conflict resolution used Codex.
### Test plan
Added a channels-last test model (`ModuleChannelsLast`) and
`method_test` cases covering a matching channels-last input (accepted
and executed), a mismatched explicit layout (rejected), and a default
contiguous input for a channels-last method (accepted).
```bash
cmake --build build --target method_test -j "$(sysctl -n hw.ncpu)"
ctest --test-dir build -R '^method_test$' --output-on-failure
```
Also ran the full CMake `ctest` suite; the only failures were unrelated
environment issues (temp-file creation in `extension_data_loader_test`,
and a `method_meta_test` model export that needs an up-to-date Python
install). Added a `TensorTest` round-trip case for `dimOrder`
serialization; Android tests are covered by CI.
After merging main, rebuilt `method_test` from a clean source snapshot
and reran it successfully, with all 28 enabled cases passing, covering
both input bounds and layout validation. Formatting and `git diff
--check` also passed.
0 commit comments