Repository navigation
Commit 8426a13
authored
Refresh bypassed op metadata in FuseQuantDequantToRequantizePass (pytorch#22919)
Summary:
`FuseQuantDequantToRequantizePass` cancels a matched `dequantize`/`quantize` pair even when a bypassable op such as `view_copy` sits between them. The inherited `fuse()` rewires those bypassed ops onto the producer's input without refreshing their `meta["val"]`, so they keep the dtype of the operand they no longer consume and the edge verifier rejects the graph:
```
SpecViolationError: These operators are taking Tensor inputs with mismatched dtypes:
Operator: <EdgeOpOverload: aten.view_copy.default>: {'self': torch.float32, '__ret_0': torch.int8}
```
A pass-local `ExportPass` replay used to hide this by recomputing metadata for the whole graph. pytorch#22156 removed those replays and added bounded metadata recompute to the passes it converted; this path was missed.
The pattern arises when an earlier pass legitimately postpones a dequantize below a reshape. The reshape then carries quantized data and is correctly retyped to `int8`; this pass later removes the quantize that justified that dtype, and does not put it back.
## Change
Override `fuse()` to capture the bypassed ops before the rewire and recompute their `meta["val"]` after it.
- `_get_bypassed_nodes` walks the producer's users, skipping the fuse candidates, then emits the set in graph-list order. fx keeps that list topologically sorted, so each node is refreshed after its predecessor, and the walk stops once the set is drained -- it costs the chain's span, not the graph.
- The refresh sits after the rewire and before the `get_fused_node` loop, because `get_fused_node` reads `consumer.args[0].meta["val"]` when it builds the requantize node.
`FuseOpPairsAcrossBranchesPass` is deliberately left alone. It is shared with `FuseTransposeOrPermuteOpPairsPass` and the Arm backend, and the dtype change here is specific to cancelling a quantize/dequantize pair.
No qparams are read or written, no node is added or removed, and no edge is rewired beyond what `fuse()` already did -- only a recorded dtype is corrected to match the input the node now has.
Authored with assistance from Claude Code.
Differential Revision: D120466515
Pull Request resolved: pytorch#229191 parent 3fd80c7 commit 8426a13
2 files changed
Lines changed: 80 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
683 | 684 | | |
684 | 685 | | |
685 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
686 | 739 | | |
687 | 740 | | |
688 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
523 | 550 | | |
524 | 551 | | |
525 | 552 | | |
| |||
0 commit comments