Repository navigation
[PyTorch] Handle unpadded dim-0 MXFP8 scales in copy_ - #3992
VikingDeng wants to merge 2 commits into
Conversation
Signed-off-by: viking <[email protected]>
Confidence Score: 4/5
[Medium impact] The changes affect PyTorch callers that copy MXFP8 tensors. Keep scale padding for swizzled tensors before merging. SummaryThe PR changes how
Reviews (2) · Last reviewed commit: "[PyTorch] Handle unpadded dim-0 MXFP8 sc..." · Reviewed by Greptile |
There was a problem hiding this comment.
First Dimension not being padded is intended for FSDP2. Swizzling kernel can directly consume unpadded scales and produce padded swizzled scales needed for the GEMMs.
This is done so that padding will avoid the additional performance penalty
Here is the PR that added that support #3768
Signed-off-by: viking <[email protected]>
|
Thanks for the context on #3768, @vthumbe1503. That makes sense. In #4021, FSDP2 I pushed a follow-up commit ( |
Comments Outside DiffThese findings could not be posted inline.
|
Fixes #4021.
MXFP8Tensor.new_zerosintentionally keeps dim 0 of_rowwise_scale_invand_columnwise_scale_invunpadded for FSDP2 (matching the unpadded-input swizzle path from #3768), whileaten.split.TensorandMXFP8Quantizer.make_emptyallocate dim-0-padded scale buffers. Whenfirst_dimis not a multiple of 128 (such as[64, 128]FSDP2 shards fromfully_shard(te.Linear(128, 128))on 2 GPUs),sharded_param.new_zeros(...).copy_(sharded_param)in FSDP2_init_sharded_paramfails with a scale shape mismatch inaten.copy_.default.Changes
transformer_engine/pytorch/tensor/mxfp8_tensor.py: keepaten.new_zeros.defaultunpadded along dim 0, and updateaten.copy_.defaultfor unswizzledMXFP8Tensorcopies to copy the active dim-0 scale prefix ([:active_rows]) and zero any trailing destination pad rows when dim-0 padding differs. Validate both scale buffers before writing any destination buffers, and route FP8 dtype or logical shape mismatches throughdequantize->expand_as->quantize_.tests/pytorch/test_quantized_tensor.py: add CPU tests covering padded/unpaddednew_zerosandcopy_, thetorch.chunk->new_zeros->copy_FSDP2 shard initialization sequence, non-mutating rejection of incompatible scale shapes, and dtype/shape mismatch fallback.Verification
pytest tests/pytorch/test_quantized_tensor.py -k "test_mxfp8_new_zeros_copies_unpadded_scales or test_mxfp8_copy_preserves_equal_shape_scale_padding or test_mxfp8_fsdp_shard_copy_from_padded_scales or test_mxfp8_copy_rejects_incompatible_scale_shapes or test_mxfp8_copy_falls_back_for_incompatible_tensors": 20 passed (PyTorch 2.14.1, CPU).pre-commit run --files transformer_engine/pytorch/tensor/mxfp8_tensor.py tests/pytorch/test_quantized_tensor.py: passed.pylint==4.1.3 --rcfile=pylintrc transformer_engine/pytorch/tensor/mxfp8_tensor.py: 10.00/10.