Fix PT2E Mul weight quantization for parameters - #4173
ricardoasouz wants to merge 2 commits into
Conversation
54d6cb4 to
471a982
Compare
471a982 to
27676ed
Compare
|
Hi @anzr299, just rebased this onto the latest develop and ran tests/executorch/test_ptq.py again. All 57 tests pass. Let me know if there’s anything else you’d like me to check. Thanks! |
27676ed to
d021470
Compare
|
Rebased onto the latest develop and revalidated using the repository-pinned ExecuTorch environment with Torch 2.13.0. |
72b5311 to
994bd48
Compare
994bd48 to
e475ecb
Compare
|
Updated this PR after re-checking it end-to-end. In the previous revision, the Mul parameter was classified as a weight, but |
|
Hi! It looks like the pre-commit workflow expired while waiting for approval. |
|
I @anzr299, Thanks very much by the observation. |
Signed-off-by: Ricardo Alves de Souza <ricardoasouz@hotmail.com>
27fbafd to
69a44b8
Compare
Summary
Fixes PT2E/TorchAO weight quantization for
aten.mul.Tensorwhen a learned parameter can appear on either operand.Previously,
TorchAOQuantizerAdapterrelied onmetatype.weight_port_idsto determine whether aget_attrinput represented a weight.PTMulMetatypehas no fixed weight port because both:activation * weightweight * activationare valid.
A
torch.nn.ParameterfeedingMulcould therefore be classified as an activation. Simply classifying it as a weight was not sufficient:WeightQuantizationInsertionPointonly preserved the target node, so the dynamically identified input port was lost before MinMax statistics collection.This change:
torch.nn.Parameteron eitherMuloperand as a weight;WeightQuantizationInsertionPoint;The optional input port is routing information only and does not change
WeightQuantizerIdidentity semantics.Concrete model case
I found a concrete case in torchvision's pretrained ConvNeXt-Tiny. Each
CNBlockuses a learned LayerScale parameter in a Mul operation:ConvNeXt-Tiny contains 18 such blocks.
I exported the blocks separately and used a custom TorchAO quantizer to isolate the LayerScale input of the Mul operation.
Without the fix, all 18 LayerScale parameters are classified as activation quantization points. With batch size 2, activation statistics treat axis 0 of the
(dim, 1, 1)parameter as the sample axis.For the first pretrained block:
0.2266329530.0924553070.226632945A regression test was also added using a learned parameter
[0.25, -0.5, 1.0]with batch size 2 and covering both operand orders.Without the fix, the resulting range bound is
0.5833333instead of1.0. With this PR, both operand orders use the correct weight range.Tests
Coverage includes:
activation * Parameter-> weight quantization point;Parameter * activation-> weight quantization point;activation * buffer-> remains activation quantization;batchwise_statistics=True;Validation:
tests/executorch/test_ptq.py-> 62 passed;tests/executorch-> 74 passed, 6 expected xfails;make pre-commit-> all hooks passed;git diff --check-> passed.A broader fallback for arbitrary
torch.nn.Parameterinputs was also checked and rejected because it changed the existing XNNPACK ViT handling of positional embeddings feedingaten.add.Tensor. The final behavior is intentionally limited toPTMulMetatype.Related to #3576.
AI-assisted development
AI tools were used during codebase exploration, hypothesis generation, and drafting. I personally reviewed, tested, and validated the final implementation and can explain and maintain the submitted changes.