Commit 33f68d1
authored
Cortex-M: annotate and preserve in-place activations (#21819)
### Summary
A model that runs its activation in place emits aten.silu_ rather than
aten.silu in the pre-dispatch graph. This is not a corner case:
Ultralytics gives every Conv block the same class-level nn.SiLU
instance, which initialize_weights() then flips to inplace=True, so one
attribute decides the whole network. ACTIVATION_OP_PATTERNS listed only
the functional overloads, so the quantizer never annotated those nodes;
FoldAndAnnotateQParamsPass then declined to fold them, since it folds
only into nodes carrying ArmAnnotationInfo, and each activation was left
as an fp32 island between two quantized convolutions. On yolo11n that is
76 of them, visible only as a count of unannotated nodes in the
quantizer report.
The other pattern dicts in this file already enumerate the in-place
variants of relu, hardtanh, clamp and hardsigmoid, so this follows that
convention rather than adding a normalization pass. aten.gelu_ is left
out because no idiomatic model reaches it: there is no Tensor.gelu_, and
neither nn.GELU nor F.gelu takes an inplace argument.
Annotating alone is not enough on the compiler path users actually run.
aot_arm_compiler.py preserved hardsigmoid and hardswish through to_edge
but not silu, so silu decomposed into sigmoid * mul, the mul carried
qparams on only one input, and AtenToCortexMPass raised a KeyError. That
made an annotated conv+SiLU model fail to compile where it had
previously produced a working fp32 island. Adding silu to that preserve
list, and to the same list in the overview doc, makes it lower to
quantized_conv2d + quantized_activation instead. The test harness had
silu preserved already, which is why no existing test saw this. That
list is Cortex-M specific, and the Arm backend maps aten.silu to a TOSA
TABLE op, so preserving it does not disturb the Ethos-U path.
### Test plan
pytest backends/cortex_m/test/ops/test_activation_quant.py -- 48 cases,
dialect and Corstone-300, green; 24 dialect cases also green on
cortex-m0plus and cortex-m7. Full backends/cortex_m/test dialect run:
407 passed. Removing the three dict entries fails the three new in-place
cases; removing the preserve entry reproduces the compile failure above
on conv + nn.SiLU(inplace=True).
Authored with assistance from Claude Code.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils
@Sebastian-Larsson @robell1 parent 5c3cb65 commit 33f68d1
4 files changed
Lines changed: 95 additions & 0 deletions
File tree
- backends
- arm/scripts
- cortex_m
- quantizer
- test/ops
- docs/source/backends/arm-cortex-m
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
| 976 | + | |
976 | 977 | | |
977 | 978 | | |
978 | 979 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
| 130 | + | |
129 | 131 | | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
42 | 55 | | |
43 | 56 | | |
44 | 57 | | |
| |||
50 | 63 | | |
51 | 64 | | |
52 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
53 | 77 | | |
54 | 78 | | |
55 | 79 | | |
| |||
61 | 85 | | |
62 | 86 | | |
63 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
64 | 130 | | |
65 | 131 | | |
66 | 132 | | |
| |||
111 | 177 | | |
112 | 178 | | |
113 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
114 | 190 | | |
115 | 191 | | |
116 | 192 | | |
| |||
131 | 207 | | |
132 | 208 | | |
133 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
134 | 214 | | |
135 | 215 | | |
136 | 216 | | |
| |||
151 | 231 | | |
152 | 232 | | |
153 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
154 | 244 | | |
155 | 245 | | |
156 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
0 commit comments