Commit bafed32
Changing logic to deal with graphs with derived quantization spec (#16357)
Summary:
Pull Request resolved: #16357
We want to add a test for `default_addmm_A8W8` to fully finish testing `CadenceDefaultQuantizer`. However there are a couple changes we need to make to the testing function.
## Change 1: We allow passing `None` in the vec of `QuantizationSpec`
This is because the addmm op has 3 inputs: `bias`, `mat1`, `mat2`. The bias uses a `DerivedQuantizationSpec`, which is dynamically constructed with references to the actual graph nodes (`mat1` and `mat2`). We can't construct an identical `DerivedQuantizationSpec` in the test because we'd need to reference the exact same node objects that the quantizer creates internally. Since we can't compare it directly, we use `None` to skip validation for that input. If `mat1` and `mat2` are quantized correctly, the derived bias spec will be correct too.
https://www.internalfb.com/code/fbsource/[2cfdb40fd8b628da2f46366115516408cfb9f50f]/xplat/executorch/backends/cadence/aot/quantizer/patterns.py?lines=91-103
## Change 2: We changed how we iterate through `input_qspec_map`
`input_qspec_map` is a dictionary mapping input nodes to their `qspecs`. The iteration order depends on insertion order, which follows how the quantizer processes `PartitionAnchors`.
Each `QuantizationPattern` implements a `get_anchors()` method that returns a `PartitionAnchors` describing which arguments are inputs, weights, biases and nodes. This is relevant because for `addmm`, the `PartitionAnchors` lists them as `inputs=[(node, 1)], weights=[(node, 2)], biases=[(node, 0, ...)]. ` So the map might iterate in order `mat1, mat2, bias` (args indices 1, 2, 0) rather than `bias, mat1, mat2` (args indices 0, 1, 2).
This means that our previous way of iterating wouldn't work. Thus, we now use the following way to iterate:
```
for input_node, input_qspec in annotation.input_qspec_map.items():
// Find the index of this input node in the op's args
arg_index = None
for i, arg in enumerate(op_node.args):
if arg is input_node:
arg_index = i
break
self.assertIsNotNone(
arg_index,
f"Input node {input_node} not found in op_node.args",
)
# Skip comparison if expected qspec is None (e.g., for DerivedQuantizationSpec)
if expected_input_qspecs[arg_index] is not None:
self.assertEqual(
input_qspec,
expected_input_qspecs[arg_index],
f"Input qspec mismatch at arg index {arg_index}",
)
```
The new code looks up which argument index each input_node corresponds to by searching through `op_node.args`, rather than assuming the enumeration index i matches the argument position.
Reviewed By: hsharma35
Differential Revision: D889557611 parent 74805a1 commit bafed32
1 file changed
+55
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
192 | 203 | | |
193 | 204 | | |
194 | 205 | | |
| |||
406 | 417 | | |
407 | 418 | | |
408 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
409 | 445 | | |
410 | 446 | | |
411 | 447 | | |
| |||
414 | 450 | | |
415 | 451 | | |
416 | 452 | | |
417 | | - | |
| 453 | + | |
418 | 454 | | |
419 | 455 | | |
420 | 456 | | |
| |||
429 | 465 | | |
430 | 466 | | |
431 | 467 | | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
446 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
447 | 486 | | |
448 | 487 | | |
449 | 488 | | |
| |||
0 commit comments