Commit 9234be6
authored
Stop emitting an all-zero weight_zero_point (pytorch#23216)
Summary:
A symmetric weight has a zero point of zero in every channel, so the
per-channel path was materializing one int32 per output channel to say
nothing. On wakeword stage 2 that is 4 of the 12 bytes per channel of qparam
overhead, and the HiFi kernels do not even read it: the nnlib entry points
behind conv take a `sym8s` weight operand, which has no weight zero point at
all.
Two halves, both here because the first is inert without the second.
Schema. `Tensor weight_zero_point` becomes `Tensor? weight_zero_point` on the
tensor-qparam overloads of conv1d (ncl/nlc and depthwise), conv2d (nchw/nhwc),
linear and fully_connected. Absent means zero. The asymmetric path is
untouched and still supplies a value, so this is additive rather than a
narrowing and existing callers keep working.
Only the tensor-qparam overloads move - 14 of the 68 declarations. The scalar
(`int`/`SymInt`) forms serialize inline in the instruction rather than as a
constant tensor, so they cost nothing and are left alone.
`quantized_transposed_conv` is left alone too: it is not on the per-channel
emission path, so changing it would be churn without payoff.
It is deliberately not `Tensor? weight_zero_point=None`. The argument sits
mid-signature, ahead of `bias_scale`/`out_scale`, and a positional schema
cannot default an argument before non-defaulted ones. Callers pass `None`
explicitly, which emits no constant. `Tensor? offset` in these same schemas is
the existing precedent for that shape.
Emitter. `weight_zero_point_arg` resolves the zero point and returns `None`
when the vector is all zeros, so fusion omits the operand instead of lifting a
constant. The test decides on the resolved values rather than on whether
`zero_points` was set, so an affine dequantize that happens to be all zeros is
also omitted, and a genuinely nonzero one is still carried through.
Two shapes of kernel needed different handling. Linear and fully_connected read
a single scalar, so they share `resolve_weight_zero_point` in
`generic/operators/quantized_linear.h`. Conv reads a pointer and a stride, so
those kernels fall back to a static zero with a stride of zero, which makes
every channel read that same zero and leaves the inner loops untouched.
Reviewed By: DrJessop
Differential Revision: D118197851
Pull Request resolved: pytorch#232161 parent 06dc587 commit 9234be6
32 files changed
Lines changed: 264 additions & 123 deletions
File tree
- backends/cadence
- aot
- quantizer
- tests
- generic/operators
- hifi/operators
- vision/operators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
| 477 | + | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
| 383 | + | |
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
472 | | - | |
| 472 | + | |
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
552 | | - | |
| 552 | + | |
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
0 commit comments