Repository navigation
[Fix] sampling: deterministic top-p / top-k renorm when tp_size > 1 (TP rank divergence in DFlash/DSpark) - #38565
Conversation
451ff7b to
bad0bb3
Compare
|
/rerun-test registered/kernels/ops/moe/test_renorm.py registered/sampling/test_sampling_mask.py registered/core/test_basic_sanity_dflash.py registered/core/test_basic_sanity_dspark.py registered/core/test_basic_sanity_eagle3.py registered/spec/dflash/test_dflash.py registered/spec/eagle/test_eagle_reject_sampling.py registered/spec/eagle/test_spec_eagle.py registered/spec/dspark/test_dspark_kernel_parity.py |
|
Results for 🚀 🚀 🚀 |
bad0bb3 to
f063d4c
Compare
|
/rerun-group unit/mem_cache |
|
/rerun-group unit/observability |
|
/rerun-test test_metrics.py test_radix_cache_hit.py test_unified_radix_cache_kl_full.py test_hicache_variants.py test_hicache_storage.py |
|
Results for 🚀 🚀 🚀 🚀 ⛔ |
|
Results for 🚀 |
|
Results for 🚀 🚀 🚀 |
|
/rerun-test registered/kernels/ops/moe/test_renorm.py registered/sampling/test_sampling_mask.py registered/core/test_basic_sanity_dflash.py registered/core/test_basic_sanity_dspark.py registered/core/test_basic_sanity_eagle3.py registered/spec/dflash/test_dflash.py registered/spec/eagle/test_eagle_reject_sampling.py registered/spec/eagle/test_spec_eagle.py registered/spec/dspark/test_dspark_kernel_parity.py |
|
Results for 🚀 🚀 🚀 |
f063d4c to
e8ee82d
Compare
|
/rerun-test registered/kernels/ops/moe/test_renorm.py registered/sampling/test_sampling_mask.py registered/core/test_basic_sanity_dflash.py registered/core/test_basic_sanity_dspark.py registered/core/test_basic_sanity_eagle3.py registered/spec/dflash/test_dflash.py registered/spec/eagle/test_eagle_reject_sampling.py registered/spec/eagle/test_spec_eagle.py registered/spec/dspark/test_dspark_kernel_parity.py |
|
Results for 🚀 🚀 🚀 |
…multicast probe in the gather-selection test sgl-project#42863's selection tests predate sgl-project#41888's has_multicast_support() probe, which now runs before the symmetric-memory rendezvous inside _build_multimem. Without a stub they only pass on a multicast-capable host (the probe is real in the test process), so sgl-project#38565's own CI would flip on hardware. Drive the probe from the tests' existing multicast= knob and cover the claims-support-but-no-alias case with the new probe= override.
…/deferred/avoid map - 3A [24-35]: NVFP4 MoE boot sgl-project#39807/sgl-project#40173, block-FP8 TP refine sgl-project#42566, k-pool indexer split sgl-project#43619, SM120 skinny GEMM sgl-project#42865/sgl-project#42867, DeepGEMM warmup guards sgl-project#32686/sgl-project#43712, autotune sgl-project#43363/sgl-project#40420, mHC overlap sgl-project#42985, FP8-einsum precompile sgl-project#42821. - 3B [36-43]: PCIe CustomAllreduce VMM sgl-project#44448, EP local expert ids sgl-project#44480, shm TP broadcast sgl-project#44202, PCIe-IPC all-gather sgl-project#42863 + multicast guard sgl-project#41888, TP-sampling consistency sgl-project#41916/sgl-project#38565, draft embed/lm_head VRAM sgl-project#37155. - sgl-project#39807 toolchain commit verified safe against our CUDA_HOME=12.9 pin (cu13 fallback needs CUDA_HOME unset AND glibc>=2.41; we are 2.39). - stack_want.txt: execution-status banner. Branch tip 5dd6ec7.
|
@claude review |
|
Please fix conflicts |
flashinfer's default top-p / top-k renorm kernels pool partial sums with float atomics, so TP ranks can disagree in the last bits on identical logits. A shared sampling coin that lands in that gap commits different tokens on different ranks, and the ranks later wedge in a collective. Route every renorm call (plain sampler, min_p path, EAGLE / DFlash / DSpark verify) through one policy module that picks flashinfer's is_deterministic=True variants whenever the TP group has more than one rank, or under --enable-deterministic-inference. A single rank keeps the fast kernels. The fast fallbacks come from the per-platform table in kernels/ops/sampling/renorm.py, which gains an XPU entry. Co-Authored-By: Claude Fable 5.1 <[email protected]>
53c104d to
c33aeb0
Compare
The sampling-mask capture tests build a bare Sampler and patch only the sampler module's get_exec. The renorm policy reads the published parallel and exec config on every call, so without a published config the first top-k renorm raised "config namespace 'exec' not published". Install the same scoped override the policy test uses (tp_size=1: fast kernels, as before) for the lifetime of each test. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
/rerun-failed-ci |
Summary
flashinfer's default top-p / top-k renorm kernels are non-deterministic (float
atomicAdd); because of this, TP ranks that renormalize the same logits can produce different results. Every consumer of this output (plain sampler, spec-verify) samples against a deterministic coin and commits the result to per-rank KV/radix state. A coin that lands in between the cross-rank gap causes divergence across ranks, and NCCL collectives hang.Previous PRs (#33549, #33289; #33614) work around this issue by broadcasting rank 0's decision. This PR addresses the root cause and avoids an extra collective, by routing the renorm through flashinfer's
is_deterministic=Truevariants. This is turned on where it matters:attn_tp_size > 1--enable-deterministic-inferenceSGLANG_RENORM_DETERMINISTIC=1/0Repro + results are below. With all relevant broadcasts turned off, the fast kernels reproduce the hang on H100 and B200 in every run. The deterministic kernels never diverge, and the end-to-end cost to TPOT is marginal.
Root cause
sgl_kernel.top_p_renorm_probandtop_k_renorm_probforward to flashinfer.RadixTopKRenormProbMultiCTA) pools the kept mass with a float atomic.is_deterministic=Trueat unchanged latency.target_probs(top-p/top-k output) against a shared coin and samples the bonus token fromrelu(q - p).min_ppath calls the same kernels with no broadcast (SGLANG_SYNC_TOKEN_IDS_ACROSS_TPis off by default).top_p=1.0, which skips the kernel entirely.Repro
Setup
ed8c3139, flashinfer 0.7.1, sgl_kernel 0.4.10) with this PR applied.z-lab/LLaMA3.1-8B-Instruct-DFlash-UltraChat,temperature=1.0,top_p=0.9, 32 concurrent multi-turn streams, fp8 KV.SGLANG_SPEC_TP_SYNC=offturns off [Spec] Fix Dspark and Dflash state divergence across TP rank #33614's broadcasts.SYNC_TOKEN_IDS_ACROSS_TP,SGLANG_SYNC_TOKEN_IDS_ACROSS_TPare off by default.SGLANG_RENORM_DETERMINISTIC=1.{rng state, prefix_lens, draft_tokens, target_logits, target_probs, accept_len, bonus, commit_lens, out_tokens}and reports the first field that differs.top_p_renorm_probtwice on the same input on one rank, counting mismatches after.Results
"knob" below refers to the new env-var,
SGLANG_RENORM_DETERMINISTIC=1.target_probsdifferencetarget_probsdivergences, none reaches a tokenEvery fast-kernel run with the broadcast off hung, with the same recorded chain each time:
target_probsdiffers between ranks while logits,prefix_lensand RNG are identical.bonus/out_tokensdiffer on one rank.draft_tokensdiffer.Toggling only the knob to 1 on the same image, model, load and probe consistently results in zero divergences, zero rank-local mismatches, and no hang.
Kernel measurements
We perform 99 repeated calls on byte-identical input. Settings: flashinfer 0.7.1, vocab 128256, H100. B200 and B300 give the same results.
nondetrefers to calls that differ from call 0.is_deterministic=TrueWe observe the following:
cudaMalloc, so there is no overhead.End-to-end speed
Setup
sglang.bench_serving, random 512-in / 256-out, 400 prompts, concurrency 32.min_p=0.05(the path the default policy makes deterministic), host Amin_p=0.05top_p=0.9(knob=1 forces the verify path deterministic too)top_p=0.9Thus, we see that there is no measureable end-to-end cost, including the forced-deterministic verify path; the accept length is also unchanged.
The renorm kernel runs once per step over
batch_sizerows (sampler) orbatch_size x draft_tokensrows (verify), so deterministic top-p adds ~0.03 ms at 32 rows and ~0.2 ms at 256 rows, which is small compared to a step of several ms.Modifications
python/sglang/srt/layers/sampling_renorm.py(new):renorm_deterministic(ranks_agree)policy.top_p_renorm_prob/top_k_renorm_probfor the sampler andspec_top_p_renorm_prob/spec_top_k_renorm_probfor verify, calling flashinfer withis_deterministic=Truewhen appropriate (sgl_kernelas before otherwise).inspect.signature), so an older flashinfer degrades to the fast kernel rather than failing on the first sampled request.sgl_kernel's own single-CTA kernel is already deterministic; no int32-sensitive code is added there.layers/sampler.py,speculative/dflash_utils.py,speculative/eagle_utils.pyare the only renorm call sites, and now they import from the module above._sync_token_ids_across_tpandspec_tp_sync.pycomments name the renorm kernels as a known source of nondeterminism and point at the knob.environ.py:SGLANG_RENORM_DETERMINISTICnext to the other determinism knobs.test/registered/kernels/ops/sampling/test_renorm.py: existing correctness tests run through the new module; regression tests call each deterministic renorm 30 times on a flat 256 x 128256 input and assert bit-identical output (the default kernels fail this 30 of 30); scoped runtime-context fixture.test/registered/unit/sampling/test_renorm_policy.py(CPU): single rank fast; TP=2 sampler deterministic and verify fast;--enable-deterministic-inferenceforces on; env overrides both ways.The fix lives in
sglangrather than thesgl_kernelwrappers, becausesglang-kernelships as a pinned prebuilt wheel. A wrapper change there is not testable in CI, and is not delivered until the next kernel release.This fix is Complementary to #33614: the broadcast keeps replicated state safe against any future non-deterministic operator. This removes the one we found, so rank 0's own output and every other consumer of
target_probs(logprobs, sampling masks) become reproducible too.Checklist
CI States
Latest PR Test (Base): ✅ Run #40984177426
Latest PR Test (Extra): ❌ Run #40984177227
Latest PR Test (AMD ROCm 10): ⏳ Run #40984177258