From 71d810bbf44b34f3a019730a6878fbcbf2480499 Mon Sep 17 00:00:00 2001 From: Chaojun Zhang Date: Tue, 26 May 2026 10:01:30 +0800 Subject: [PATCH] [XPU] Ensure RNG offset alignment with PyTorch requirements in XPU sampler (#43028) Signed-off-by: chaojun-zhang Signed-off-by: Chaojun Zhang Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- vllm/v1/sample/ops/topk_topp_sampler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vllm/v1/sample/ops/topk_topp_sampler.py b/vllm/v1/sample/ops/topk_topp_sampler.py index 1fc5f6e8cc..f07fa17a9d 100644 --- a/vllm/v1/sample/ops/topk_topp_sampler.py +++ b/vllm/v1/sample/ops/topk_topp_sampler.py @@ -291,7 +291,8 @@ class TopKTopPSampler(nn.Module): ) # The custom XPU sampler kernel consumes RNG values internally, so advance # the default generator's offset to keep future draws deterministic. - offset += logits.numel() + # pytorch: offset must be multiple of 4 + offset = (offset + logits.numel() + 3) // 4 * 4 state.view(torch.int64)[1] = offset generator.set_state(state) return random_sampled, logits_to_return