From 7fda3caea41e15cd1f7f1346b825f113e5b27b77 Mon Sep 17 00:00:00 2001 From: Michael <13900043+michaelzhang-ai@users.noreply.github.com> Date: Wed, 20 May 2026 14:01:13 +0800 Subject: [PATCH] [AMD] test(sgl-kernel): seed RNG on ROCm in test_moe_topk_sigmoid to fix tie-break flake (#25356) --- sgl-kernel/tests/test_moe_topk_sigmoid.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sgl-kernel/tests/test_moe_topk_sigmoid.py b/sgl-kernel/tests/test_moe_topk_sigmoid.py index 1f9beb07a..e9a9240ee 100644 --- a/sgl-kernel/tests/test_moe_topk_sigmoid.py +++ b/sgl-kernel/tests/test_moe_topk_sigmoid.py @@ -5,6 +5,19 @@ import pytest import torch from sgl_kernel import topk_sigmoid +_IS_HIP = torch.version.hip is not None + + +@pytest.fixture(autouse=True) +def _deterministic_seed(): + # AMD/ROCm only: pin RNG so torch.randn produces identical gating scores + # across runs. atol=0 indices comparison is otherwise tripped by near-tied + # sigmoid scores where hipCUB's tie-break inside torch.topk disagrees with + # sgl_kernel.topk_sigmoid. Not observed on CUDA, so leave CUDA behavior + # unchanged. + if _IS_HIP: + torch.manual_seed(0) + @pytest.mark.parametrize( "num_tokens, num_experts, topk",