Activation + GroupedLinear Fusion for MOE and other MOE optimizations - #3238
Activation + GroupedLinear Fusion for MOE and other MOE optimizations#3238vthumbe1503 wants to merge 14 commits into
Conversation
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
for more information, see https://pre-commit.ci
Greptile SummaryThis PR adds three related optimizations to the MoE grouped-linear stack: (1) new
Confidence Score: 5/5Safe to merge; fused forward and backward paths are correctly wired, tensor-offset bookkeeping is consistent across all call sites. The gradient math is correct end-to-end. The saved-tensor layout at index [4] (output_tensor_offsets) is consistently written in forward and read in backward across GroupedLinear, ForwardScaledActivationGroupedLinear, and BackwardScaledActivationGroupedLinear. The unreachable branch does not affect correctness. Files Needing Attention: backward_activation_grouped_linear.py lines 115–121 contain a dead branch with an incorrect gradient-routing assumption that could matter if the op framework semantics change. Important Files Changed
Sequence DiagramsequenceDiagram
participant Input
participant ScaledActivation
participant GroupedQuantize as Grouped Quantize
participant FC2 as GroupedLinear (fc2)
participant Output
Note over Input,Output: Forward Pass (ForwardScaledActivationGroupedLinear)
Input->>ScaledActivation: input_ [tokens, 2H or H]
ScaledActivation->>GroupedQuantize: activation output [tokens, H]
GroupedQuantize->>FC2: grouped_x (quantized)
FC2->>Output: out [tokens, out_features]
Note over Output,Input: Backward Pass (BackwardScaledActivationGroupedLinear)
Output-->>FC2: grad_output [tokens, fc1.out_features]
FC2-->>GroupedQuantize: grouped_dy (quantized dactivation input)
GroupedQuantize-->>ScaledActivation: dense_dy [tokens, fc1.out_features]
ScaledActivation-->>Input: grad_input [tokens, fc1.in_features]
Reviews (8): Last reviewed commit: "Merge branch 'main' into grouped_linear_..." | Re-trigger Greptile |
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
for more information, see https://pre-commit.ci
| ) | ||
|
|
||
|
|
||
| class ForwardScaledActivationGroupedLinear(FusedOperation): |
There was a problem hiding this comment.
There is a trade-off in creating a partially fused module, since we already have FC1 - ACT - FC2 fused module, We need to justify the value of creating a FC1-ACT fusion, instead of just adding features to the grouped_mlp instead.
There was a problem hiding this comment.
This essentially enables the infrastructure to enable (Act + GroupQuant from FC2) fusion, and enables to add fused kernels if possible in the future. cc: @timmoon10
There was a problem hiding this comment.
The other important thought i had in mind is the fact that ScaledActivation today doesnt take in m_splits and it is going to be a lot of upstream disruption to allow for that. And at the same time ScaledActivation can be used after Dense Layers as well and not necessarily after a GroupedLinear layer(and so it might not always need m_splits).
Allowing for this fusion, we allow the m_splits information to be also consumed in the scaled_activation + grouped quantization fusion. Right now the activation kernel that we are using isnt even using the m_splits, but for paged stashing optimization we might need that and we can potentially add a new kernel for that in the future.
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
for more information, see https://pre-commit.ci
|
/te-ci pytorch |
…ns for precomputed tensor offsets in backward Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
…ansformerEngine into grouped_linear_act_fusion
|
/te-ci pytorch |
Description
Better Kernels for Scaled Activations
Activation + GroupQuantize Fusion
Precomputed Tensor Offsets Optimization
BF16 Grouped MLP Performance for num_groups=8 and swiglu activation
MXFP8 Grouped MLP performance for num_groups = 8 and swiglu activation
With CuteDSL fusions
Without CuteDSL fusions
Fixes #2988
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: