Skip to content

[Perf] dsv41: Write large eager mHC output directly into MegaMoE buffers - #46056

Open
alphabetc1 wants to merge 2 commits into
sgl-project:mainfrom
alphabetc1:perf/dsv41-mhc-megamoe-producer
Open

alphabetc1 wants to merge 2 commits into
sgl-project:mainfrom
alphabetc1:perf/dsv41-mhc-megamoe-producer

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Remove an intermediate activation copy in large eager DeepSeek-V4.1 prefills by writing mHC output directly into MegaMoE's existing symmetric buffers.

Main's #46163 covers MegaGate decode/target-verify. This PR adds the large eager-prefill path, including routing metadata outside MegaGate, while reusing the shared Mega-mHC output interface.

Modifications

  • Write quantized activations and scales into validated, preallocated buffers without collective allocation.
  • Preserve routing metadata handling and the existing fallback for small/idle batches, CUDA graph capture, and unsupported configurations.
  • Enable the fast path for eager SM10x prefills with at least 16,384 rows.

Adapted from the producer/buffer boundary in DeepInfer.

Accuracy Tests

Merge validation: pre-commit and local mocked control-flow checks passed (4 producer combinations, 24 consumer cases). The GSM8K and earlier exact-output results below predate the merge.

The current-head DSv4.1 DP2/EP2 model CI is a regression check, not coverage of this optimization: it uses --moe-a2a-backend none and does not exercise the >=16,384-row MegaMoE branch. Current-head directed numerical validation passed on two GPU ranks using production producer/consumer code with random weights at model dimensions: 27 records per rank cover 33,792-row batches, unequal and idle ranks, the 16,384-row boundary, routing metadata ownership, descriptor-identity fallback, and actual CUDA graph fallback. Valid quantized activation/scales/routing buffers, mHC boundary outputs, and final MoE outputs matched exactly. Buffer poisoning checks were included. This establishes the tested numerical boundary behavior; it is not a full-checkpoint accuracy evaluation.

Current-head checkpoint-backed shadow validation also passed: 256 measured comparisons per rank at 33,792 rows, visiting source layers 0–19 with real checkpoint weights/activations. The tested mHC/MoE boundary outputs matched exactly. This exercised routing_in_buffer=False; the alternate routing-buffer path is covered by the directed tests above. This is boundary validation, not a current-head full quality benchmark.

Selected current-head /rerun-test runs passed: MegaMoE API, pre-dispatch, mHC kernels, and DSv4.1 DP2/EP2 regression. The model regression's backend limitation above still applies.

Earlier-head validation:

  • Reported exact-output checks passed for uneven/idle batches, routing metadata paths, capacity padding, and CUDA graph fallback.
  • GSM8K (1,314 examples): baseline 97.34%, candidate 97.56%. No accuracy improvement is claimed; most cached-suffix batches exercised the fallback.

Speed Tests and Profiling

Current candidate 9387694b2a1c060ffd7d405a783a77294f481c24 versus baseline 1335d372f0a58857422e40b89a097daa7d3bf86c, using measured script revision 32457f3689d4d38b1ecf774a02bc4de047e51d9b, based on #46006. The identical script file is now published in #46006 at 1aa97c3865fb6b7667f0b8e43f9e316fe79804e4 (SHA256 c402a986dca6d9fdd59e4957eeaf53f37425fb78b39d9ef69c390d0661ec2dc3). This version fixes suffix assignment per rank and can retain raw completions after requests drain; scoring is unchanged.

Matched ABBA, 4,096 requests per rank, 131,072 context tokens, 4,096 uncached suffix tokens, and 32,768 new tokens per rank per step. Both replay paths are enabled, producing 33,792 physical rows per rank. Resolved topology is TP2/EP2/attention-DP2/replica-DP1.

Arm Baseline (ms/step) Candidate (ms/step) Throughput change
A1 → B1 333.772134 333.445486 +0.09796%
B2 → A2 333.733122 333.375643 +0.10723%

The mean throughput improvement is 0.1026%: repeatable within this matched comparison, but very small. Baseline span was 0.01169%, candidate span 0.02095%. All four arms passed the original benchmark guards, drained 8,192 requests, and reproduced their scores exactly from retained completions. Startup Engram huge-page counts matched across arms.

These are fixed-batch engine-step results. Agent/application E2E benefit has not been established. Earlier larger numbers used older code or the pre-fix input generator and are not substituted for this current-head result.

Measured configuration and reproduction command

Use the two source revisions above with the same model files and runtime. Recorded versions: PyTorch 2.14.1+cu130, FlashInfer 0.7.2, sgl-deep-gemm 0.2.3.post2, sgl-flash-mla 1.0.0, deepseek-recipe 0.2.0. Use two GB300 GPUs. Configure a fresh Mooncake master per arm, RDMA transport, and MOONCAKE_GLOBAL_SEGMENT_SIZE=150gb per rank; supply deployment-specific Mooncake addresses and RDMA device externally. Local model/log/output paths are normalized below. The older --data-parallel-size 2 --enable-dp-attention flags resolve to attention-DP2 with one replica for these revisions.

export SGLANG_ENABLE_DP_SPEC_PREFILL_COORDINATION=0
export SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank
export SGLANG_SIMULATE_ACC_LEN=3.51
export SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK=1
export SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1
export SGLANG_OPT_DSV41_BF16_INDEX_LOGITS=1
export SGLANG_OPT_DSV41_MEGA_MHC_PREFILL=1
export SGLANG_UNIFIED_RADIX_TREE_CORE_BACKEND=rust
export SGLANG_DP_USE_GATHERV=0
export SGLANG_LOG_MS=1
export SGLANG_NUMA_BIND_V2=0
export SGLANG_DISAGGREGATION_WAITING_TIMEOUT=900
export SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=65536
export SGLANG_TIMEOUT_KEEP_ALIVE=900
export SGLANG_RAGGED_VERIFY_MODE=static
export SGLANG_DSV41_REASONING_EFFORT=high
export SGLANG_DEFAULT_THINKING=1
export SGLANG_SIMULATE_ACC_METHOD=match-expected
export SGLANG_JIT_DEEPGEMM_PRECOMPILE=0
export SGLANG_SIMULATE_ACC_TOKEN_MODE=real-draft-token
export SGLANG_USE_CUDA_IPC_TRANSPORT=0
export SGLANG_ENABLE_TORCH_COMPILE=0
export SGLANG_ENABLE_DETERMINISTIC_INFERENCE=0

python benchmark/engine_steps/bench_engine_steps.py \
  prefill \
  --engine \
  --dp 2 \
  --num-gpus 2 \
  --context 131072 \
  --new-tokens 4096 \
  --tokens-per-step 32768 \
  --requests 4096 \
  --warmup-steps 5 \
  --timeout 900 \
  --seed 733427905 \
  --server-log server.log \
  --out result.json \
  --prefill-completions completions.json \
  --model-path deepseek-ai/DeepSeek-V4.1-Flash \
  --chunked-prefill-size 67584 \
  --cuda-graph-max-bs-decode 1 \
  --data-parallel-size 2 \
  --disable-decode-cuda-graph \
  --dsv4-attn-backend flashmla_mega \
  --enable-decoder-swa-bounded-replay \
  --enable-dp-attention \
  --enable-dp-lm-head \
  --enable-metrics \
  --expert-parallel-size 2 \
  --max-running-requests 256 \
  --mem-fraction-static 0.9 \
  --moe-a2a-backend megamoe \
  --random-seed 733427905 \
  --served-model-name deepseek-ai/DeepSeek-V4.1-Flash \
  --speculative-algorithm DSPARK \
  --speculative-dspark-block-size 5 \
  --swa-full-tokens-ratio 0.12 \
  --tensor-parallel-size 2 \
  --trust-remote-code \
  --watchdog-timeout 3600 \
  --skip-server-warmup \
  --enable-encoder-swa-bounded-replay \
  --max-prefill-tokens 33792 \
  --enable-unified-cache-external-linker \
  --unified-cache-external-linker-backend mooncake \
  --hicache-storage-backend-extra-config '{"enable_group_semantics":true}' \
  --host 127.0.0.1 \
  --port 30100 \
  --nccl-port 23515

Checklist

  • Format with pre-commit.
  • Extend the existing API test for non-allocating producer lookup.
  • Current-head directed large-row producer/consumer numerical validation.
  • Complete current-head matched ABBA with rank-stable inputs and raw-score reproduction.
  • Maintainer review of scope and supported configurations.

CI States

Latest PR Test (Base): ❌ Run #40067684925
Latest PR Test (Extra): ❌ Run #40067684945
Latest PR Test (AMD ROCm 10): ❌ Run #40067684950

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_mega_moe_deepgemm_api.py test_deepseek_v4_boundary.py test_mhc_kernels.py test_mega_moe_pre_dispatch.py test_deepseek_v41_flash_gb300_tp2ep2.py test_deepseek_v41_flash_gb300_dp2ep2.py test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (2 tests): ✅ View workflow run

cd test/ && python3 registered/unit/layers/moe/test_mega_moe_deepgemm_api.py
cd test/ && python3 registered/unit/models/test_deepseek_v4_boundary.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/layernorm/test_mhc_kernels.py

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/moe/test_mega_moe_pre_dispatch.py
cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

🚀 2-gpu-gb300 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp2ep2.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_mega_moe_deepgemm_api.py test_deepseek_v4_boundary.py test_mhc_kernels.py test_mega_moe_pre_dispatch.py test_deepseek_v41_flash_gb300_tp2ep2.py test_deepseek_v41_flash_gb300_dp2ep2.py test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (2 tests): ✅ View workflow run

cd test/ && python3 registered/unit/layers/moe/test_mega_moe_deepgemm_api.py
cd test/ && python3 registered/unit/models/test_deepseek_v4_boundary.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/layernorm/test_mhc_kernels.py

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/moe/test_mega_moe_pre_dispatch.py
cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

🚀 2-gpu-gb300 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp2ep2.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py

@alphabetc1

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/layers/moe/test_mega_moe_deepgemm_api.py test/registered/kernels/ops/moe/test_mega_moe_pre_dispatch.py test/registered/kernels/ops/layernorm/test_mhc_kernels.py test/registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/layers/moe/test_mega_moe_deepgemm_api.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/moe/test_mega_moe_pre_dispatch.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/layernorm/test_mhc_kernels.py

🚀 2-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant