Improve TorchAO quantization test coverage and XPU support#13530
Open
jiqing-feng wants to merge 10 commits intohuggingface:mainfrom
Open
Improve TorchAO quantization test coverage and XPU support#13530jiqing-feng wants to merge 10 commits intohuggingface:mainfrom
jiqing-feng wants to merge 10 commits intohuggingface:mainfrom
Conversation
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Contributor
Author
|
Hi @sayakpaul . Would you please review this PR? Thanks! |
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR improves the TorchAO quantization testing infrastructure with several fixes: enabling
int4wotests on Intel XPU, implementing_dequantizefor TorchAO, fixing input dtype mismatches, and fixing training gradient underflow.Changes
Enable int4wo tests on XPU: Removed the
_int4wo_skipmarker that restrictedint4wotests to CUDA only, allowing them to run on all accelerator backends.XPU-specific int4 packing format: Added XPU-specific handling in
_get_quant_config()— Intel XPU requiresint4_packing_format="plain_int32"forInt4WeightOnlyConfig.Fix input dtype casting: Introduced
_get_dummy_inputs_for_model(model)helper inQuantizationTesterMixinto automatically cast floating-point input tensors to the model's parameter dtype, preventing dtype mismatches during quantized model inference.Implement
_dequantizefor TorchAO: Added_dequantize()method inTorchAoHfQuantizerthat iterates allnn.Linearmodules, callsweight.dequantize()onTorchAOBaseTensorweights, and replaces them with standardnn.Parameter. Also fixed_verify_if_layer_quantizedto checkisinstance(module.weight, TorchAOBaseTensor)so dequantized layers are correctly detected as non-quantized.Fix training gradient underflow: Changed autocast dtype from
float16tobfloat16in_test_quantization_training. Float16's limited dynamic range (max ~65504, min subnormal ~5.96e-8) causes gradients to underflow to zero when passing through quantized tensor subclass operations; bfloat16 shares float32's exponent range and avoids this issue.Reduce WanAnimate TorchAO test input sizes: Shrunk dummy inputs in
TestWanAnimateTransformer3DTorchAoto avoid OOM on devices without FlashAttention (e.g. XPU, which falls back to math SDPA and materializes the full O(S²) attention matrix). Reducedhidden_statesfrom (1,36,21,64,64) to (1,36,5,16,16) andface_pixel_valuesfrom (1,3,77,512,512) to (1,3,13,512,512), bringing self-attention sequence length from 21,504 to 320 and peak attention memory from ~74 GiB to ~16 MB. Face frame count (13) is chosen so the face encoder's two stride-2 convolutions produce temporal output 4, plus 1 padding = 5, matchinghidden_statestemporal dim.