Repository navigation
Commit 52f9431
authored
Cortex-M: keep the max_pool2d reference off aten's channels-last int8 path (pytorch#21820)
### Summary
aten's channels-last max_pool2d buffers each window index in
vec::int_same_size_t<opmath_t> and guards it with
TORCH_CHECK(input_depth * input_height * input_width <=
numeric_limits<integer_t>::max())
(aten/src/ATen/native/cpu/MaxPoolKernel.cpp,
cpu_max_pool_channels_last). For int8 that caps an image at 127 spatial
elements -- H*W, with channels not counted. Reproduce with:
torch.nn.functional.max_pool2d(
torch.zeros(1, 1, 12, 12, dtype=torch.int8).to(
memory_format=torch.channels_last), 2, 2)
The Cortex-M reference implementation called F.max_pool2d on the tensor
as given, so a channels-last graph tripped that ceiling and raised
before producing a result. That is a limit of the eager kernel and not
of arm_max_pool_s8, so it only ever struck the host dialect stage -- but
it struck it hard, since the whole model test aborts.
Pooling does not depend on the memory format, so the reference now pools
a contiguous copy; the existing return already puts the result back in
channels-last, and .contiguous() aliases an already-contiguous tensor,
so NCHW graphs pay nothing. quantized_max_pool2d_impl is the only
reference in this file that pools in the native int8 dtype: avg_pool2d
dequantizes to float first and both convolutions promote to int32, so
none of them can reach the check.
### Test plan
pytest backends/cortex_m/test/ops/test_max_pool2d.py -- 16 passed, 2
xfailed, dialect and Corstone-300; the new case adds ~2.4 s, in line
with the existing implementation cases. Full backends/cortex_m/test
dialect run: 404 passed. Reverting input.contiguous() fails the new case
with the TORCH_CHECK above.
Authored with assistance from Claude Code.1 parent ae2958e commit 52f9431
2 files changed
Lines changed: 58 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
1498 | 1513 | | |
1499 | | - | |
| 1514 | + | |
1500 | 1515 | | |
1501 | 1516 | | |
1502 | 1517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
37 | 67 | | |
38 | 68 | | |
39 | 69 | | |
| |||
68 | 98 | | |
69 | 99 | | |
70 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
71 | 113 | | |
72 | 114 | | |
73 | 115 | | |
| |||
0 commit comments