Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/srt/cpu/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Setting torch.manual_seed(0) at the module level is a good step towards making tests deterministic and addressing flakiness. This ensures that each time this test file is executed, PyTorch's random number generation starts from a known state.

A point to consider for future enhancements (though likely outside the scope of this specific PR's diffs) is the level of test isolation. While this global seed makes the file's execution deterministic as a whole:

  1. Tests within this file will still share and advance the global RNG state. If one test consumes a variable amount of random numbers or modifies the RNG in other ways, it can affect the starting state of subsequent tests in the same file.
  2. For stronger isolation, where each test method (test_*) starts with an identical RNG state, seeding could be done in the setUp method of the TestActivation class (or a common base class like CustomTestCase). This would reset the seed before each test method execution.

However, for the immediate goal of reducing flakiness across different runs of the test suite, this global seed is a valid and common approach. If flakiness persists within specific files despite this change, the setUp method approach might be worth investigating.



class TestActivation(CustomTestCase):
M = [128, 129, 257]
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestDecodeAttention(CustomTestCase):
def _run_sdpa_forward_decode(
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestExtendAttention(CustomTestCase):

Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class Mod(nn.Module):
def __init__(self, input_channel, output_channel, has_bias):
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_mla.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestMLA(CustomTestCase):
def _run_sdpa_forward_decode(
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

kernel = torch.ops.sgl_kernel

torch.manual_seed(0)

from utils import (
BLOCK_K,
BLOCK_N,
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestNorm(CustomTestCase):
M = [4096, 1024]
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_rope.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
)
from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestROPE(CustomTestCase):
def test_deepseek_v2_rope(self):
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_shared_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


class TestSharedExpert(CustomTestCase):
M = [2, 121]
Expand Down
2 changes: 2 additions & 0 deletions test/srt/cpu/test_topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from sglang.srt.models.llama4 import Llama4MoE
from sglang.test.test_utils import CustomTestCase

torch.manual_seed(0)


# This is used by the Deepseek-V2 model
class TestGroupedTopK(CustomTestCase):
Expand Down
Loading