Repository navigation
Commit 4fe4d86
authored
Keep YOLO26Model in contiguous layout after predict() (pytorch#23505)
### Summary
Part of pytorch#23453 (case 1: ultralytics 8.4.133 to 8.4.139).
Starting with 8.4.133, ultralytics converts the model to `channels_last`
during `predict()` on x86 Linux/Windows CPUs with oneDNN. `YOLO26Model`
calls `predict()` once during setup, so the exported program ends up
with channels-last conv weights and a contiguous example input. The
portable convolution kernel then rejects this with
`tensors_have_same_dim_order(in, out)` (`0x12` at instruction 0:0).
This change converts the model back to the default layout after
`predict()`, both in `YOLO26Model` (`model.py`) and in
`export_and_validate.py`, which follows the same pattern. With the
pinned `ultralytics==8.4.14`, this is a no-op. Passing
`channels_last=False` to `predict()`, as `examples/riscv` does, isn't an
option while we're pinned to 8.4.14, since that version rejects the
argument. This does not address case 2 (8.4.140+,
`PendingUnbackedSymbolNotFound` during strict export).
### Test plan
Tested on main @
[238506a](pytorch@238506a),
Ubuntu 24.04 (WSL2), CPU-only torch 2.14.0:
```bash
python -m examples.portable.scripts.export --model_name=yolo26 --strict
./cmake-out/executor_runner --model_path yolo26.pte
```
| ultralytics | before | after |
| ----------- | ------------------------- | ------------------------- |
| 8.4.14 | runs, outputs match eager | runs, outputs match eager |
| 8.4.133 | fails at instruction 0:0 | runs, outputs match eager |
| 8.4.137 | fails at instruction 0:0 | runs, outputs match eager |
Outputs were compared against eager through the portable pybindings
(`atol=1e-3`). The `(1, 300, 6)` top-k output can reorder near-tied
scores with random-noise inputs, including on unmodified main, so for
that output I compared sorted scores instead (8/8 seeds match).
No automated test was added. CI currently runs yolo26 with the pinned
8.4.14, where this change is a no-op, and a unit test would require
installing ultralytics and downloading the weights. Happy to add one if
there is a preferred place for it.
Authored with assistance from Claude Code.
cc @nil-is-all1 parent d9649f7 commit 4fe4d86
2 files changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
0 commit comments