[Pytorch] Add support for row-wise quanted input for grouped gemm#3244
[Pytorch] Add support for row-wise quanted input for grouped gemm#3244YangFei1990 wants to merge 6 commits into
Conversation
Signed-off-by: YangFei1990 <feiw@nvidia.com>
| and isinstance(input_quantizers[0], MXFP8Quantizer) | ||
| and isinstance(input_.quantizer, MXFP8Quantizer) |
There was a problem hiding this comment.
Should we also assert input_quantizers[0] == input_.quantizer?
There was a problem hiding this comment.
I think == comparison is too strict. It will compare all value fields, I think things like columnwise_usage or optimize_for_gemm could mismatch? Maybe we should explicit assert dype to be E4M3? But let me know if the dispatch output tensor's quantizer can match all value fields.
| with_columnwise: bool, | ||
| tensor_offsets: Optional[torch.Tensor] = None, | ||
| ) -> None: | ||
| """Prepare a rowwise-only MXFP8 grouped input for grouped GEMM (in place). |
There was a problem hiding this comment.
Looks like this helper actually "prepares" colwise besides rowwise. I think we should make the function name and docstring clearer and more consistent.
| format; they are converted to the GEMM-swizzled layout afterwards. | ||
| TODO: optimize and fuse the round-trips requant | ||
| """ | ||
| if grouped_x.rowwise_data is None: |
There was a problem hiding this comment.
Should we validate grouped_x.rowwise_scale as well?
| raise ValueError("Pre-quantized MXFP8 grouped input is missing rowwise data.") | ||
| if grouped_x._with_gemm_swizzled_scales: | ||
| raise NotImplementedError( | ||
| "Pre-quantized MXFP8 grouped input must have scales in compact format." |
| scale_shape = ( | ||
| round_up_to_nearest_multiple(total_tokens, 128), | ||
| round_up_to_nearest_multiple(cols // 32, 4), | ||
| ) |
There was a problem hiding this comment.
Do we need to do this while we already have 128 per-expert-alignment in Dispatch? The total tokens should already be divisible by 128.
For hidden size, there will be an assertion in Dispatch to expect % 512 = 0.
Here, I think we can add assertions instead.
|
|
||
| def prepare_prequantized_mxfp8_grouped_input( | ||
| grouped_x: GroupedTensorStorage, | ||
| quantizer: MXFP8Quantizer, |
There was a problem hiding this comment.
Actually, is there a GroupedQuantizer in TE/PyT? If so, we probably need to use it instead.
There was a problem hiding this comment.
I do not see a GroupedQuantizer in Pytorch. I see what used is tex.group_quantize. Let me know if I missed it. Also can you help me understand the benefit of GroupedQuantizer and how it compared with current Pytorch approach?
Signed-off-by: YangFei1990 <feiw@nvidia.com>
Signed-off-by: YangFei1990 <feiw@nvidia.com>
Greptile SummaryAdds row-wise prequantized MXFP8 support to grouped GEMM paths.
Confidence Score: 3/5The PR is not yet safe to merge because fused grouped MLP still aborts with frozen expert weights when input or routing gradients are required. The basic grouped-linear fixes now supply dequantized gradients for scaled bias and directly reduce ordinary dbias without a wgrad stage, but the fused forward still omits columnwise activation data when weights are frozen and then asserts that this data exists while saving tensors, preventing the targeted frozen-expert backward flow from running. Files Needing Attention: transformer_engine/pytorch/ops/fused/grouped_mlp.py, transformer_engine/pytorch/utils.py, tests/pytorch/test_grouped_mlp.py Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Row-wise MXFP8 GroupedTensor] --> B[Repack as GroupedTensorStorage]
B --> C[Swizzle row-wise scales]
B --> D{Columnwise copy needed?}
D -->|Yes| E[Dequantize]
E --> F[Columnwise-only requantize]
C --> G[Forward or dgrad grouped GEMM]
F --> H[Wgrad grouped GEMM]
E --> I[Bias and routing-scale reductions]
Reviews (4): Last reviewed commit: "allow bias + frozen weight path in prequ..." | Re-trigger Greptile |
Signed-off-by: YangFei1990 <feiw@nvidia.com>
Signed-off-by: YangFei1990 <feiw@nvidia.com>
Signed-off-by: YangFei1990 <feiw@nvidia.com>
|
/te-ci pytorch |
Description
To support the NCCL EP FP8 dispatch, this PR introduce a capability to allow grouped gemm to take input that is already quantized in row-wise.
Fixes # (issue)
Type of change
Checklist: