Keep fused MoE weights intact through FSDP gather (1.5% perf improvement on DeepSeek-v3)#4448
Conversation
Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
…e with padding when EP>1 Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
…ndex Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
…ame when EP > 1 Signed-off-by: JAX Toolbox <jax@nvidia.com>
Signed-off-by: JAX Toolbox <jax@nvidia.com>
…adding non-ring of expert with EP=1. Signed-off-by: JAX Toolbox <jax@nvidia.com>
…to_all params computation between te and mt impl to use the same function. Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: Teddy Do Phung <tdophung@login-ptyche02.ptyche.clusters.nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
…mutation Integrate te permutation
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Squash of all integrate_te_permutation commits: - Add te_permutation.py with wrappers for TE token_dispatch/combine/sort_chunks_by_index - Add te_permutation_impl and te_permutation_align_size config flags - Refactor moe.py to support both MT and TE permutation/unpermute paths - Handle ring-of-experts with TE permutation - Fix Nan/Inf issue for TE padding with EP=1
Signed-off-by: tdophung <tdophung@nvidia.com>
Signed-off-by: tdophung <tdophung@nvidia.com>
…old/gmm-for-merge [TE] Integrate TE Grouped GEMM v2
Signed-off-by: tdophung <tdophung@nvidia.com>
…old/fix-te-permute-silent-fallback [TE] Fix TE permute silent fallback issue and fix integration of TE permute
Signed-off-by: tdophung <tdophung@nvidia.com>
20e6333 to
b2609eb
Compare
There was a problem hiding this comment.
sync issue? I assume this file should be untouched in this PR, please note if this understanding is not correct
| fused_qkv: false | ||
| fused_mlp: false | ||
| fused_qkv: False | ||
| fused_mla_lora_proj: False # Fuse MLA Q+KV LoRA up-projections (wq_a+wkv_a) into a single matmul. Requires q_lora_rank > 0. |
There was a problem hiding this comment.
can this be put into a separate PR? Keep PRs small for easier readability and reviewing
| FP8 = "fp8" | ||
| NANOO_FP8 = "nanoo_fp8" | ||
| FP8_NANO_V2 = "fp8_nanoo" | ||
| FP8_GPU = "fp8_gpu" | ||
| FP8_FULL = "fp8_full" | ||
| TE_NO_QUANT = "te_no_quant" |
There was a problem hiding this comment.
can this be part of a separate PR? Is this quantization necessary?
There was a problem hiding this comment.
I see maybe this quantization technique has some dependency with fused vs non fused (which is surprising to me), maybe since fused just doesn't support quantization for now?
| def train_loop(config, recorder, state=None): | ||
| """Main Training loop.""" | ||
| # Initialize HybridEP buffer manager BEFORE setup_train_loop, because model creation | ||
| # during setup traces shard_map which calls hybrid_ep_dispatch_ffi (needs buffer manager). | ||
| if config.use_hybrid_ep: |
There was a problem hiding this comment.
would prefer to put this in a method (to keep train_loop as lean and readable as possible). Either a method defined somewhere outside of train_loop, or possibly in a new te_utils file
Description
Preserve prefused MoE input weights through
shard_mapso FSDP performs one all-gather of the combined weight tensor before the grouped GEMM.Previously, MaxText split the prefused
[experts, embed, 2 * mlp]weight into separatew0andw1tensors beforeshard_map. This could cause XLA to all-gather each half independently and concatenate them again immediately before the grouped GEMM.The updated flow is:
Only the GMM output is split into gate and up-projection activations. This split is required for SwiGLU and is considerably cheaper than splitting, gathering, and concatenating the large weight tensors.
The implementation:
shard_map.The optimization currently applies to sparse MoE training when prefused weights can be consumed directly. Quantized serving and sparsified-weight paths continue using separate
w0andw1tensors. Supporting fused quantized-weight retrieval could be considered as a future improvement.Tests
The original experimental change was profiled with a DeepSeek MoE workload and removed the separate weight-slice operations before the grouped GEMM.
The version rebased onto current
mainhas not been run end-to-end. The patch was checked with:To reproduce the performance comparison, run the same sparse MoE workload with:
Compare the generated HLO or GPU profile before and after this change. The updated version should contain one FSDP all-gather for the combined MoE input weight and should not split and concatenate the weight before the grouped GEMM.
Checklist
gemini-reviewlabel.