[Proposal] Dropless grouped-GEMM experts for deepspeed.moe.layer.MoE (roadmap #8672: block-sparse kernels)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- distributed-systems, machine-learning
Hướng nghiên cứu
Start by reading deepspeed/moe/ep_kernels.py and deepspeed/moe/ep_experts.py for the existing token permutation and grouped GEMM paths, then compare them with deepspeed.moe.layer.MoE and TopKGate. The proposal leaves parameter layout and checkpoint conversion as an open design question and calls for parity, performance, compatibility, and portability experiments. Done means adding the opt-in dropless mode while preserving the existing per-expert checkpoint format and validating it against the listed configurations.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Add a dropless execution mode to the original deepspeed.moe.layer.MoE that replaces capacity padding and the einsum dispatch/combine with the token permutation and grouped GEMM already used by AutoEP (deepspeed/moe/ep_kernels.py, deepspeed/moe/ep_experts.py). This delivers the core idea of MegaBlocks (Gale et al., MLSys 2023) — no token dropping, no padding to a capacity — without porting MegaBlocks' block-sparse kernels or adding a dependency.
Motivation
deepspeed.moe.layer.MoE is still the MoE API for users who build models by hand (Megatron-DeepSpeed style). It offers two modes, and both are costly:
drop_tokens=True: each expert is padded tocapacity_factor × tokens × k / E. Overflow tokens are dropped, and the padding is still computed.drop_tokens=False: every expert is padded to the maximum expert load across the EP group. This is the padding overhead the MegaBlocks paper sets out to remove.
AutoEP already avoids both, but only for Hugging Face models matched by a preset. Baseline measurements (below) show the original layer is 1.4–1.8× slower than AutoEP's dropless path. In no-drop mode it also uses 2.3× the peak memory.
Why not port MegaBlocks directly?
- Upstream MegaBlocks has itself moved its dropless MoE to a grouped-GEMM backend (
grouped_gemm). Its block-sparsestkpath is the older one. - The latest PyPI release (0.10.0) is source-only and pins
torch>=2.7.0,<2.7.1. It cannot be installed next to current torch (2.8 here) without downgrading. - DeepSpeed already contains equivalent, maintained building blocks: Triton permutation kernels,
torch._grouped_mm, an optional Triton grouped GEMM, and fused SwiGLU. These are portable across accelerators via the shared Triton check.
Rough design
- Add a new
MoE(..., drop_tokens=False, dropless_impl="grouped_mm")option, opt-in so existing behaviour is unchanged by default. It requires experts expressible as stacked weights, i.e. the common SwiGLU or GELU MLP. Other expert modules keep the current path and get a clear error if the option is requested. - Gating: reuse
TopKGatefor logits,l_auxand top-k selection, and skip capacity-buffer construction. Emit(indices, weights)per token. - Dispatch: compute per-expert token counts, then all-to-all the counts and the variable-size token buffers across the EP group. This is the same scheme AutoEP uses with
comm_backend="comm". - Compute:
generate_permute_indices→GroupedExperts-style grouped GEMM → unpermute, then a weighted combine. - Parameters: keep the existing
Expertsper-expertnn.Linearlayout as the checkpoint format. Either stack at runtime (benchmark the cost), or add an opt-in stacked layout with checkpoint conversion. This is the main open design question for maintainers. - Accelerator portability: use the existing
torch._grouped_mm/ Triton / for-loop fallback chain inGroupedExpertsunchanged.
Baseline results (already measured)
Setup: Mixtral-style MoE, 0.70B params (12 layers, hidden 1024, 16 experts, top-2, expert FFN 1024), random init with an identical seed and identical initial weights across variants. SFT on packed yahma/alpaca-cleaned (TinyLlama chat template, prompt tokens masked), seq 1024, micro-batch 8 per GPU, bf16, ZeRO-2, EP=2, AdamW, 400 steps. Throughput excludes the first 30 steps.
Hardware: 2× NVIDIA H100 80GB HBM3, driver 595.112.07, CUDA 12.9, torch 2.8.0+cu129, transformers 5.23.0, DeepSpeed 0.20.1+5420b75de.
| Variant | Tokens/s (global) | vs AutoEP | Peak mem/GPU | Routed tokens dropped (mean / last 100 steps) | LM loss (mean of last 50 steps) |
|---|---|---|---|---|---|
| AutoEP, dropless grouped GEMM | 90.4k | 1.00× | 12.5 GiB | 0 / 0 | 4.127 |
MoE drop_tokens=False |
51.1k | 0.57× | 28.3 GiB | 0 / 0 | 4.181 |
MoE capacity factor 1.0 |
56.2k | 0.62× | 13.0 GiB | 21.7% / 10.1% | 4.197 |
MoE capacity factor 1.25 |
62.0k | 0.69× | 13.6 GiB | 14.0% / 3.4% | 4.157 |
MoE capacity factor 2.0 |
58.9k | 0.65× | 15.3 GiB | 6.0% / 0% | 4.124 |
Takeaways:
- The dropless grouped-GEMM path is faster than every capacity setting of the original layer, including ones that drop up to 22% of routed tokens.
- The original layer's no-drop mode costs 2.3× the peak memory.
- At this scale and run length (single seed, 400 steps), the loss differences are small (≤0.07). They are not evidence of a quality gap from dropping either way, and the proposal does not rely on them.
Planned experiments for the implementation PR
- Numerical parity: new dropless mode vs
drop_tokens=Falsewith identical weights. Forward outputs,l_auxand gradients compared to bf16 tolerance. EP=1 and EP=2. - Throughput, peak memory and loss curves on the setup above. Also a finer-grained config (64 experts, top-8) where padding waste is larger, with 3 seeds for the loss comparison.
- Compatibility matrix: ZeRO-0/1/2 (the original MoE layer does not support ZeRO-3 today), bf16 and fp16, EP=1/2. Checkpoint save/load round trip with the existing per-expert format.
- Portability: the for-loop fallback path on a non-CUDA accelerator or on CPU in unit tests.
Not in scope
- AutoEP itself (already dropless).
- MegaBlocks' block-sparse
stkkernels. If maintainers want them as an alternative backend, that can be a follow-up with its own benchmark against grouped GEMM.
Related, separate finding
During baselining, an unmodified HF MixtralForCausalLM (transformers 5.23, native expert loop) under ZeRO-2 with plain data parallelism (2 GPUs) deadlocks at step 1. One rank is in step() → check_overflow, the other is still in backward, so the two ranks' gradient-reduction collective order diverges. Filed separately as #9110.
- Ngôn ngữ chính
- Python
- Star
- 43.3k
- Fork
- 5.1k
- Merge trung bình
- 5 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 85
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của deepspeedai/DeepSpeed
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()Có thể đã có người làm @its-amann đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
deepspeedai/DeepSpeed#9190 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exceptionCó thể đã có người làm @bantianyue đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#9183 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
deepspeedai/DeepSpeed#9019 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped foreverCó thể đã có người làm @damienen đã nhận 26 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
deepspeedai/DeepSpeed#8982 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] OneCycle applies the minimum momentum to the first Adam updateCó thể đã có người làm @ai-yang đã nhận 30 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#8951 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của deepspeedai/DeepSpeed
Issue tương tự
-
area/auth comp/agent P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#161417 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Dao-AILab/flash-attention#3251 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[New Check]: sqlserver_public_network_access_disabledCó thể đã có người làm @pouria-l đã nhận hôm nay. Đang mởfeature-request status/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prowler-cloud/prowler#13607 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
external langchain
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
langchain-ai/docs#8184 ·
Maintainer thường phản hồi trong vòng 1 ngày