Repository navigation
Commit 37456c1
Don't Fold In Negative Scalar Multiplies Into Quant/Dequant
Summary:
## Context
The way we lowered the GDN model is we looked at the traced model, and then recreated "stages" of it(i.e created a graph for that stage), and lowered each one of those stages, making them go through the entire compiler pipeline.
That’s usually fine for the ops/nodes in the middle, because they still have the surrounding nodes(producer consumer chain) and those get collapsed/changed in the same way, but in the boundaries, where there’s connections to other other nodes not in the subgraph, the lowering might end up producing a different result than what we expect in the actual graph. The quant/dequant insertion, calibration and FuseMul adjacency depend on the global context so it’ll look different.
That's what happens here.
## Problem
In D117100989, we do `N_c = -A_c` as `aten.full(-1.0) + aten.mul.Tensor`(elementwise kernel). However, before the multiply, there's a quantize, and so multiply gets combined with the quantize. The issue is that this is a negative, and so we're going to have a negative scale in the quantize/dequantize scales, because of `FuseMulTensorIntoDequantPass` and `FuseMulScalarIntoDequantPass` folding it in.
## What this diff does
- Make all three multiply fusion passes stop when the derived scale is not positive.
- Leave the original multiply in the graph when fusion is not valid.
- Add focused tests for tensor-to-quant, tensor-from-dequant, and scalar-from-dequant with multipliers `0.0` and `-1.0`.
- Give the chunk-32 GDN test a test-only gate offset of `-5.0`. This keeps the 32-step cumulative `Gamma_c` values in the useful int16 calibration range. Chunk size 2 stays unchanged.
- Use measured tolerances for the three equivalent chunk-32 pre-trace transforms.
## Result
The full chunk-32 graph keeps one explicit `aten.mul.Tensor` with `aten.full(-1.0)` for `N_c = -A_c`. All quantize, dequantize, requantize, and packed prep scales in the dumped graph are finite and positive.
Reviewed By: ThomasJannaud
Differential Revision: D1208717681 parent bfdfe10 commit 37456c1
2 files changed
Lines changed: 136 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
842 | | - | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
843 | 846 | | |
844 | 847 | | |
845 | 848 | | |
| |||
925 | 928 | | |
926 | 929 | | |
927 | 930 | | |
| 931 | + | |
| 932 | + | |
928 | 933 | | |
929 | 934 | | |
930 | 935 | | |
| |||
984 | 989 | | |
985 | 990 | | |
986 | 991 | | |
987 | | - | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
988 | 996 | | |
989 | 997 | | |
990 | 998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
795 | 840 | | |
796 | 841 | | |
797 | 842 | | |
| |||
880 | 925 | | |
881 | 926 | | |
882 | 927 | | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
883 | 967 | | |
884 | 968 | | |
885 | 969 | | |
| |||
931 | 1015 | | |
932 | 1016 | | |
933 | 1017 | | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
934 | 1060 | | |
935 | 1061 | | |
936 | 1062 | | |
| |||
0 commit comments