[RFC] AutoEP: stage expert weight gradients (dW) across microbatches
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 with deepspeed/moe/ep_experts.py and trace the existing deferred weight-gradient path that uses torch._grouped_mm; then inspect the ZeRO-2 gradient hook and engine accumulation boundary behavior. The issue specifies staging, periodic and overflow flushes, and rejection conditions, but leaves open design questions and calls for broad experiments. Done means implementing the opt-in mode and validating accumulation boundaries, gradients, performance, and memory across the stated scope.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Add an opt-in AutoEP mode that stages the rows of the experts' weight-gradient GEMMs (dW, "tgmm") across microbatches and runs those GEMMs once per several backward passes, instead of once per backward.
Config surface (both under expert_parallel, default off):
deferred_dw_flush_period(int, default1= off): backward passes between two periodic flushes.deferred_dw_rows_per_expert(int, default0= size on first backward): staging capacity per local expert.
Motivation
With hundreds of experts, or with small microbatches, each expert receives few rows per backward. The dW GEMMs then produce three full-size weight gradients (E x hidden x intermediate each) from a handful of rows per expert, and autograd adds each result to the accumulated gradient. The work per backward is dominated by streaming the weights' footprint through HBM, not by arithmetic. Under gradient accumulation this cost is paid on every microbatch although the optimizer only reads the sum.
Design
- Staging.
MoeDeferredDwStaging(indeepspeed/moe/ep_experts.py) holds, per MoE layer and rank, a buffer oflocal_experts x rows_per_expertrows for each tensor the dW GEMMs read (expert input, activation output, output gradient, projection gradients) and a per-expert cursor. A staging backward computes the input gradient as usual, copies each expert's valid rows (no alignment padding) behind its cursor, and returns no weight gradient. - Phase-locked flush. One backward in every
deferred_dw_flush_periodgathers the staged rows expert-major and runs the sametorch._grouped_mmproducts the existing deferred path runs, once. - Overflow-triggered flush. If a backward's rows do not fit behind some expert's cursor, the staged rows are flushed first and the new rows staged in the emptied buffer. The period is not moved. A backward that does not fit an empty buffer computes its own dW immediately.
- Accumulation boundary. The engine marks the backward that closes a gradient accumulation window; that backward always flushes.
engine.step()raises if rows are still staged at a boundary, rather than applying them one step late. - Autograd contract. A flush returns its gradients from the autograd function of the backward that runs it, so ZeRO gradient hooks, reduction, clipping and the optimizer are unchanged. The only core change is that ZeRO-2's gradient hook skips a parameter for which the backward delivered no gradient.
- Scope.
torch._grouped_mmexpert path only; ZeRO 0/1/2; managed gradient accumulation. Rejected (not ignored) withoverlap_weight_grad, AutoEP+AutoTP folding, ZeRO-3, ZenFlow, DeepCompile, unmanaged accumulation.
Costs and risks
- Memory. Each layer on each rank permanently holds
local_experts x rows_per_expert x (2*hidden + 3*intermediate)values in the compute dtype, plus a transient copy of the staged rows during a flush. - Regime dependence. It is a loss when experts receive many rows per backward (see below).
- One host sync per backward per layer to decide whether the rows fit.
- Numerics. The window's sum is formed in one GEMM rather than by adding per-backward results, so values differ by summation order.
Measurements so far
One NVIDIA H200, PyTorch 2.8.0+cu129, bf16. Timing covers only the grouped expert MLP forward+backward per microbatch (not an end-to-end step). Speedup vs. the same module without staging, flush period = accumulation window.
| Shape (local experts, hidden, intermediate) | 8 rows/expert | 32 | 128 | 512 |
|---|---|---|---|---|
| 128, 2048, 768, fused gate+up, window 8 | 1.69x | 1.62x | 1.34x | 0.90x |
| 32, 7168, 2048, window 8 | 1.91x | 1.80x | 1.54x | 1.03x |
| 512, 1024, 512, window 16 | 1.65x | 1.65x | 1.06x | 0.66x |
Staging memory for the first shape at period 8: 0.20 / 0.78 / 3.13 / 12.5 GiB per layer per rank.
Accumulated bf16 gradient error vs. an fp64 reference (relative L2, shapes where the reference was computed): 5.0e-3 to 6.1e-3 without staging, 3.5e-3 with staging.
Planned experiments (not done yet)
- End-to-end optimizer-step time and peak memory on a real MoE model (e.g. Qwen3-30B-A3B, expert parallel 8) with and without staging.
- Loss-curve comparison over a training run.
- DeepEP backend and multi-node runs.
- ZeRO-3 support.
Open questions
- Should the default capacity stay data-dependent (sized on the first backward) or be required explicitly?
- Is a per-backward host sync acceptable, or should the overflow test use the counts the split plan already brings to the host?
- Is dense zero-padded
bmmover the staging buffer worth evaluating against the gather + ragged_grouped_mmused here?
- 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