Repository navigation
Conversation
Counts and source token-topk indices pushed to peers are stored as value + 1; the workspace starts zeroed, so 0 means "not arrived". The pull warps poll each count and index with ld.volatile and clear an index slot after reading it (each slot is read once per call; counts are cleared by the existing workspace cleanup). The NVLink barrier before the pull is skipped: the scheduler already polls the per-expert arrival sums. Combine and broadcast-output readiness are tagged with a per-call epoch (grid sync counter 3, bumped by SM 0 after the end barrier) instead of each launch's grid index. The grid-index push and the local readiness clears relied on the removed barrier. Configs with the fused post-expert-norm partials keep the barrier, since their reset is ordered by it. Outputs are bitwise identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…every config Sentinel dispatch: the pull polls per-rank counts only for experts with tokens. A count store for an empty expert can land after the cleanup cleared it, and the next call would read the leftover as its count. Cleanup now waits for every count to arrive before clearing it. Index slots must be zero when a sentinel call starts. Configs that keep the barrier (fused post-expert-norm partials) and the BF16 kernel left raw indices behind, so a buffer shared with a sentinel config could hand a stale index to the pull. Every config now clears a slot after reading it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… different slot extent The BF16 kernel still tags combine readiness with grid index + 1 in the same words the FP8/FP4 kernel now tags with a per-call epoch. In a buffer shared through `base`, a BF16 tag equal to the next FP8 epoch would be accepted as readiness before the peer's L2 writes land. FP8/FP4 epoch tags now set bit 63. The index slots span `num_experts * num_max_tokens_per_rank` words after the fixed signals and are followed by per-call metadata. `SymmBuffer(base=...)` on SM100 now requires the same extent as the base buffer, so no config's metadata can sit in another config's slots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d them Without the pull barrier, a call with no tokens for a rank let the other SMs fetch the per-expert sums, find no work and clear them while SM 0 was still pushing counts to peers; SM 0 then spun forever in fetch_expert_recv_count. Seen as a hang on the first (0-token) call of a broadcast_y stress on CC 10.7. SM 0 now clears the sums after the end barrier's grid sync. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
Superseded by #179 (ports upstream deepseek-ai#525's barrier-free dispatch across both FP8/FP4 and BF16 kernels, removing both the dispatch grid sync and pre-pull NVLink barrier). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Before pulling tokens, every FP8/FP4 Mega MoE call runs a cross-rank NVLink barrier (
kBeforeDispatchPullBarrierTag). The barrier orders two things before the pull:At decode sizes the barrier is a visible part of the call. The scheduler already polls the per-expert arrival sums, so the barrier only has to cover the counts and indices.
Change
sm100_fp8_fp4_mega_moe.cuh, plus the index-slot clear insm100_bf16_mega_moe.cuhand abasecheck indeep_gemm/mega/__init__.py.ld.volatileand subtract 1.kSentinelDispatch).broadcast_y) are tagged with a per-call epoch kept in grid-sync counter 3. SM 0 bumps it after the end barrier. Every rank makes the same calls, so all ranks agree on the tag. This replaces the grid-index push and the local readiness clears, which relied on the removed barrier. The epoch also keeps increasing across CUDA graph replays, where grid indices repeat.base.SymmBuffer(base=...)requires the same index-slot extent on SM100. The slots spannum_experts * num_max_tokens_per_rankwords after the fixedMegaMoESignalsand are followed by per-call metadata, so a config with a different extent would put that metadata in another config's slots. The check compares the aligned token counts (get_token_alignment_for_mega_moe()is 1920 on this B300), so configs that differ only in hidden size, intermediate size or MMA type still share.kSentinelDispatch = not kFusedPostNormPartials), because their reset is ordered by it. They also use the epoch tag.Outputs are bitwise identical.
Tests
B300 SXM6 (148 SMs), 8 ranks on one node, CUDA 13.0, built with
build_sgl_deep_gemm.sh. No localization (CUDA < 13.4). DeepSeek-V3 MoE shape: hidden 7168, intermediate 2048, 256 experts (32 per rank), top-8.Race test. 160 back-to-back calls per arm with no host sync, random per-rank GPU sleeps, and 0..32 tokens per rank (every 7th call has 0 tokens on all ranks). Output compared bitwise against v0.2.9 (same kernel and host code as
dev) on all 8 ranks:ybroadcast_yyy, only 16 of 256 experts routed (most experts empty)post_expert_norm=Trueon the same bufferSymmBuffersharing the memory throughbasepost_expert_norm=TruePost-norm calls are not bitwise reproducible on
devitself (the partial sums of squares are float atomics):devagainstdevdiffers on those calls by up to 3e-3 relative, and this PR shows the same.Workspace invariant. After every call (host sync between calls, mixed post-norm sequence), the index-slot region and the per-rank count words are read back:
basecheck (single rank, BF16 base buffer with 256 experts, 256 tokens):devKernel time (this PR /
dev, CUPTI). Both arms run in one process, switched with_C.init, in alternating rounds. Uniform routing, FP8xFP8. Min over ranks is the mean over calls of the fastest rank's time; max over ranks is the slowest's.Max over ranks is from rounds without host-jitter spikes; spikes appeared in both arms on this shared box.
tests/test_mega_moe.pydefaults (FP8xFP4, hidden 7168, intermediate 3072, 384 experts top-6, 1 shared expert), 8 ranks. Perf only, sincedeep_epis not installed:devBF16 (
--mma-type bf16xbf16, 32 tokens), with the slot clear: 1.002.That test's calls are not rank-aligned, and the shared expert plus intermediate 3072 make the call longer, so the barrier is a smaller share.
The B300 results above were measured on the commit before the sum-clear fix.
Multi-node, CC 10.7 (sm_107a)
4 GPUs per node, 1 to 6 nodes in one NVLink domain, CUDA 13.4, localized weights, 210 SMs. FP8xFP8, hidden 7168, intermediate 2048, top-8, 16 experts per rank (16 ranks = DeepSeek-V3's 256 experts). Kernel time, this PR /
dev, 8 alternating rounds in one process, uniform routing. All outputs bitwise equal todev.On one node, one rank was slower than the rest in both arms by a similar margin, so max over ranks there shows no gain.
Race test on CC 10.7, same rig as above:
ybroadcast_ybroadcast_ybroadcast_yy, 16 experts routedBefore the sum-clear fix,
broadcast_yhung on the first call (0 tokens on every rank) at 4, 8 and 24 ranks;devpassed. The device timeout prints showed one rank's SM 0 missing from both grid syncs while its other SMs had already cleaned. The per-rank-yruns at 24 ranks were measured before the fix and passed.Not covered
SymmBuffer(base=...)callers whose configs differ in slot extent now get an assertion instead of sharing; nothing in this repo or in sglang passesbase.post_expert_normor BF16 mixing.🤖 Generated with Claude Code