Use fused pad+MCT when available#142
Conversation
sudhu2k
left a comment
There was a problem hiding this comment.
Otherwise looks good to me.
| if HAVE_TE and is_rocm: | ||
| HAVE_FUSED_PADDING_MCT = hasattr(Fp8Padding, 'compute_padded_splits') | ||
| if not HAVE_FUSED_PADDING_MCT: | ||
| logging.getLogger(__name__).info( |
There was a problem hiding this comment.
Use the logger object from line 72 to do
Use logger.warning(
"message"
) instead
There was a problem hiding this comment.
Pull request overview
This PR adds an ROCm/TransformerEngine-gated fast path for FP8/FP4 MoE that fuses padding with TE’s cast+transpose (MCT) in grouped GEMMs, aiming to avoid BF16 intermediate padding and optionally unpad FC2 outputs.
Changes:
- Detect TE support for fused padding (via
Fp8Padding.compute_padded_splits) and use it to compute paddedm_splitswithout materializing a BF16-padded activation. - Plumb
actual_m_splits(andunpad_outputfor FC2) throughTEGroupedMLPinto the TE GroupedLinear wrapper when supported by the installed TE version.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| megatron/core/transformer/moe/experts.py | Adds ROCm fused padding path and passes actual_m_splits / unpad_output into grouped linears. |
| megatron/core/extensions/transformer_engine.py | Extends TE GroupedLinear wrapper signature and conditionally forwards fused-padding kwargs to TE. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if HAVE_FUSED_PADDING_MCT: | ||
| # ROCm: fuse padding into cast_transpose — compute padded | ||
| # splits without allocating a BF16 intermediate. | ||
| tokens_per_expert = self.quantization_padding.compute_padded_splits(tokens_per_expert) |
There was a problem hiding this comment.
We don't have a fp8 triton groupedgemm kernel for now and we would fall back to hipblasLT Multistream GEMM. But I guess it would be future proof to do this and the better way would be to pad on the gpu tensors directly instead of creating a new tensor from a list.
There was a problem hiding this comment.
I think maybe this should be postponed until we have intentions to do a grouped gemm in triton.
fuses the padding kernels and cast transpose kernels that are used for FP8 MoE operations. Fuses both in forward and backward pass.