[PyTorch] Share MXFP8 data tensor between rowwise and columnwise for 2D quantization - #3385
[PyTorch] Share MXFP8 data tensor between rowwise and columnwise for 2D quantization#3385TangChangcheng wants to merge 1 commit into
Conversation
Greptile SummaryThe PR reduces dual-direction 2D MXFP8 weight storage by sharing the byte-identical rowwise data buffer with the columnwise representation.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "[PyTorch] Share MXFP8 data tensor betwee..." | Re-trigger Greptile |
…2D quantization For 2D MXFP8 quantization, the rowwise and columnwise FP8 data tensors are byte-identical since they originate from the same 32x32 block scales. This commit shares a single data buffer between the two representations, halving the FP8 weight memory footprint for 2D-quantized weights. The columnwise data tensor is reused as an alias of the rowwise data tensor in the C++ quantizer, the inner_tensor_specs paths, and the MXFP8Tensor constructor. The cuBLAS GEMM path already selects the appropriate pointer via the transA flag and handles the transpose internally, so no GEMM changes are needed. Signed-off-by: tangcc1127 <tangcc1127@gmail.com>
40d5bf9 to
f926c56
Compare
|
In general I agree with this optimization (although I would like this change to also include a change to the kernel to skip writing the transposed data if the pointers for columnwise and rowwise tensors are the same). One problem is that currently Megatron does not have a good handling of the 2D MXFP8 weights and so enabling this optimization unconditionally could possibly make it unusable there. @kunlunl @zhongbozhu could you comment on this - if we still technically have both rowwise and columnwise tensors on the pyTorch side, but they are backed by the same actual buffer, is the distributed optimizer still going to work or do we need more work for that? |
Summary
For 2D MXFP8 quantization, the rowwise and columnwise FP8 data tensors are byte-identical since they originate from the same 32x32 block scales. Currently, two separate
[M, K]uint8 buffers are allocated and written with identical data.This PR shares a single data buffer between the two representations, halving the FP8 weight memory footprint for 2D-quantized weights.
Changes
quantizer.cpp): Whenwith_2d_quantization && rowwise_usage && columnwise_usage, reuserowwise_data_tensorascolumnwise_data_tensorinstead of allocating a separate buffer.inner_tensor_specs(mxfp8_tensor.py): Skip_columnwise_dataallocation when 2D and rowwise is already enabled.MXFP8Tensor.__new__(mxfp8_tensor.py): Whencolumnwise_datais None and 2D quantization is active, alias it torowwise_data.No GEMM or kernel changes are needed: cuBLAS already selects the appropriate pointer via the
transAflag and handles the transpose internally.Related