Repository navigation
fix(pytorch): make MTP rejection sampling reproducible per request - #5193
caikun-pjlab wants to merge 2 commits into
Conversation
RunningLeon
left a comment
There was a problem hiding this comment.
Thanks for this fix. On H200 with Qwen3.5-4B and MTP3, the same-seed serial retry matched all 2,048 tokens after an unrelated request, unlike on main. I recommend addressing the two inline findings before merging: the CUDA bonus draw still depends on batching, and the new recovery kernel fails to compile for ROCm.
| draft_token_ids, | ||
| bonus_token_ids, | ||
| is_greedy=is_greedy, | ||
| random_seeds=expanded_sampling_inputs.random_seeds[::num_tokens], |
There was a problem hiding this comment.
The rejection path now honors the RNG strides, but the bonus path still passes strided seed and offset views to the CUDA multinomial kernel, which indexes them as contiguous. On H200 with fixed logits and all drafts accepted, 7 of 8 bonus tokens differed between batched and singleton runs, and 8 of 8 differed when the batch was reversed. This also reproduces on main, but it leaves the bonus-token reproducibility guarantee incomplete. Please pass the strides to the multinomial kernel or make the bonus RNG views contiguous, and add a regression with an all-accepted draft and a stochastic bonus.
| ) | ||
| prob = tl.maximum(target_prob - draft_prob, 0.0) | ||
| uniform = _rejection_uniform(seed, position, vocab_offset, 2, tl.float32) | ||
| score = tl.where(vocab_mask, prob * (-1.0 / libdevice.log1p(-uniform)), float('-inf')) |
There was a problem hiding this comment.
ROCm also uses CudaOpsBackend. With Triton 3.6.0, this NVIDIA-specific log1p fails to compile for gfx942: Implicit conversion of CUDA __nv_log1pf device function has been dropped. The baseline compiles, and switching only to triton.language.extra.libdevice lets this kernel compile for both gfx942 and sm90. Please use the backend-neutral import and add a ROCm compile check.
Motivation
MTP rejection sampling used process-global CUDA RNG for acceptance decisions and recovery sampling. Consequently, a request's seed did not fully control its sampling results, and unrelated requests could affect reproducibility.
Speculative decoding also advanced the sampling offset by one per round, even when a round emitted multiple tokens.
Modification
Tests
Deployment validation used GLM-5.3-Flash on 8 H200 GPUs with DP=8, EP=8, and 5 MTP draft tokens:
Performance
All nine measured sampler configurations improved over the baseline.
Representative CUDA Graph microbenchmark: batch=32, draft tokens=5, vocabulary=131072.