[Platform] Deprecate seed_everything (#31659)

Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
This commit is contained in:
wangxiyuan
2026-01-04 18:34:04 -08:00
committed by GitHub
parent 367856de14
commit bb4337b34c
77 changed files with 219 additions and 171 deletions
+1
View File
@@ -154,3 +154,4 @@ The interface for the model/module may change during vLLM's development. If you
!!! warning "Deprecations" !!! warning "Deprecations"
- `use_v1` parameter in `Platform.get_attn_backend_cls` is deprecated. It has been removed in v0.13.0. - `use_v1` parameter in `Platform.get_attn_backend_cls` is deprecated. It has been removed in v0.13.0.
- `_Backend` in `vllm.attention` is deprecated. It has been removed in v0.13.0. Please use `vllm.attention.backends.registry.register_backend` to add new attention backend to `AttentionBackendEnum` instead. - `_Backend` in `vllm.attention` is deprecated. It has been removed in v0.13.0. Please use `vllm.attention.backends.registry.register_backend` to add new attention backend to `AttentionBackendEnum` instead.
- `seed_everything` platform interface is deprecated. It will be removed in v0.14.0 or later. Please use `vllm.utils.torch_utils.set_random_seed` instead.
+2 -1
View File
@@ -26,6 +26,7 @@ from vllm.distributed.parallel_state import (
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
from ...models.registry import HF_EXAMPLE_MODELS from ...models.registry import HF_EXAMPLE_MODELS
from ...utils import ( from ...utils import (
@@ -301,7 +302,7 @@ def async_tp_pass_on_test_model(
dtype: torch.dtype, dtype: torch.dtype,
dynamic: bool, dynamic: bool,
): ):
current_platform.seed_everything(0) set_random_seed(0)
device = torch.device(f"cuda:{local_rank}") device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -32,6 +32,7 @@ from vllm.model_executor.layers.quantization.utils.w8a8_utils import (
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
from ...utils import has_module_attribute, multi_gpu_test from ...utils import has_module_attribute, multi_gpu_test
from ..backend import TestBackend from ..backend import TestBackend
@@ -263,7 +264,7 @@ def all_reduce_fusion_pass_on_test_model(
enable_rms_norm_custom_op, enable_rms_norm_custom_op,
enable_quant_fp8_custom_op, enable_quant_fp8_custom_op,
): ):
current_platform.seed_everything(0) set_random_seed(0)
device = torch.device(f"cuda:{local_rank}") device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -31,6 +31,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import GroupShape
from vllm.model_executor.layers.quantization.utils.w8a8_utils import Fp8LinearOp from vllm.model_executor.layers.quantization.utils.w8a8_utils import Fp8LinearOp
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
from ...utils import multi_gpu_test from ...utils import multi_gpu_test
from ..backend import TestBackend from ..backend import TestBackend
@@ -232,7 +233,7 @@ def sequence_parallelism_pass_on_test_model(
fuse_norm_quant: bool, fuse_norm_quant: bool,
dynamic: bool, dynamic: bool,
): ):
current_platform.seed_everything(0) set_random_seed(0)
device = torch.device(f"cuda:{local_rank}") device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -8,6 +8,7 @@ import torch
import vllm.v1.attention.backends.rocm_aiter_fa # noqa: F401 import vllm.v1.attention.backends.rocm_aiter_fa # noqa: F401
from vllm.attention.utils.fa_utils import is_flash_attn_varlen_func_available from vllm.attention.utils.fa_utils import is_flash_attn_varlen_func_available
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
NUM_HEADS = [(4, 4), (8, 2)] NUM_HEADS = [(4, 4), (8, 2)]
HEAD_SIZES = [128, 256] HEAD_SIZES = [128, 256]
@@ -104,7 +105,7 @@ def test_varlen_with_paged_kv(
if not is_flash_attn_varlen_func_available(): if not is_flash_attn_varlen_func_available():
pytest.skip("flash_attn_varlen_func required to run this test.") pytest.skip("flash_attn_varlen_func required to run this test.")
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
+2 -1
View File
@@ -13,6 +13,7 @@ from vllm.attention.layer import Attention
from vllm.attention.layers.mm_encoder_attention import MMEncoderAttention from vllm.attention.layers.mm_encoder_attention import MMEncoderAttention
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.mem_utils import get_max_shared_memory_bytes from vllm.utils.mem_utils import get_max_shared_memory_bytes
from vllm.utils.torch_utils import set_random_seed
FLOAT32_BYTES = torch.finfo(torch.float).bits // 8 FLOAT32_BYTES = torch.finfo(torch.float).bits // 8
# This will change depending on the compute capability. # This will change depending on the compute capability.
@@ -150,7 +151,7 @@ def test_paged_attention(
global PARTITION_SIZE global PARTITION_SIZE
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
scale = float(1.0 / (head_size**0.5)) scale = float(1.0 / (head_size**0.5))
num_query_heads, num_kv_heads = num_heads num_query_heads, num_kv_heads = num_heads
+9 -8
View File
@@ -9,6 +9,7 @@ import torch
from tests.kernels.utils import DEFAULT_OPCHECK_TEST_UTILS, opcheck from tests.kernels.utils import DEFAULT_OPCHECK_TEST_UTILS, opcheck
from vllm import _custom_ops as ops from vllm import _custom_ops as ops
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
COPYING_DIRECTION = [("cuda", "cpu"), ("cuda", "cuda"), ("cpu", "cuda")] COPYING_DIRECTION = [("cuda", "cpu"), ("cuda", "cuda"), ("cpu", "cuda")]
DTYPES = [torch.bfloat16, torch.float] DTYPES = [torch.bfloat16, torch.float]
@@ -64,7 +65,7 @@ def test_reshape_and_cache(
) -> None: ) -> None:
if kv_cache_dtype == "fp8" and head_size % 16: if kv_cache_dtype == "fp8" and head_size % 16:
pytest.skip() pytest.skip()
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
torch.cuda.set_device(device) torch.cuda.set_device(device)
# Create a random slot mapping. # Create a random slot mapping.
@@ -185,7 +186,7 @@ def test_reshape_and_cache_flash(
kv_cache_layout: str, kv_cache_layout: str,
implementation: str, implementation: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
torch.cuda.set_device(device) torch.cuda.set_device(device)
assert implementation in ["cuda", "triton"] assert implementation in ["cuda", "triton"]
@@ -355,7 +356,7 @@ def test_swap_blocks(
if kv_cache_dtype == "fp8" and head_size % 16: if kv_cache_dtype == "fp8" and head_size % 16:
pytest.skip() pytest.skip()
current_platform.seed_everything(seed) set_random_seed(seed)
src_device = device if direction[0] == "cuda" else "cpu" src_device = device if direction[0] == "cuda" else "cpu"
dst_device = device if direction[1] == "cuda" else "cpu" dst_device = device if direction[1] == "cuda" else "cpu"
@@ -444,7 +445,7 @@ def test_fp8_e4m3_conversion(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
low = -224.0 low = -224.0
high = 224.0 high = 224.0
@@ -507,7 +508,7 @@ def test_concat_and_cache_mla(
device: str, device: str,
kv_cache_dtype: str, kv_cache_dtype: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -584,7 +585,7 @@ def test_concat_and_cache_ds_mla(
if dtype.itemsize != 2: if dtype.itemsize != 2:
pytest.skip("ds_mla only supports 16-bit input") pytest.skip("ds_mla only supports 16-bit input")
kv_cache_dtype = "fp8_ds_mla" kv_cache_dtype = "fp8_ds_mla"
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -695,7 +696,7 @@ def test_swap_blocks_mla(
device: str, device: str,
kv_cache_dtype: str, kv_cache_dtype: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
torch.cuda.set_device(device) torch.cuda.set_device(device)
@@ -947,7 +948,7 @@ def test_concat_and_cache_mla_cpu(
) -> None: ) -> None:
device = "cpu" device = "cpu"
kv_cache_dtype = "auto" kv_cache_dtype = "auto"
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
total_slots = num_blocks * block_size total_slots = num_blocks * block_size
@@ -6,6 +6,7 @@ import pytest
import torch import torch
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.flash_attn import cascade_attention, merge_attn_states from vllm.v1.attention.backends.flash_attn import cascade_attention, merge_attn_states
try: try:
@@ -39,7 +40,7 @@ def test_merge_kernel(
dtype: torch.dtype, dtype: torch.dtype,
): ):
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_query_heads = num_heads[0] num_query_heads = num_heads[0]
num_kv_heads = num_heads[1] num_kv_heads = num_heads[1]
assert num_query_heads % num_kv_heads == 0 assert num_query_heads % num_kv_heads == 0
@@ -103,7 +104,7 @@ def test_cascade(
f'to: "{fa_version_unsupported_reason(fa_version)}"' f'to: "{fa_version_unsupported_reason(fa_version)}"'
) )
current_platform.seed_everything(0) set_random_seed(0)
window_size = (-1, -1) window_size = (-1, -1)
scale = head_size**-0.5 scale = head_size**-0.5
+2 -1
View File
@@ -8,6 +8,7 @@ import pytest
import torch import torch
from vllm.platforms import CpuArchEnum, current_platform from vllm.platforms import CpuArchEnum, current_platform
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.cpu_attn import _get_attn_isa from vllm.v1.attention.backends.cpu_attn import _get_attn_isa
if not current_platform.is_cpu(): if not current_platform.is_cpu():
@@ -190,7 +191,7 @@ def varlen_with_paged_kv(
use_sink: bool, use_sink: bool,
isa: str, isa: str,
) -> None: ) -> None:
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
+2 -1
View File
@@ -6,6 +6,7 @@ import pytest
import torch import torch
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
try: try:
from vllm.vllm_flash_attn import ( from vllm.vllm_flash_attn import (
@@ -129,7 +130,7 @@ def test_varlen_with_paged_kv(
"Flash attention with quantized inputs is only " "Flash attention with quantized inputs is only "
"supported on version 3 with bfloat16 base type" "supported on version 3 with bfloat16 base type"
) )
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
+5 -4
View File
@@ -5,6 +5,7 @@
import pytest import pytest
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
try: try:
import flashinfer import flashinfer
@@ -101,7 +102,7 @@ def test_flashinfer_decode_with_paged_kv(
sliding_window: int | None, sliding_window: int | None,
) -> None: ) -> None:
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(kv_lens) num_seqs = len(kv_lens)
num_query_heads = num_heads[0] num_query_heads = num_heads[0]
num_kv_heads = num_heads[1] num_kv_heads = num_heads[1]
@@ -196,7 +197,7 @@ def test_flashinfer_prefill_with_paged_kv(
sliding_window: int | None, sliding_window: int | None,
) -> None: ) -> None:
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
@@ -299,7 +300,7 @@ def test_flashinfer_prefill_with_paged_fp8_kv(
) -> None: ) -> None:
pytest.skip("TODO: fix the accuracy issue") pytest.skip("TODO: fix the accuracy issue")
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
@@ -409,7 +410,7 @@ def test_flashinfer_decode_with_paged_fp8_kv(
) -> None: ) -> None:
# test doesn't work for num_heads = (16,16) # test doesn't work for num_heads = (16,16)
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(kv_lens) num_seqs = len(kv_lens)
num_query_heads = num_heads[0] num_query_heads = num_heads[0]
num_kv_heads = num_heads[1] num_kv_heads = num_heads[1]
@@ -10,6 +10,7 @@ from tests.kernels.quantization.nvfp4_utils import (
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.math_utils import round_up from vllm.utils.math_utils import round_up
from vllm.utils.torch_utils import set_random_seed
if not current_platform.is_device_capability_family(100): if not current_platform.is_device_capability_family(100):
pytest.skip( pytest.skip(
@@ -80,7 +81,7 @@ def test_flashinfer_trtllm_decode_with_baseline(
has_sinks: bool, has_sinks: bool,
) -> None: ) -> None:
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(42) set_random_seed(42)
q_quant_dtype, kv_quant_dtype, o_quant_dtype = quant_dtypes q_quant_dtype, kv_quant_dtype, o_quant_dtype = quant_dtypes
q_quant_dtype = q_quant_dtype or dtype q_quant_dtype = q_quant_dtype or dtype
@@ -279,7 +280,7 @@ def test_flashinfer_trtllm_prefill_with_baseline(
has_sinks: bool, has_sinks: bool,
) -> None: ) -> None:
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(42) set_random_seed(42)
q_quant_dtype, kv_quant_dtype, o_quant_dtype = quant_dtypes q_quant_dtype, kv_quant_dtype, o_quant_dtype = quant_dtypes
q_quant_dtype = q_quant_dtype or dtype q_quant_dtype = q_quant_dtype or dtype
@@ -5,7 +5,7 @@ import pytest
import torch import torch
from vllm.model_executor.layers.lightning_attn import linear_decode_forward_triton from vllm.model_executor.layers.lightning_attn import linear_decode_forward_triton
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
NUM_HEADS = [4, 8] NUM_HEADS = [4, 8]
HEAD_SIZES = [64] HEAD_SIZES = [64]
@@ -124,7 +124,7 @@ def test_linear_decode_forward_triton(
torch.set_default_device("cuda") torch.set_default_device("cuda")
torch.manual_seed(42) torch.manual_seed(42)
torch.cuda.manual_seed_all(42) torch.cuda.manual_seed_all(42)
current_platform.seed_everything(42) set_random_seed(42)
base = 0.01 base = 0.01
q = base * torch.randn(batch_size, num_heads, 1, head_size, dtype=dtype) q = base * torch.randn(batch_size, num_heads, 1, head_size, dtype=dtype)
k = base * torch.randn(batch_size, num_heads, 1, head_size, dtype=dtype) k = base * torch.randn(batch_size, num_heads, 1, head_size, dtype=dtype)
@@ -167,7 +167,7 @@ def test_linear_decode_forward_triton_with_padding(
torch.set_default_device("cuda") torch.set_default_device("cuda")
torch.manual_seed(42) torch.manual_seed(42)
torch.cuda.manual_seed_all(42) torch.cuda.manual_seed_all(42)
current_platform.seed_everything(42) set_random_seed(42)
batch_size = 4 batch_size = 4
base = 0.01 base = 0.01
@@ -231,7 +231,7 @@ def test_lightning_attention_reference(
torch.set_default_device("cuda") torch.set_default_device("cuda")
torch.manual_seed(42) torch.manual_seed(42)
torch.cuda.manual_seed_all(42) torch.cuda.manual_seed_all(42)
current_platform.seed_everything(42) set_random_seed(42)
base = 0.01 base = 0.01
q = base * torch.randn(batch_size, num_heads, seq_len, head_size, dtype=dtype) q = base * torch.randn(batch_size, num_heads, seq_len, head_size, dtype=dtype)
+3 -2
View File
@@ -19,6 +19,7 @@ from vllm.platforms import current_platform
from vllm.platforms.cpu import CpuPlatform from vllm.platforms.cpu import CpuPlatform
from vllm.platforms.cuda import CudaPlatform from vllm.platforms.cuda import CudaPlatform
from vllm.platforms.rocm import RocmPlatform from vllm.platforms.rocm import RocmPlatform
from vllm.utils.torch_utils import set_random_seed
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@@ -123,7 +124,7 @@ def test_mha_attn_forward(
dtype: torch.dtype, dtype: torch.dtype,
device: str, device: str,
): ):
current_platform.seed_everything(0) set_random_seed(0)
torch.set_default_device(device) torch.set_default_device(device)
torch.set_default_dtype(dtype) torch.set_default_dtype(dtype)
@@ -168,7 +169,7 @@ def test_mha_attn_varlen_forward(
dtype: torch.dtype, dtype: torch.dtype,
device: str, device: str,
): ):
current_platform.seed_everything(0) set_random_seed(0)
torch.set_default_device(device) torch.set_default_device(device)
torch.set_default_dtype(dtype) torch.set_default_dtype(dtype)
@@ -13,7 +13,7 @@ import torch.nn.functional as F
from vllm.attention.ops.chunked_prefill_paged_decode import chunked_prefill_paged_decode from vllm.attention.ops.chunked_prefill_paged_decode import chunked_prefill_paged_decode
from vllm.attention.ops.prefix_prefill import context_attention_fwd from vllm.attention.ops.prefix_prefill import context_attention_fwd
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE, set_random_seed
NUM_HEADS = [64] NUM_HEADS = [64]
NUM_QUERIES_PER_KV = [1, 64] NUM_QUERIES_PER_KV = [1, 64]
@@ -125,7 +125,7 @@ def test_contexted_kv_attention(
): ):
pytest.skip("ROCm custom paged attention does not support fp8_e5m2 KV cache") pytest.skip("ROCm custom paged attention does not support fp8_e5m2 KV cache")
current_platform.seed_everything(0) set_random_seed(0)
torch.set_default_device(device) torch.set_default_device(device)
# Need this, otherwise when we capture the graph the process # Need this, otherwise when we capture the graph the process
@@ -346,7 +346,7 @@ def test_contexted_kv_attention_alibi(
): ):
pytest.skip("ROCm custom paged attention does not support fp8_e5m2 KV cache") pytest.skip("ROCm custom paged attention does not support fp8_e5m2 KV cache")
current_platform.seed_everything(0) set_random_seed(0)
torch.set_default_device(device) torch.set_default_device(device)
# Need this, otherwise when we capture the graph the process # Need this, otherwise when we capture the graph the process
@@ -8,6 +8,7 @@ import torch
from vllm.attention.ops.triton_unified_attention import unified_attention from vllm.attention.ops.triton_unified_attention import unified_attention
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.math_utils import next_power_of_2 from vllm.utils.math_utils import next_power_of_2
from vllm.utils.torch_utils import set_random_seed
NUM_HEADS = [(4, 4), (8, 2)] NUM_HEADS = [(4, 4), (8, 2)]
HEAD_SIZES = [128, 256] HEAD_SIZES = [128, 256]
@@ -113,7 +114,7 @@ def test_triton_unified_attn(
) -> None: ) -> None:
torch.set_default_device("cuda") torch.set_default_device("cuda")
current_platform.seed_everything(0) set_random_seed(0)
num_seqs = len(seq_lens) num_seqs = len(seq_lens)
query_lens = [x[0] for x in seq_lens] query_lens = [x[0] for x in seq_lens]
kv_lens = [x[1] for x in seq_lens] kv_lens = [x[1] for x in seq_lens]
+3 -3
View File
@@ -18,7 +18,7 @@ from vllm.model_executor.layers.activation import (
SiluAndMul, SiluAndMul,
SwigluOAIAndMul, SwigluOAIAndMul,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
DTYPES = [torch.half, torch.bfloat16, torch.float] DTYPES = [torch.half, torch.bfloat16, torch.float]
NUM_TOKENS = [7, 83, 2048] # Arbitrary values for testing NUM_TOKENS = [7, 83, 2048] # Arbitrary values for testing
@@ -52,7 +52,7 @@ def test_act_and_mul(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
x = torch.randn(num_tokens, 2 * d, dtype=dtype) x = torch.randn(num_tokens, 2 * d, dtype=dtype)
if activation == "silu_and_mul": if activation == "silu_and_mul":
@@ -129,7 +129,7 @@ def test_activation(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
x = torch.randn(num_tokens, d, dtype=dtype) x = torch.randn(num_tokens, d, dtype=dtype)
layer = activation[0]() layer = activation[0]()
@@ -8,6 +8,7 @@ from tests.kernels.utils import opcheck
from vllm.model_executor.layers.layernorm import RMSNorm from vllm.model_executor.layers.layernorm import RMSNorm
from vllm.model_executor.layers.rotary_embedding import RotaryEmbedding from vllm.model_executor.layers.rotary_embedding import RotaryEmbedding
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
DTYPES = [torch.bfloat16, torch.float16] DTYPES = [torch.bfloat16, torch.float16]
IS_NEOX = [True, False] IS_NEOX = [True, False]
@@ -64,7 +65,7 @@ def test_fused_qk_norm_rope_matches_reference(
rotary_ratio: float, rotary_ratio: float,
): ):
torch.set_default_device(device) torch.set_default_device(device)
current_platform.seed_everything(seed) set_random_seed(seed)
num_heads, num_kv_heads, head_dim = 16, 4, 128 num_heads, num_kv_heads, head_dim = 16, 4, 128
num_tokens = 4 num_tokens = 4
+3 -3
View File
@@ -7,7 +7,7 @@ import torch
from tests.kernels.quant_utils import FP8_DTYPE from tests.kernels.quant_utils import FP8_DTYPE
from tests.kernels.utils import opcheck from tests.kernels.utils import opcheck
from vllm.model_executor.layers.layernorm import RMSNorm from vllm.model_executor.layers.layernorm import RMSNorm
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
DTYPES = [torch.half, torch.bfloat16, torch.float] DTYPES = [torch.half, torch.bfloat16, torch.float]
NUM_TOKENS = [7, 83, 4096] # Arbitrary values for testing NUM_TOKENS = [7, 83, 4096] # Arbitrary values for testing
@@ -34,7 +34,7 @@ def test_rms_norm(
device: str, device: str,
strided_input: bool, strided_input: bool,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
layer = RMSNorm(hidden_size).to(dtype=dtype) layer = RMSNorm(hidden_size).to(dtype=dtype)
layer.weight.data.normal_(mean=1.0, std=0.1) layer.weight.data.normal_(mean=1.0, std=0.1)
@@ -88,7 +88,7 @@ def test_fused_rms_norm_quant(
device: str, device: str,
strided_input: bool, strided_input: bool,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
weight = torch.empty(hidden_size, dtype=dtype).normal_(mean=1.0, std=0.1) weight = torch.empty(hidden_size, dtype=dtype).normal_(mean=1.0, std=0.1)
+2 -1
View File
@@ -10,6 +10,7 @@ from transformers import __version__ as TRANSFORMERS_VERSION
from vllm.model_executor.layers.rotary_embedding import get_rope from vllm.model_executor.layers.rotary_embedding import get_rope
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.transformers_utils.config import get_config from vllm.transformers_utils.config import get_config
from vllm.utils.torch_utils import set_random_seed
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -24,7 +25,7 @@ def generate_test_data(
device: torch.device, device: torch.device,
): ):
"""Generate test data for given configuration.""" """Generate test data for given configuration."""
current_platform.seed_everything(42) set_random_seed(42)
# Create 2D positions (3, num_tokens) for multimodal case # Create 2D positions (3, num_tokens) for multimodal case
positions = torch.randint( positions = torch.randint(
0, max_position_embeddings // 4, (3, num_tokens), device=device 0, max_position_embeddings // 4, (3, num_tokens), device=device
+2 -2
View File
@@ -9,7 +9,7 @@ import torch
from tests.kernels.allclose_default import get_default_atol, get_default_rtol from tests.kernels.allclose_default import get_default_atol, get_default_rtol
from vllm.model_executor.layers.rotary_embedding import get_rope from vllm.model_executor.layers.rotary_embedding import get_rope
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
IS_NEOX_STYLE = [True, False] IS_NEOX_STYLE = [True, False]
DTYPES = [torch.bfloat16, torch.float] DTYPES = [torch.bfloat16, torch.float]
@@ -79,7 +79,7 @@ def test_rotary_embedding(
if rotary_dim is None: if rotary_dim is None:
rotary_dim = head_size rotary_dim = head_size
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
if rotary_dim is None: if rotary_dim is None:
rotary_dim = head_size rotary_dim = head_size
+4 -4
View File
@@ -12,7 +12,7 @@ from vllm.model_executor.layers.mamba.ops.causal_conv1d import (
causal_conv1d_fn, causal_conv1d_fn,
causal_conv1d_update, causal_conv1d_update,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
def causal_conv1d_ref( def causal_conv1d_ref(
@@ -154,7 +154,7 @@ def test_causal_conv1d_update(dim, width, seqlen, has_bias, silu_activation, ity
if itype == torch.bfloat16: if itype == torch.bfloat16:
rtol, atol = 1e-2, 5e-2 rtol, atol = 1e-2, 5e-2
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
batch = 2 batch = 2
x = torch.randn(batch, dim, seqlen, device=device, dtype=itype) x = torch.randn(batch, dim, seqlen, device=device, dtype=itype)
x_ref = x.clone() x_ref = x.clone()
@@ -201,7 +201,7 @@ def test_causal_conv1d_update_with_batch_gather(
rtol, atol = 1e-2, 5e-2 rtol, atol = 1e-2, 5e-2
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
padding = 5 if with_padding else 0 padding = 5 if with_padding else 0
padded_batch_size = batch_size + padding padded_batch_size = batch_size + padding
@@ -278,7 +278,7 @@ def test_causal_conv1d_varlen(
if itype == torch.bfloat16: if itype == torch.bfloat16:
rtol, atol = 1e-2, 5e-2 rtol, atol = 1e-2, 5e-2
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
seqlens = [] seqlens = []
batch_size = batch batch_size = batch
padding = 3 if with_padding else 0 padding = 3 if with_padding else 0
+2 -2
View File
@@ -12,8 +12,8 @@ from vllm.distributed.parallel_state import (
initialize_model_parallel, initialize_model_parallel,
) )
from vllm.model_executor.layers.mamba.mamba_mixer2 import Mixer2RMSNormGated from vllm.model_executor.layers.mamba.mamba_mixer2 import Mixer2RMSNormGated
from vllm.platforms import current_platform
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
@multi_gpu_test(num_gpus=2) @multi_gpu_test(num_gpus=2)
@@ -68,7 +68,7 @@ def mixer2_gated_norm_tensor_parallel(
dtype: torch.dtype, dtype: torch.dtype,
device: str, device: str,
): ):
current_platform.seed_everything(0) set_random_seed(0)
device = torch.device(f"cuda:{local_rank}") device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(device) torch.cuda.set_device(device)
+6 -6
View File
@@ -13,7 +13,7 @@ from vllm.model_executor.layers.mamba.ops.mamba_ssm import (
selective_scan_fn, selective_scan_fn,
selective_state_update, selective_state_update,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
def selective_state_update_ref( def selective_state_update_ref(
@@ -271,7 +271,7 @@ def test_selective_scan(
rtolw = max(rtolw, rtol) rtolw = max(rtolw, rtol)
atolw = max(atolw, atol) atolw = max(atolw, atol)
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
batch_size = 1 batch_size = 1
dim = 4 dim = 4
dstate = 8 dstate = 8
@@ -401,7 +401,7 @@ def test_selective_state_update(dim, dstate, has_z, itype):
if torch.version.hip: if torch.version.hip:
atol *= 2 atol *= 2
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
batch_size = 1 batch_size = 1
state = torch.randn(batch_size, dim, dstate, dtype=itype, device=device) state = torch.randn(batch_size, dim, dstate, dtype=itype, device=device)
x = torch.randn(batch_size, dim, device=device, dtype=itype) x = torch.randn(batch_size, dim, device=device, dtype=itype)
@@ -438,7 +438,7 @@ def test_selective_state_update_varlen(dim, dstate, has_z, itype, max_seq_len):
if torch.version.hip: if torch.version.hip:
atol *= 2 atol *= 2
# set seed # set seed
current_platform.seed_everything(0) set_random_seed(0)
batch_size = 4 batch_size = 4
token_counts = torch.randint(1, max_seq_len + 1, (batch_size,), device=device) token_counts = torch.randint(1, max_seq_len + 1, (batch_size,), device=device)
total_tokens = int(token_counts.sum().item()) total_tokens = int(token_counts.sum().item())
@@ -857,7 +857,7 @@ def test_selective_state_update_with_num_accepted_tokens(
if torch.version.hip: if torch.version.hip:
atol *= 2 atol *= 2
current_platform.seed_everything(0) set_random_seed(0)
batch_size = 4 batch_size = 4
tokens_per_seq = torch.randint(1, max_seq_len + 1, (batch_size,), device=device) tokens_per_seq = torch.randint(1, max_seq_len + 1, (batch_size,), device=device)
@@ -983,7 +983,7 @@ def test_selective_state_update_varlen_with_num_accepted(
if torch.version.hip: if torch.version.hip:
atol *= 2 atol *= 2
current_platform.seed_everything(0) set_random_seed(0)
batch_size = 4 batch_size = 4
tokens_per_seq = torch.randint(1, max_seq_len + 1, (batch_size,), device=device) tokens_per_seq = torch.randint(1, max_seq_len + 1, (batch_size,), device=device)
+2 -2
View File
@@ -9,7 +9,7 @@ from einops import rearrange, repeat
from vllm.model_executor.layers.mamba.ops.ssd_combined import ( from vllm.model_executor.layers.mamba.ops.ssd_combined import (
mamba_chunk_scan_combined_varlen, mamba_chunk_scan_combined_varlen,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.mamba2_attn import compute_varlen_chunk_metadata from vllm.v1.attention.backends.mamba2_attn import compute_varlen_chunk_metadata
# Added by the IBM Team, 2024 # Added by the IBM Team, 2024
@@ -82,7 +82,7 @@ def ssd_minimal_discrete(X, A, B, C, block_len, initial_states=None):
def generate_random_inputs(batch_size, seqlen, n_heads, d_head, itype, device="cuda"): def generate_random_inputs(batch_size, seqlen, n_heads, d_head, itype, device="cuda"):
current_platform.seed_everything(0) set_random_seed(0)
A = -torch.exp(torch.rand(n_heads, dtype=itype, device=device)) A = -torch.exp(torch.rand(n_heads, dtype=itype, device=device))
dt = F.softplus( dt = F.softplus(
torch.randn(batch_size, seqlen, n_heads, dtype=itype, device=device) - 4 torch.randn(batch_size, seqlen, n_heads, dtype=itype, device=device) - 4
@@ -10,7 +10,7 @@ from tqdm import tqdm
from vllm.config import VllmConfig, set_current_vllm_config from vllm.config import VllmConfig, set_current_vllm_config
from vllm.model_executor.layers.fused_moe.config import FUSED_MOE_UNQUANTIZED_CONFIG from vllm.model_executor.layers.fused_moe.config import FUSED_MOE_UNQUANTIZED_CONFIG
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
from .common import ( from .common import (
Config, Config,
@@ -40,7 +40,7 @@ def rank_worker(
config: Config, config: Config,
weights: WeightTensors, weights: WeightTensors,
): ):
current_platform.seed_everything(pgi.rank) set_random_seed(pgi.rank)
# sanity check # sanity check
from vllm import envs from vllm import envs
@@ -9,7 +9,7 @@ from typing import Any
import torch import torch
from vllm.config import VllmConfig from vllm.config import VllmConfig
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
from .common import Config, RankTensors, WeightTensors, make_modular_kernel from .common import Config, RankTensors, WeightTensors, make_modular_kernel
from .parallel_utils import ProcessGroupInfo, parallel_launch_with_config from .parallel_utils import ProcessGroupInfo, parallel_launch_with_config
@@ -82,7 +82,7 @@ def rank_worker(
config: Config, config: Config,
weights: WeightTensors, weights: WeightTensors,
): ):
current_platform.seed_everything(pgi.rank) set_random_seed(pgi.rank)
# sanity check # sanity check
from vllm import envs from vllm import envs
+3 -2
View File
@@ -21,6 +21,7 @@ from vllm.model_executor.layers.fused_moe.fused_batched_moe import (
from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.triton_utils import tl from vllm.triton_utils import tl
from vllm.utils.torch_utils import set_random_seed
MNK_FACTORS = [ MNK_FACTORS = [
(1, 128, 128), (1, 128, 128),
@@ -115,7 +116,7 @@ def test_batched_mm(
): ):
"""Note: float8_e4m3fn is not supported on CUDA architecture < 89, """Note: float8_e4m3fn is not supported on CUDA architecture < 89,
and those tests will be skipped on unsupported hardware.""" and those tests will be skipped on unsupported hardware."""
current_platform.seed_everything(7) set_random_seed(7)
use_fp8_w8a8 = dtype == torch.float8_e4m3fn use_fp8_w8a8 = dtype == torch.float8_e4m3fn
@@ -252,7 +253,7 @@ def test_fused_moe_batched_experts(
): ):
"""Note: float8_e4m3fn is not supported on CUDA architecture < 89, """Note: float8_e4m3fn is not supported on CUDA architecture < 89,
and those tests will be skipped on unsupported hardware.""" and those tests will be skipped on unsupported hardware."""
current_platform.seed_everything(7) set_random_seed(7)
use_fp8_w8a8 = dtype == torch.float8_e4m3fn use_fp8_w8a8 = dtype == torch.float8_e4m3fn
+2 -1
View File
@@ -8,6 +8,7 @@ from tests.kernels.allclose_default import get_default_atol, get_default_rtol
from vllm._custom_ops import cpu_fused_moe, cpu_prepack_moe_weight from vllm._custom_ops import cpu_fused_moe, cpu_prepack_moe_weight
from vllm.model_executor.layers.activation import SiluAndMul, SwigluOAIAndMul from vllm.model_executor.layers.activation import SiluAndMul, SwigluOAIAndMul
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not current_platform.is_cpu(): if not current_platform.is_cpu():
pytest.skip("skipping CPU-only tests", allow_module_level=True) pytest.skip("skipping CPU-only tests", allow_module_level=True)
@@ -114,7 +115,7 @@ def test_cpu_fused_moe(
act: str, act: str,
isa: str, isa: str,
): ):
current_platform.seed_everything(0) set_random_seed(0)
topk_num = max(expert_num // 2, 1) topk_num = max(expert_num // 2, 1)
up_dim = 2 * intermediate_size up_dim = 2 * intermediate_size
+4 -3
View File
@@ -20,6 +20,7 @@ from vllm.model_executor.layers.fused_moe.cutlass_moe import (
from vllm.model_executor.layers.fused_moe.fused_moe import fused_experts, fused_topk from vllm.model_executor.layers.fused_moe.fused_moe import fused_experts, fused_topk
from vllm.model_executor.layers.fused_moe.utils import moe_kernel_quantize_input from vllm.model_executor.layers.fused_moe.utils import moe_kernel_quantize_input
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
NUM_EXPERTS = [40, 64] NUM_EXPERTS = [40, 64]
TOP_KS = [6, 8] TOP_KS = [6, 8]
@@ -277,7 +278,7 @@ def test_cutlass_moe_8_bit_no_graph(
workspace_init, workspace_init,
ep_size: int | None = None, ep_size: int | None = None,
): ):
current_platform.seed_everything(7) set_random_seed(7)
monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192") monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192")
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
mt = MOETensors8Bit.make_moe_tensors_8bit(m, k, n, e, per_act_token, per_out_ch) mt = MOETensors8Bit.make_moe_tensors_8bit(m, k, n, e, per_act_token, per_out_ch)
@@ -332,7 +333,7 @@ def test_cutlass_moe_8_bit_cuda_graph(
monkeypatch, monkeypatch,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192") monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192")
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
dtype = torch.half dtype = torch.half
@@ -469,7 +470,7 @@ def test_run_cutlass_moe_fp8(
ep_size: int, ep_size: int,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
mt = MOETensors8Bit.make_moe_tensors_8bit( mt = MOETensors8Bit.make_moe_tensors_8bit(
m, k, n, e, per_act_token, per_out_channel m, k, n, e, per_act_token, per_out_channel
@@ -22,13 +22,13 @@ from vllm.model_executor.layers.fused_moe.config import (
) )
from vllm.model_executor.layers.fused_moe.fused_moe import fused_experts from vllm.model_executor.layers.fused_moe.fused_moe import fused_experts
from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel
from vllm.platforms import current_platform
from vllm.utils.deep_gemm import ( from vllm.utils.deep_gemm import (
get_mk_alignment_for_contiguous_layout, get_mk_alignment_for_contiguous_layout,
is_deep_gemm_e8m0_used, is_deep_gemm_e8m0_used,
is_deep_gemm_supported, is_deep_gemm_supported,
) )
from vllm.utils.import_utils import has_deep_ep, has_deep_gemm from vllm.utils.import_utils import has_deep_ep, has_deep_gemm
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.workspace import init_workspace_manager from vllm.v1.worker.workspace import init_workspace_manager
from ...utils import multi_gpu_test from ...utils import multi_gpu_test
@@ -367,7 +367,7 @@ def _test_deepep_deepgemm_moe(
device = torch.device(f"cuda:{pgi.local_rank}") device = torch.device(f"cuda:{pgi.local_rank}")
init_workspace_manager(device) init_workspace_manager(device)
current_platform.seed_everything(pgi.rank) set_random_seed(pgi.rank)
w1 = w1.to(device=torch.cuda.current_device()) w1 = w1.to(device=torch.cuda.current_device())
w2 = w2.to(device=torch.cuda.current_device()) w2 = w2.to(device=torch.cuda.current_device())
@@ -456,7 +456,7 @@ def test_ht_deepep_deepgemm_moe(
""" """
m, n, k = mnk m, n, k = mnk
current_platform.seed_everything(7) set_random_seed(7)
if topk > num_experts: if topk > num_experts:
pytest.skip(f"Skipping test: topk={topk} > E={num_experts}") pytest.skip(f"Skipping test: topk={topk} > E={num_experts}")
@@ -531,7 +531,7 @@ def test_ll_deepep_deepgemm_moe(
assert not is_deep_gemm_e8m0_used() assert not is_deep_gemm_e8m0_used()
m, n, k = mnk m, n, k = mnk
current_platform.seed_everything(7) set_random_seed(7)
if topk > num_experts: if topk > num_experts:
pytest.skip(f"Skipping test: topk={topk} > E={num_experts}") pytest.skip(f"Skipping test: topk={topk} > E={num_experts}")
+3 -3
View File
@@ -20,8 +20,8 @@ from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularK
from vllm.model_executor.layers.quantization.utils.fp8_utils import ( from vllm.model_executor.layers.quantization.utils.fp8_utils import (
per_token_group_quant_fp8, per_token_group_quant_fp8,
) )
from vllm.platforms import current_platform
from vllm.utils.import_utils import has_deep_ep from vllm.utils.import_utils import has_deep_ep
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.workspace import init_workspace_manager from vllm.v1.worker.workspace import init_workspace_manager
from ...utils import multi_gpu_test from ...utils import multi_gpu_test
@@ -446,7 +446,7 @@ def test_deep_ep_moe(
low_latency_mode = False low_latency_mode = False
use_fp8_dispatch = False use_fp8_dispatch = False
current_platform.seed_everything(7) set_random_seed(7)
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
config = TestConfig(dtype=dtype, topk=topk, m=m, k=k, n=n, num_experts=num_experts) config = TestConfig(dtype=dtype, topk=topk, m=m, k=k, n=n, num_experts=num_experts)
@@ -507,7 +507,7 @@ def test_low_latency_deep_ep_moe(
f"hidden sizes {DeepEPLLPrepareAndFinalize.SUPPORTED_HIDDEN_SIZES}" f"hidden sizes {DeepEPLLPrepareAndFinalize.SUPPORTED_HIDDEN_SIZES}"
) )
current_platform.seed_everything(7) set_random_seed(7)
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
config = TestConfig(dtype=dtype, topk=topk, m=m, k=k, n=n, num_experts=num_experts) config = TestConfig(dtype=dtype, topk=topk, m=m, k=k, n=n, num_experts=num_experts)
+3 -2
View File
@@ -22,6 +22,7 @@ from vllm.model_executor.layers.quantization.utils.flashinfer_utils import (
from vllm.model_executor.layers.quantization.utils.fp8_utils import input_to_float8 from vllm.model_executor.layers.quantization.utils.fp8_utils import input_to_float8
from vllm.model_executor.models.llama4 import Llama4MoE from vllm.model_executor.models.llama4 import Llama4MoE
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
try: try:
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
@@ -158,7 +159,7 @@ def test_flashinfer_per_tensor_moe_fp8_no_graph(
): ):
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip("Test is only supported for sm >= 100") pytest.skip("Test is only supported for sm >= 100")
current_platform.seed_everything(7) set_random_seed(7)
monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192") monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192")
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
td = TestData.make_moe_tensors_8bit(m, k, n, e, reorder=True) td = TestData.make_moe_tensors_8bit(m, k, n, e, reorder=True)
@@ -222,7 +223,7 @@ def test_flashinfer_cutlass_moe_fp8_no_graph(
monkeypatch, monkeypatch,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192") monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", "8192")
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
td = TestData.make_moe_tensors_8bit( td = TestData.make_moe_tensors_8bit(
+2 -1
View File
@@ -23,6 +23,7 @@ from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk
from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
from vllm.utils.torch_utils import set_random_seed
if not has_flashinfer_cutlass_fused_moe() or not current_platform.has_device_capability( if not has_flashinfer_cutlass_fused_moe() or not current_platform.has_device_capability(
100 100
@@ -60,7 +61,7 @@ def test_flashinfer_fp4_moe_no_graph(
activation: str, activation: str,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
with set_current_vllm_config( with set_current_vllm_config(
VllmConfig(parallel_config=ParallelConfig(pipeline_parallel_size=1)) VllmConfig(parallel_config=ParallelConfig(pipeline_parallel_size=1))
): ):
+2 -1
View File
@@ -19,6 +19,7 @@ from vllm.model_executor.layers.fused_moe.fused_moe import (
fused_grouped_topk, fused_grouped_topk,
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
@pytest.mark.skipif( @pytest.mark.skipif(
@@ -52,7 +53,7 @@ def test_grouped_topk(
) )
get_cached_compilation_config.cache_clear() get_cached_compilation_config.cache_clear()
current_platform.seed_everything(0) set_random_seed(0)
hidden_states = torch.randn((n_token, n_hidden), dtype=dtype, device="cuda") hidden_states = torch.randn((n_token, n_hidden), dtype=dtype, device="cuda")
gating_output = torch.randn((n_token, n_expert), dtype=dtype, device="cuda") gating_output = torch.randn((n_token, n_expert), dtype=dtype, device="cuda")
e_score_correction_bias = torch.randn( e_score_correction_bias = torch.randn(
@@ -15,7 +15,7 @@ from vllm.config import VllmConfig, set_current_vllm_config
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
from vllm.utils.import_utils import has_deep_ep, has_deep_gemm, has_pplx from vllm.utils.import_utils import has_deep_ep, has_deep_gemm, has_pplx
from vllm.utils.torch_utils import cuda_device_count_stateless from vllm.utils.torch_utils import cuda_device_count_stateless, set_random_seed
from vllm.v1.worker.workspace import init_workspace_manager from vllm.v1.worker.workspace import init_workspace_manager
from .modular_kernel_tools.common import ( from .modular_kernel_tools.common import (
@@ -82,7 +82,7 @@ def rank_worker(
device = torch.device(f"cuda:{pgi.local_rank}") device = torch.device(f"cuda:{pgi.local_rank}")
init_workspace_manager(device) init_workspace_manager(device)
current_platform.seed_everything(pgi.rank) set_random_seed(pgi.rank)
# sanity check # sanity check
from vllm import envs from vllm import envs
@@ -34,6 +34,7 @@ from vllm.model_executor.layers.fused_moe.prepare_finalize import (
) )
from vllm.model_executor.layers.utils import shuffle_weight from vllm.model_executor.layers.utils import shuffle_weight
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
MNK = [ MNK = [
(1, 512, 384), (1, 512, 384),
@@ -211,7 +212,7 @@ def test_oai_triton_moe(
unfused: bool, unfused: bool,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(0) set_random_seed(0)
( (
w1, w1,
w2, w2,
+2 -1
View File
@@ -60,6 +60,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import quantize_w
from vllm.model_executor.models.mixtral import MixtralMoE from vllm.model_executor.models.mixtral import MixtralMoE
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.scalar_type import ScalarType, scalar_types from vllm.scalar_type import ScalarType, scalar_types
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.workspace import init_workspace_manager from vllm.v1.worker.workspace import init_workspace_manager
NUM_EXPERTS = [8, 64, 192] NUM_EXPERTS = [8, 64, 192]
@@ -234,7 +235,7 @@ def test_fused_moe(
monkeypatch, monkeypatch,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", str(chunk_size)) monkeypatch.setenv("VLLM_FUSED_MOE_CHUNK_SIZE", str(chunk_size))
@@ -14,12 +14,13 @@ from vllm.model_executor.layers.fused_moe.moe_align_block_size import (
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.math_utils import round_up from vllm.utils.math_utils import round_up
from vllm.utils.torch_utils import set_random_seed
NUM_TOKENS = [1, 3, 256, 2256, 4096] NUM_TOKENS = [1, 3, 256, 2256, 4096]
NUM_EXPERTS = [32, 160, 256, 257] NUM_EXPERTS = [32, 160, 256, 257]
TOP_KS = [1, 2, 16, 32] TOP_KS = [1, 2, 16, 32]
BLOCK_SIZES = [32, 128] BLOCK_SIZES = [32, 128]
current_platform.seed_everything(0) set_random_seed(0)
def _group_tokens_by_expert( def _group_tokens_by_expert(
@@ -17,11 +17,12 @@ from vllm.model_executor.layers.fused_moe.moe_permute_unpermute import (
moe_unpermute, moe_unpermute,
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
NUM_EXPERTS = [16, 64, 256] NUM_EXPERTS = [16, 64, 256]
TOP_KS = [2, 6, 8] TOP_KS = [2, 6, 8]
EP_SIZE = [1, 4, 16] EP_SIZE = [1, 4, 16]
current_platform.seed_everything(0) set_random_seed(0)
if current_platform.is_rocm(): if current_platform.is_rocm():
pytest.skip( pytest.skip(
@@ -226,7 +227,7 @@ def test_moe_permute_unpermute(
n_local_expert, expert_map, _ = determine_expert_map(ep_size, ep_rank, n_expert) n_local_expert, expert_map, _ = determine_expert_map(ep_size, ep_rank, n_expert)
expert_map = expert_map.cuda() expert_map = expert_map.cuda()
start_expert = n_local_expert * ep_rank start_expert = n_local_expert * ep_rank
current_platform.seed_everything(0) set_random_seed(0)
hidden_states = torch.randn((n_token, n_hidden), device="cuda").to(dtype) hidden_states = torch.randn((n_token, n_hidden), device="cuda").to(dtype)
gating_output = torch.randn((n_token, n_expert), device="cuda").to(dtype) gating_output = torch.randn((n_token, n_expert), device="cuda").to(dtype)
topk_weights, topk_ids, token_expert_indices = fused_topk( topk_weights, topk_ids, token_expert_indices = fused_topk(
+2 -1
View File
@@ -16,6 +16,7 @@ from vllm.model_executor.layers.fused_moe.config import nvfp4_moe_quant_config
from vllm.model_executor.layers.fused_moe.cutlass_moe import cutlass_moe_fp4 from vllm.model_executor.layers.fused_moe.cutlass_moe import cutlass_moe_fp4
from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -42,7 +43,7 @@ MNK_FACTORS = [
def test_cutlass_fp4_moe_no_graph( def test_cutlass_fp4_moe_no_graph(
m: int, n: int, k: int, e: int, topk: int, dtype: torch.dtype, workspace_init m: int, n: int, k: int, e: int, topk: int, dtype: torch.dtype, workspace_init
): ):
current_platform.seed_everything(7) set_random_seed(7)
with set_current_vllm_config( with set_current_vllm_config(
VllmConfig(parallel_config=ParallelConfig(pipeline_parallel_size=1)) VllmConfig(parallel_config=ParallelConfig(pipeline_parallel_size=1))
): ):
+2 -1
View File
@@ -14,6 +14,7 @@ from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk
from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.math_utils import cdiv from vllm.utils.math_utils import cdiv
from vllm.utils.torch_utils import set_random_seed
from ...utils import multi_gpu_test from ...utils import multi_gpu_test
from .parallel_utils import ProcessGroupInfo, parallel_launch from .parallel_utils import ProcessGroupInfo, parallel_launch
@@ -290,7 +291,7 @@ def test_cutlass_moe_pplx(
world_dp_size: tuple[int, int], world_dp_size: tuple[int, int],
use_internode: bool, use_internode: bool,
): ):
current_platform.seed_everything(7) set_random_seed(7)
with set_current_vllm_config(vllm_config): with set_current_vllm_config(vllm_config):
dtype = torch.half dtype = torch.half
+7 -7
View File
@@ -44,8 +44,8 @@ from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularK
from vllm.model_executor.layers.fused_moe.topk_weight_and_reduce import ( from vllm.model_executor.layers.fused_moe.topk_weight_and_reduce import (
TopKWeightAndReduceDelegate, TopKWeightAndReduceDelegate,
) )
from vllm.platforms import current_platform
from vllm.utils.math_utils import round_up from vllm.utils.math_utils import round_up
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.workspace import init_workspace_manager from vllm.v1.worker.workspace import init_workspace_manager
from ...utils import multi_gpu_test from ...utils import multi_gpu_test
@@ -184,7 +184,7 @@ def test_fused_moe_batched_experts(
dtype: torch.dtype, dtype: torch.dtype,
workspace_init, workspace_init,
): ):
current_platform.seed_everything(7) set_random_seed(7)
a = torch.randn((m, k), device="cuda", dtype=dtype) / 10 a = torch.randn((m, k), device="cuda", dtype=dtype) / 10
w1 = torch.randn((e, 2 * n, k), device="cuda", dtype=dtype) / 10 w1 = torch.randn((e, 2 * n, k), device="cuda", dtype=dtype) / 10
@@ -491,7 +491,7 @@ def test_pplx_prepare_finalize_slow(
if per_act_token_quant and block_shape is not None: if per_act_token_quant and block_shape is not None:
pytest.skip("Skip illegal quantization combination") pytest.skip("Skip illegal quantization combination")
current_platform.seed_everything(7) set_random_seed(7)
m, n, k = mnk m, n, k = mnk
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
device = "cuda" device = "cuda"
@@ -809,7 +809,7 @@ def test_pplx_moe_slow(
block_shape: list[int] | None, block_shape: list[int] | None,
use_internode: bool, use_internode: bool,
): ):
current_platform.seed_everything(7) set_random_seed(7)
m, n, k = mnk m, n, k = mnk
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
@@ -888,7 +888,7 @@ def _pplx_test_loop(
new_vllm_config.parallel_config.enable_expert_parallel = True new_vllm_config.parallel_config.enable_expert_parallel = True
_set_vllm_config(new_vllm_config, pgi.world_size, pgi.rank, pgi.local_rank) _set_vllm_config(new_vllm_config, pgi.world_size, pgi.rank, pgi.local_rank)
current_platform.seed_everything(7) set_random_seed(7)
combos = itertools.product( combos = itertools.product(
PPLX_COMBOS, NUM_EXPERTS, TOP_KS, DTYPES, [False, True], [None, [128, 128]] PPLX_COMBOS, NUM_EXPERTS, TOP_KS, DTYPES, [False, True], [None, [128, 128]]
) )
@@ -982,7 +982,7 @@ def test_pplx_prepare_finalize(
world_dp_size: tuple[int, int], world_dp_size: tuple[int, int],
use_internode: bool, use_internode: bool,
): ):
current_platform.seed_everything(7) set_random_seed(7)
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
parallel_launch( parallel_launch(
world_size * dp_size, world_size * dp_size,
@@ -1005,7 +1005,7 @@ def test_pplx_moe(
use_internode: bool, use_internode: bool,
use_shared_experts: bool, use_shared_experts: bool,
): ):
current_platform.seed_everything(7) set_random_seed(7)
world_size, dp_size = world_dp_size world_size, dp_size = world_dp_size
parallel_launch( parallel_launch(
world_size, world_size,
@@ -13,6 +13,7 @@ from vllm.model_executor.layers.fused_moe.batched_deep_gemm_moe import (
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.deep_gemm import DeepGemmQuantScaleFMT, has_deep_gemm from vllm.utils.deep_gemm import DeepGemmQuantScaleFMT, has_deep_gemm
from vllm.utils.math_utils import cdiv, round_up from vllm.utils.math_utils import cdiv, round_up
from vllm.utils.torch_utils import set_random_seed
if current_platform.is_fp8_fnuz(): if current_platform.is_fp8_fnuz():
pytest.skip( pytest.skip(
@@ -201,7 +202,7 @@ def token_random(E, T, H2, tokens_per_expert):
@torch.inference_mode() @torch.inference_mode()
def test_silu_mul_fp8_quant_deep_gemm(E: int, T: int, H: int, fp8_type: torch.dtype): def test_silu_mul_fp8_quant_deep_gemm(E: int, T: int, H: int, fp8_type: torch.dtype):
group_size = 128 group_size = 128
current_platform.seed_everything(42) set_random_seed(42)
tokens_per_expert = torch.randint( tokens_per_expert = torch.randint(
low=0, low=0,
@@ -11,6 +11,7 @@ from vllm.model_executor.layers.quantization.utils.fp8_utils import (
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.triton_utils import triton from vllm.triton_utils import triton
from vllm.utils.deep_gemm import is_deep_gemm_e8m0_used from vllm.utils.deep_gemm import is_deep_gemm_e8m0_used
from vllm.utils.torch_utils import set_random_seed
FLOAT8_DTYPE = torch.float8_e4m3fn FLOAT8_DTYPE = torch.float8_e4m3fn
GROUP_SIZE = 128 GROUP_SIZE = 128
@@ -72,7 +73,7 @@ def reference(x: torch.Tensor, use_ue8m0: bool) -> tuple[torch.Tensor, torch.Ten
reason="ROCm does not support DeepGemm.", reason="ROCm does not support DeepGemm.",
) )
def test_silu_mul_fp8_quant_deep_gemm(T: int, N: int): def test_silu_mul_fp8_quant_deep_gemm(T: int, N: int):
current_platform.seed_everything(42) set_random_seed(42)
input = torch.rand((T, N), dtype=torch.bfloat16, device="cuda") input = torch.rand((T, N), dtype=torch.bfloat16, device="cuda")
@@ -13,7 +13,7 @@ from vllm.model_executor.layers.quantization.awq_triton import (
awq_dequantize_triton, awq_dequantize_triton,
awq_gemm_triton, awq_gemm_triton,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
device = "cuda" device = "cuda"
@@ -86,7 +86,7 @@ def test_dequantize(qweight_rows, qweight_cols, group_size):
zeros_cols = qweight_cols zeros_cols = qweight_cols
zeros_dtype = torch.int32 zeros_dtype = torch.int32
current_platform.seed_everything(0) set_random_seed(0)
qweight = torch.randint( qweight = torch.randint(
0, 0,
@@ -141,7 +141,7 @@ def test_gemm(N, K, M, splitK, group_size):
qzeros_rows = scales_rows qzeros_rows = scales_rows
qzeros_cols = qweight_cols qzeros_cols = qweight_cols
current_platform.seed_everything(0) set_random_seed(0)
input = torch.rand((input_rows, input_cols), dtype=input_dtype, device=device) input = torch.rand((input_rows, input_cols), dtype=input_dtype, device=device)
qweight = torch.randint( qweight = torch.randint(
@@ -17,6 +17,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import (
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.scalar_type import ScalarType, scalar_types from vllm.scalar_type import ScalarType, scalar_types
from vllm.utils.torch_utils import set_random_seed
IS_SUPPORTED_BY_GPU = ( IS_SUPPORTED_BY_GPU = (
current_platform.is_cuda() and current_platform.get_device_capability()[0] >= 9 current_platform.is_cuda() and current_platform.get_device_capability()[0] >= 9
@@ -248,7 +249,7 @@ def compute_moe_reference_output(setup: MoETestSetup) -> torch.Tensor:
@pytest.mark.parametrize("random_zero", [True, False]) @pytest.mark.parametrize("random_zero", [True, False])
def test_cutlass_w4a8_moe_mm_end_to_end(shape, random_zero): def test_cutlass_w4a8_moe_mm_end_to_end(shape, random_zero):
num_experts, N, K = shape num_experts, N, K = shape
current_platform.seed_everything(42) set_random_seed(42)
setup = make_moe_test_setup( setup = make_moe_test_setup(
num_experts=num_experts, K=K, N=N, max_blocks=64, random_zero=random_zero num_experts=num_experts, K=K, N=N, max_blocks=64, random_zero=random_zero
) )
@@ -308,7 +309,7 @@ class W4A8MoELayer(torch.nn.Module):
reason="W4A8 Grouped GEMM is not supported on this GPU type.", reason="W4A8 Grouped GEMM is not supported on this GPU type.",
) )
def test_cutlass_w4a8_moe_mm_cuda_graph(): def test_cutlass_w4a8_moe_mm_cuda_graph():
current_platform.seed_everything(42) set_random_seed(42)
# Fixed config for CUDA graph test (single parameter point). # Fixed config for CUDA graph test (single parameter point).
num_experts = 8 num_experts = 8
K = 512 K = 512
@@ -12,6 +12,7 @@ from nvfp4_utils import (
from vllm import _custom_ops as ops from vllm import _custom_ops as ops
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.flashinfer import flashinfer_scaled_fp4_mm from vllm.utils.flashinfer import flashinfer_scaled_fp4_mm
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -72,7 +73,7 @@ def test_flashinfer_nvfp4_gemm(
if backend == "trtllm" and dtype == torch.float16: if backend == "trtllm" and dtype == torch.float16:
pytest.skip("Only torch.bfloat16 is supported for TRTLLM FP4 GEMM operations") pytest.skip("Only torch.bfloat16 is supported for TRTLLM FP4 GEMM operations")
current_platform.seed_everything(seed) set_random_seed(seed)
m, n, packed_k = shape m, n, packed_k = shape
k = packed_k * 2 k = packed_k * 2
block_size = 16 block_size = 16
@@ -6,6 +6,7 @@ import torch
from vllm import _custom_ops as ops from vllm import _custom_ops as ops
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.flashinfer import flashinfer_scaled_fp8_mm from vllm.utils.flashinfer import flashinfer_scaled_fp8_mm
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -38,7 +39,7 @@ def test_flashinfer_fp8_gemm(
device: str, device: str,
autotune: bool, autotune: bool,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
m, n, k = shape m, n, k = shape
a = torch.randn((m, k), dtype=dtype, device=device) a = torch.randn((m, k), dtype=dtype, device=device)
b = torch.randn((n, k), dtype=dtype, device=device) / k b = torch.randn((n, k), dtype=dtype, device=device) / k
+4 -4
View File
@@ -11,7 +11,7 @@ from tests.kernels.quant_utils import (
ref_dynamic_per_token_quant, ref_dynamic_per_token_quant,
) )
from tests.kernels.utils import opcheck from tests.kernels.utils import opcheck
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
DTYPES = [torch.bfloat16, torch.float] DTYPES = [torch.bfloat16, torch.float]
HIDDEN_SIZES = [17, 1024, 1025, 1026, 5137, 8193] HIDDEN_SIZES = [17, 1024, 1025, 1026, 5137, 8193]
@@ -51,7 +51,7 @@ def opcheck_fp8_quant(
def test_dynamic_per_token_fp8_quant( def test_dynamic_per_token_fp8_quant(
num_tokens: int, hidden_size: int, dtype: torch.dtype, scale_ub: bool, seed: int num_tokens: int, hidden_size: int, dtype: torch.dtype, scale_ub: bool, seed: int
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
x = ( x = (
torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") + 1e-6 torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") + 1e-6
@@ -81,7 +81,7 @@ def test_dynamic_per_token_fp8_quant(
def test_dynamic_per_tensor_fp8_quant( def test_dynamic_per_tensor_fp8_quant(
num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda")
@@ -101,7 +101,7 @@ def test_dynamic_per_tensor_fp8_quant(
@torch.inference_mode() @torch.inference_mode()
@pytest.mark.parametrize("seed", SEEDS) @pytest.mark.parametrize("seed", SEEDS)
def test_fp8_quant_large(seed: int) -> None: def test_fp8_quant_large(seed: int) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
num_tokens = 1024000 # Mistral-Nemo's max_position_embeddings num_tokens = 1024000 # Mistral-Nemo's max_position_embeddings
hidden_size = 1152 # Smallest hidden_size to reproduce the error hidden_size = 1152 # Smallest hidden_size to reproduce the error
@@ -7,7 +7,7 @@ import torch
from vllm.model_executor.layers.quantization.input_quant_fp8 import QuantFP8 from vllm.model_executor.layers.quantization.input_quant_fp8 import QuantFP8
from vllm.model_executor.layers.quantization.utils.quant_utils import GroupShape from vllm.model_executor.layers.quantization.utils.quant_utils import GroupShape
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -30,7 +30,7 @@ def test_quantfp8_group_functionality(
Tests both CUDA and native implementations, column-major scales, Tests both CUDA and native implementations, column-major scales,
and verifies consistency between implementations. and verifies consistency between implementations.
""" """
current_platform.seed_everything(seed) set_random_seed(seed)
x = torch.randn((batch_size, hidden_dim), dtype=torch.bfloat16, device="cuda") * 8 x = torch.randn((batch_size, hidden_dim), dtype=torch.bfloat16, device="cuda") * 8
expected_num_groups = (hidden_dim + group_size - 1) // group_size expected_num_groups = (hidden_dim + group_size - 1) // group_size
@@ -83,7 +83,7 @@ def test_quantfp8_group_functionality(
@pytest.mark.parametrize("use_ue8m0", [True, False]) @pytest.mark.parametrize("use_ue8m0", [True, False])
@torch.inference_mode() @torch.inference_mode()
def test_quantfp8_group_multidimensional(seed: int, use_ue8m0: bool) -> None: def test_quantfp8_group_multidimensional(seed: int, use_ue8m0: bool) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
group_size = 64 group_size = 64
@@ -136,7 +136,7 @@ def test_quantfp8_group_multidimensional(seed: int, use_ue8m0: bool) -> None:
@pytest.mark.parametrize("seed", [42]) @pytest.mark.parametrize("seed", [42])
@torch.inference_mode() @torch.inference_mode()
def test_quantfp8_group_edge_cases(seed: int) -> None: def test_quantfp8_group_edge_cases(seed: int) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
batch_size = 16 batch_size = 16
group_size = 64 group_size = 64
+4 -4
View File
@@ -11,7 +11,7 @@ from huggingface_hub import snapshot_download
import vllm._custom_ops as ops import vllm._custom_ops as ops
from vllm.model_executor.layers.fused_moe import fused_experts from vllm.model_executor.layers.fused_moe import fused_experts
from vllm.model_executor.layers.quantization.gguf import _fused_moe_gguf from vllm.model_executor.layers.quantization.gguf import _fused_moe_gguf
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
GGUF_SAMPLE = snapshot_download("Isotr0py/test-gguf-sample") GGUF_SAMPLE = snapshot_download("Isotr0py/test-gguf-sample")
GGUF_SAMPLE_MOE = snapshot_download("SzymonOzog/test-gguf-moe-sample") GGUF_SAMPLE_MOE = snapshot_download("SzymonOzog/test-gguf-moe-sample")
@@ -91,7 +91,7 @@ def test_dequantize(
@pytest.mark.parametrize("quant_type", QUANT_TYPES) @pytest.mark.parametrize("quant_type", QUANT_TYPES)
@torch.inference_mode() @torch.inference_mode()
def test_mmvq(hidden_size: int, dtype: torch.dtype, quant_type: GGMLQuantizationType): def test_mmvq(hidden_size: int, dtype: torch.dtype, quant_type: GGMLQuantizationType):
current_platform.seed_everything(0) set_random_seed(0)
tensors = get_gguf_sample_tensors(hidden_size, quant_type) tensors = get_gguf_sample_tensors(hidden_size, quant_type)
x = torch.rand((1, hidden_size), dtype=dtype, device="cuda") x = torch.rand((1, hidden_size), dtype=dtype, device="cuda")
@@ -134,7 +134,7 @@ def test_mmq(
dtype: torch.dtype, dtype: torch.dtype,
quant_type: GGMLQuantizationType, quant_type: GGMLQuantizationType,
): ):
current_platform.seed_everything(0) set_random_seed(0)
tensors = get_gguf_sample_tensors(hidden_size, quant_type) tensors = get_gguf_sample_tensors(hidden_size, quant_type)
x = torch.rand((num_tokens, hidden_size), dtype=dtype, device="cuda") x = torch.rand((num_tokens, hidden_size), dtype=dtype, device="cuda")
@@ -169,7 +169,7 @@ def test_moe(
quant_type: GGMLQuantizationType, quant_type: GGMLQuantizationType,
top_k: int, top_k: int,
): ):
current_platform.seed_everything(0) set_random_seed(0)
H, E = 1024, 256 H, E = 1024, 256
x = torch.rand((num_tokens, H), dtype=dtype, device="cuda") x = torch.rand((num_tokens, H), dtype=dtype, device="cuda")
@@ -7,7 +7,7 @@ import torch
from tests.kernels.quant_utils import ref_dynamic_per_token_quant from tests.kernels.quant_utils import ref_dynamic_per_token_quant
from tests.kernels.utils import opcheck from tests.kernels.utils import opcheck
from vllm._custom_ops import scaled_int8_quant from vllm._custom_ops import scaled_int8_quant
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
DTYPES = [torch.bfloat16, torch.float] DTYPES = [torch.bfloat16, torch.float]
HIDDEN_SIZES = [17, 1024, 1025, 1026, 5137, 8193] HIDDEN_SIZES = [17, 1024, 1025, 1026, 5137, 8193]
@@ -46,7 +46,7 @@ def opcheck_int8_quant_dynamic(output, input, symmetric=True):
def test_dynamic_scaled_int8_quant( def test_dynamic_scaled_int8_quant(
num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000
@@ -70,7 +70,7 @@ def test_dynamic_scaled_int8_quant(
def test_dynamic_scaled_int8_azp_quant( def test_dynamic_scaled_int8_azp_quant(
num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
int8_traits = torch.iinfo(torch.int8) int8_traits = torch.iinfo(torch.int8)
x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 - 300 x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 - 300
@@ -111,7 +111,7 @@ def test_dynamic_scaled_int8_azp_quant(
def test_static_scaled_int8_quant( def test_static_scaled_int8_quant(
num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int, scale: float num_tokens: int, hidden_size: int, dtype: torch.dtype, seed: int, scale: float
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
int8_traits = torch.iinfo(torch.int8) int8_traits = torch.iinfo(torch.int8)
x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000
@@ -144,7 +144,7 @@ def test_static_scaled_int8_azp_quant(
scale: float, scale: float,
azp: int, azp: int,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
int8_traits = torch.iinfo(torch.int8) int8_traits = torch.iinfo(torch.int8)
x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 - 300 x = torch.rand(num_tokens, hidden_size, dtype=dtype, device="cuda") * 1000 - 300
@@ -24,6 +24,7 @@ from compressed_tensors.transform.utils.hadamard import deterministic_hadamard_m
from vllm._custom_ops import fusedQuantizeMx, matmul_mxf4_bf16_tn from vllm._custom_ops import fusedQuantizeMx, matmul_mxf4_bf16_tn
from vllm.model_executor.layers.quantization.qutlass_utils import to_blocked from vllm.model_executor.layers.quantization.qutlass_utils import to_blocked
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip("CUDA required for these tests.", allow_module_level=True) pytest.skip("CUDA required for these tests.", allow_module_level=True)
@@ -205,7 +206,7 @@ LLAMA_MODELS = {
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def _seed_each_test(): def _seed_each_test():
current_platform.seed_everything(0) set_random_seed(0)
np.random.seed(0) np.random.seed(0)
torch.random.manual_seed(0) torch.random.manual_seed(0)
@@ -6,6 +6,7 @@ import torch
from vllm import _custom_ops as ops from vllm import _custom_ops as ops
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.scalar_type import scalar_types from vllm.scalar_type import scalar_types
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -134,7 +135,7 @@ def test_quantize_to_fp4(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device(device) torch.set_default_device(device)
m, n = shape m, n = shape
@@ -156,7 +157,7 @@ def test_quantize_to_fp4(
@torch.inference_mode() @torch.inference_mode()
def test_quantize_to_fp4_padded(pad_shape: tuple[int, int]) -> None: def test_quantize_to_fp4_padded(pad_shape: tuple[int, int]) -> None:
dtype = torch.float16 dtype = torch.float16
current_platform.seed_everything(42) set_random_seed(42)
torch.set_default_device("cuda:0") torch.set_default_device("cuda:0")
m, n = pad_shape m, n = pad_shape
@@ -25,6 +25,7 @@ from vllm import _custom_ops as ops # use existing nvfp4 gemm in vllm
from vllm._custom_ops import fusedQuantizeNv from vllm._custom_ops import fusedQuantizeNv
from vllm.model_executor.layers.quantization.qutlass_utils import to_blocked from vllm.model_executor.layers.quantization.qutlass_utils import to_blocked
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip("CUDA required for these tests.", allow_module_level=True) pytest.skip("CUDA required for these tests.", allow_module_level=True)
@@ -193,7 +194,7 @@ LLAMA_MODELS = {
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def _seed_each_test(): def _seed_each_test():
current_platform.seed_everything(0) set_random_seed(0)
np.random.seed(0) np.random.seed(0)
torch.random.manual_seed(0) torch.random.manual_seed(0)
@@ -6,6 +6,7 @@ from nvfp4_utils import FLOAT4_E2M1_MAX, FLOAT8_E4M3_MAX, dequantize_nvfp4_to_dt
from vllm import _custom_ops as ops from vllm import _custom_ops as ops
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -59,7 +60,7 @@ def test_nvfp4_gemm(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
m, n, packed_k = shape m, n, packed_k = shape
k = packed_k * 2 k = packed_k * 2
block_size = 16 block_size = 16
@@ -11,6 +11,7 @@ from tests.kernels.quantization.nvfp4_utils import (
from vllm._custom_ops import scaled_fp4_quant from vllm._custom_ops import scaled_fp4_quant
from vllm.model_executor.layers.activation import SiluAndMul from vllm.model_executor.layers.activation import SiluAndMul
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
if not current_platform.has_device_capability(100): if not current_platform.has_device_capability(100):
pytest.skip( pytest.skip(
@@ -33,7 +34,7 @@ def test_silu_mul_nvfp4_quant(
dtype: torch.dtype, dtype: torch.dtype,
shape: tuple[int, int], shape: tuple[int, int],
) -> None: ) -> None:
current_platform.seed_everything(42) set_random_seed(42)
device = "cuda:0" device = "cuda:0"
torch.set_default_device(device) torch.set_default_device(device)
@@ -11,6 +11,7 @@ import pytest
import torch import torch
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
device = "cuda" device = "cuda"
@@ -85,7 +86,7 @@ def test_scaled_mm(
): ):
is_floating_point_type = lambda t: torch.tensor([1, 1], dtype=t).is_floating_point() is_floating_point_type = lambda t: torch.tensor([1, 1], dtype=t).is_floating_point()
current_platform.seed_everything(0) set_random_seed(0)
# NOTE: There are cases, where if the matrix is large enough, an output # NOTE: There are cases, where if the matrix is large enough, an output
# like 65504.4 can be produced, and can easily turn into inf when # like 65504.4 can be produced, and can easily turn into inf when
@@ -9,6 +9,7 @@ from vllm._custom_ops import (
apply_repetition_penalties_torch, apply_repetition_penalties_torch,
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
NUM_SEQS = [1, 2, 3, 4, 8, 13, 17, 32, 37, 256, 1023, 1024, 1025] NUM_SEQS = [1, 2, 3, 4, 8, 13, 17, 32, 37, 256, 1023, 1024, 1025]
# [stress, stress, stress, Qwen, llama 4] # [stress, stress, stress, Qwen, llama 4]
@@ -38,7 +39,7 @@ def test_apply_repetition_penalties(
Test the apply_repetition_penalties custom op Test the apply_repetition_penalties custom op
against a reference implementation. against a reference implementation.
""" """
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device("cuda:0") torch.set_default_device("cuda:0")
# Create test data # Create test data
@@ -95,7 +96,7 @@ def test_apply_repetition_penalties_zero_seqs() -> None:
dtype = torch.float32 dtype = torch.float32
seed = 0 seed = 0
current_platform.seed_everything(seed) set_random_seed(seed)
torch.set_default_device("cuda:0") torch.set_default_device("cuda:0")
# Create test data # Create test data
+8 -8
View File
@@ -10,7 +10,7 @@ from vllm.model_executor.layers.fla.ops.layernorm_guard import (
layernorm_fn, layernorm_fn,
rms_norm_ref, rms_norm_ref,
) )
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
def layer_norm_ref( def layer_norm_ref(
@@ -114,7 +114,7 @@ def test_layer_norm_fwd_basic(
is_rms_norm: bool, is_rms_norm: bool,
) -> None: ) -> None:
"""Test basic layer norm forward pass without z (gate) tensor.""" """Test basic layer norm forward pass without z (gate) tensor."""
current_platform.seed_everything(seed) set_random_seed(seed)
device = torch.device("cuda:0") device = torch.device("cuda:0")
# Create inputs # Create inputs
@@ -156,7 +156,7 @@ def test_layer_norm_fwd_with_gate(
is_rms_norm: bool, is_rms_norm: bool,
) -> None: ) -> None:
"""Test layer norm forward pass with z (gate) tensor.""" """Test layer norm forward pass with z (gate) tensor."""
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
# Create inputs # Create inputs
@@ -213,7 +213,7 @@ def test_layer_norm_fwd_with_groups(
f"hidden_size {hidden_size} not divisible by group_size {group_size}" f"hidden_size {hidden_size} not divisible by group_size {group_size}"
) )
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
# Create inputs # Create inputs
@@ -253,7 +253,7 @@ def test_layer_norm_rows_per_block(
dtype: torch.dtype, dtype: torch.dtype,
) -> None: ) -> None:
"""Test that rows_per_block logic works correctly for various M sizes.""" """Test that rows_per_block logic works correctly for various M sizes."""
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
hidden_size = 1024 hidden_size = 1024
@@ -278,7 +278,7 @@ def test_layer_norm_rows_per_block(
def test_strided_input(dtype: torch.dtype) -> None: def test_strided_input(dtype: torch.dtype) -> None:
"""Test that the kernel handles non-contiguous (strided) """Test that the kernel handles non-contiguous (strided)
inputs correctly.""" inputs correctly."""
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
num_tokens = 128 num_tokens = 128
hidden_size = 1024 hidden_size = 1024
@@ -318,7 +318,7 @@ def test_output_buffer_provided(
dtype: torch.dtype, dtype: torch.dtype,
) -> None: ) -> None:
"""Test that the kernel works when an output buffer is provided.""" """Test that the kernel works when an output buffer is provided."""
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
# Create inputs # Create inputs
@@ -359,7 +359,7 @@ def test_multidimensional_input(
dtype: torch.dtype, dtype: torch.dtype,
) -> None: ) -> None:
"""Test that the autograd function handles multidimensional inputs.""" """Test that the autograd function handles multidimensional inputs."""
current_platform.seed_everything(42) set_random_seed(42)
device = torch.device("cuda:0") device = torch.device("cuda:0")
hidden_size = shape[-1] hidden_size = shape[-1]
+4 -4
View File
@@ -18,8 +18,8 @@ from vllm.distributed.parallel_state import (
get_tensor_model_parallel_world_size, get_tensor_model_parallel_world_size,
) )
from vllm.lora.ops.triton_ops import fused_moe_lora from vllm.lora.ops.triton_ops import fused_moe_lora
from vllm.platforms import current_platform
from vllm.utils.network_utils import get_open_port from vllm.utils.network_utils import get_open_port
from vllm.utils.torch_utils import set_random_seed
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@@ -265,7 +265,7 @@ def test_fused_moe_lora_kernel(
seed, seed,
): ):
torch.set_default_device(device) torch.set_default_device(device)
current_platform.seed_everything(seed) set_random_seed(seed)
# the number of randomly generated sentences. # the number of randomly generated sentences.
num_sequences = 10 num_sequences = 10
# generate data # generate data
@@ -358,7 +358,7 @@ def test_fused_moe_lora_kernel_fully_sharded(
seed, seed,
column_parallel, column_parallel,
): ):
current_platform.seed_everything(seed) set_random_seed(seed)
# the number of randomly generated sentences. # the number of randomly generated sentences.
num_sequences = 10 num_sequences = 10
# generate data # generate data
@@ -415,7 +415,7 @@ def use_fused_moe_lora_kernel_tensor_parallel(
def _get_shard_slice(shard_size): def _get_shard_slice(shard_size):
return slice(local_rank * shard_size, (local_rank + 1) * shard_size) return slice(local_rank * shard_size, (local_rank + 1) * shard_size)
current_platform.seed_everything(seed) set_random_seed(seed)
device = torch.device(f"cuda:{local_rank}") device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(device) torch.cuda.set_device(device)
+1 -1
View File
@@ -43,8 +43,8 @@ from vllm.model_executor.layers.vocab_parallel_embedding import (
VocabParallelEmbedding, VocabParallelEmbedding,
get_masked_input_and_mask, get_masked_input_and_mask,
) )
from vllm.model_executor.utils import set_random_seed
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
from .utils import DummyLoRAManager from .utils import DummyLoRAManager
+3 -3
View File
@@ -9,7 +9,7 @@ import vllm.lora.ops.torch_ops as torch_ops
import vllm.lora.ops.triton_ops as triton_ops import vllm.lora.ops.triton_ops as triton_ops
from vllm.lora.ops.triton_ops import LoRAKernelMeta from vllm.lora.ops.triton_ops import LoRAKernelMeta
from vllm.lora.ops.triton_ops.utils import _LORA_A_PTR_DICT, _LORA_B_PTR_DICT from vllm.lora.ops.triton_ops.utils import _LORA_A_PTR_DICT, _LORA_B_PTR_DICT
from vllm.platforms import current_platform from vllm.utils.torch_utils import set_random_seed
from .utils import PunicaTensors, assert_close, generate_data_for_nslices from .utils import PunicaTensors, assert_close, generate_data_for_nslices
@@ -395,7 +395,7 @@ def test_kernels(
Tests LoRA kernels. Tests LoRA kernels.
""" """
torch.set_default_device(device) torch.set_default_device(device)
current_platform.seed_everything(seed) set_random_seed(seed)
if op_type == "shrink": if op_type == "shrink":
check_lora_shrink_kernel( check_lora_shrink_kernel(
@@ -447,7 +447,7 @@ def test_kernels_hidden_size(
Tests SGMV and LoRA kernels. Tests SGMV and LoRA kernels.
""" """
torch.set_default_device(device) torch.set_default_device(device)
current_platform.seed_everything(seed) set_random_seed(seed)
if op_type == "shrink": if op_type == "shrink":
check_lora_shrink_kernel( check_lora_shrink_kernel(
+4 -3
View File
@@ -21,6 +21,7 @@ from vllm.model_executor.models.vision import (
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.network_utils import get_open_port from vllm.utils.network_utils import get_open_port
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
pytestmark = pytest.mark.cpu_test pytestmark = pytest.mark.cpu_test
@@ -98,7 +99,7 @@ def run_dp_sharded_vision_model_vs_direct(
""" """
# Set random seed for reproducibility # Set random seed for reproducibility
current_platform.seed_everything(0) set_random_seed(0)
device = f"{current_platform.device_name}:{local_rank}" device = f"{current_platform.device_name}:{local_rank}"
current_platform.set_device(device) current_platform.set_device(device)
@@ -284,7 +285,7 @@ def run_dp_sharded_mrope_vision_model_vs_direct(
calling the model directly. calling the model directly.
""" """
# Set random seed for reproducibility # Set random seed for reproducibility
current_platform.seed_everything(0) set_random_seed(0)
device = f"{current_platform.device_name}:{local_rank}" device = f"{current_platform.device_name}:{local_rank}"
current_platform.set_device(device) current_platform.set_device(device)
torch.set_default_device(device) torch.set_default_device(device)
@@ -408,7 +409,7 @@ def run_dp_sharded_mrope_vision_model_uneven_load_worker(
): ):
"""Test run_dp_sharded_mrope_vision_model with uneven load distribution.""" """Test run_dp_sharded_mrope_vision_model with uneven load distribution."""
# Set up distributed environment # Set up distributed environment
current_platform.seed_everything(123) set_random_seed(123)
device = f"{current_platform.device_name}:{local_rank}" device = f"{current_platform.device_name}:{local_rank}"
current_platform.set_device(device) current_platform.set_device(device)
torch.set_default_device(device) torch.set_default_device(device)
@@ -19,7 +19,11 @@ from vllm.attention.backends.registry import AttentionBackendEnum
from vllm.config import ModelConfig from vllm.config import ModelConfig
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.math_utils import cdiv from vllm.utils.math_utils import cdiv
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE, is_torch_equal_or_newer from vllm.utils.torch_utils import (
STR_DTYPE_TO_TORCH_DTYPE,
is_torch_equal_or_newer,
set_random_seed,
)
from vllm.v1.attention.backends.utils import ( from vllm.v1.attention.backends.utils import (
CommonAttentionMetadata, CommonAttentionMetadata,
set_kv_cache_layout, set_kv_cache_layout,
@@ -320,7 +324,7 @@ def _test_backend_correctness(
multiple GPUs. This tests that backends work correctly with different multiple GPUs. This tests that backends work correctly with different
head counts. head counts.
""" """
current_platform.seed_everything(42) set_random_seed(42)
hf_config_override = None hf_config_override = None
if tensor_parallel_size > 1: if tensor_parallel_size > 1:
+2 -1
View File
@@ -7,6 +7,7 @@ import pytest
import torch import torch
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.flash_attn import FlashAttentionBackend from vllm.v1.attention.backends.flash_attn import FlashAttentionBackend
from vllm.v1.kv_offload.mediums import CPULoadStoreSpec, GPULoadStoreSpec from vllm.v1.kv_offload.mediums import CPULoadStoreSpec, GPULoadStoreSpec
from vllm.v1.kv_offload.worker.cpu_gpu import CpuGpuOffloadingHandlers from vllm.v1.kv_offload.worker.cpu_gpu import CpuGpuOffloadingHandlers
@@ -62,7 +63,7 @@ def test_transfer(
seed: int, seed: int,
device: str, device: str,
) -> None: ) -> None:
current_platform.seed_everything(seed) set_random_seed(seed)
# create per-layer GPU KV caches based on available attn_backends # create per-layer GPU KV caches based on available attn_backends
attn_backends_list = BACKENDS_TO_TEST attn_backends_list = BACKENDS_TO_TEST
+2 -1
View File
@@ -15,6 +15,7 @@ import torch_xla.core.xla_model
from vllm.attention.layers.mm_encoder_attention import MMEncoderAttention from vllm.attention.layers.mm_encoder_attention import MMEncoderAttention
from vllm.attention.selector import _cached_get_attn_backend from vllm.attention.selector import _cached_get_attn_backend
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@@ -63,7 +64,7 @@ def test_mha_attn_forward(
head_size: int, head_size: int,
device: str, device: str,
): ):
current_platform.seed_everything(0) set_random_seed(0)
# These are expected to be f32 # These are expected to be f32
q = torch.randn(batch_size, seq_len, num_heads * head_size, device=device) q = torch.randn(batch_size, seq_len, num_heads * head_size, device=device)
k = torch.randn(batch_size, seq_len, num_kv_heads * head_size, device=device) k = torch.randn(batch_size, seq_len, num_kv_heads * head_size, device=device)
+2 -1
View File
@@ -26,6 +26,7 @@ from vllm.platforms import current_platform
from vllm.sampling_params import SamplingParams from vllm.sampling_params import SamplingParams
from vllm.utils.mem_constants import GiB_bytes from vllm.utils.mem_constants import GiB_bytes
from vllm.utils.system_utils import update_environment_variables from vllm.utils.system_utils import update_environment_variables
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.core.kv_cache_utils import estimate_max_model_len, get_kv_cache_configs from vllm.v1.core.kv_cache_utils import estimate_max_model_len, get_kv_cache_configs
from vllm.v1.core.sched.output import CachedRequestData, NewRequestData, SchedulerOutput from vllm.v1.core.sched.output import CachedRequestData, NewRequestData, SchedulerOutput
from vllm.v1.kv_cache_interface import ( from vllm.v1.kv_cache_interface import (
@@ -776,7 +777,7 @@ def test_hybrid_attention_mamba_tensor_shapes():
will not corrupt an attention block and vice versa will not corrupt an attention block and vice versa
""" """
current_platform.seed_everything(42) set_random_seed(42)
update_environment_variables( update_environment_variables(
{ {
-2
View File
@@ -2,10 +2,8 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm.model_executor.parameter import BasevLLMParameter, PackedvLLMParameter from vllm.model_executor.parameter import BasevLLMParameter, PackedvLLMParameter
from vllm.model_executor.utils import set_random_seed
__all__ = [ __all__ = [
"set_random_seed",
"BasevLLMParameter", "BasevLLMParameter",
"PackedvLLMParameter", "PackedvLLMParameter",
] ]
-6
View File
@@ -10,12 +10,6 @@ import torch
from vllm.utils.torch_utils import is_torch_equal_or_newer from vllm.utils.torch_utils import is_torch_equal_or_newer
def set_random_seed(seed: int | None) -> None:
from vllm.platforms import current_platform
current_platform.seed_everything(seed)
def set_weight_attrs( def set_weight_attrs(
weight: torch.Tensor, weight: torch.Tensor,
weight_attrs: dict[str, Any] | None, weight_attrs: dict[str, Any] | None,
+4
View File
@@ -372,6 +372,10 @@ class Platform:
Loosely based on: https://github.com/Lightning-AI/pytorch-lightning/blob/2.4.0/src/lightning/fabric/utilities/seed.py#L20 Loosely based on: https://github.com/Lightning-AI/pytorch-lightning/blob/2.4.0/src/lightning/fabric/utilities/seed.py#L20
""" """
logger.info_once(
"`seed_everything` is deprecated. It will be removed in v0.14.0 or later. "
"Please use `vllm.utils.torch_utils.set_random_seed` instead."
)
if seed is not None: if seed is not None:
random.seed(seed) random.seed(seed)
np.random.seed(seed) np.random.seed(seed)
+10 -5
View File
@@ -3,6 +3,7 @@
import contextlib import contextlib
import importlib.metadata import importlib.metadata
import os import os
import random
import threading import threading
from collections.abc import Callable, Collection from collections.abc import Callable, Collection
from functools import lru_cache from functools import lru_cache
@@ -278,6 +279,13 @@ def kv_cache_dtype_str_to_dtype(
return STR_DTYPE_TO_TORCH_DTYPE[kv_cache_dtype] return STR_DTYPE_TO_TORCH_DTYPE[kv_cache_dtype]
def set_random_seed(seed: int | None) -> None:
if seed is not None:
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
def create_kv_caches_with_random_flash( def create_kv_caches_with_random_flash(
num_blocks: int, num_blocks: int,
block_size: int, block_size: int,
@@ -290,9 +298,7 @@ def create_kv_caches_with_random_flash(
device: str | None = "cuda", device: str | None = "cuda",
cache_layout: str | None = "NHD", cache_layout: str | None = "NHD",
) -> tuple[list[torch.Tensor], list[torch.Tensor]]: ) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
from vllm.platforms import current_platform set_random_seed(seed)
current_platform.seed_everything(seed)
dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype) dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype)
generic_kv_cache_shape = (num_blocks, 2, block_size, num_heads, head_size) generic_kv_cache_shape = (num_blocks, 2, block_size, num_heads, head_size)
@@ -335,9 +341,8 @@ def create_kv_caches_with_random(
raise ValueError( raise ValueError(
f"Does not support key cache of type fp8 with head_size {head_size}" f"Does not support key cache of type fp8 with head_size {head_size}"
) )
from vllm.platforms import current_platform
current_platform.seed_everything(seed) set_random_seed(seed)
dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype) dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype)
+1 -1
View File
@@ -10,10 +10,10 @@ import torch
from vllm import envs from vllm import envs
from vllm.config import VllmConfig from vllm.config import VllmConfig
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.model_executor.utils import set_random_seed
from vllm.platforms import CpuArchEnum, current_platform from vllm.platforms import CpuArchEnum, current_platform
from vllm.platforms.cpu import CpuPlatform, LogicalCPUInfo from vllm.platforms.cpu import CpuPlatform, LogicalCPUInfo
from vllm.profiler.wrapper import TorchProfilerWrapper from vllm.profiler.wrapper import TorchProfilerWrapper
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.cpu_model_runner import CPUModelRunner from vllm.v1.worker.cpu_model_runner import CPUModelRunner
from vllm.v1.worker.gpu_worker import Worker, init_worker_distributed_environment from vllm.v1.worker.gpu_worker import Worker, init_worker_distributed_environment
+1 -1
View File
@@ -34,7 +34,6 @@ from vllm.distributed.parallel_state import (
) )
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.lora.request import LoRARequest from vllm.lora.request import LoRARequest
from vllm.model_executor import set_random_seed
from vllm.model_executor.models.interfaces import is_mixture_of_experts from vllm.model_executor.models.interfaces import is_mixture_of_experts
from vllm.model_executor.warmup.kernel_warmup import kernel_warmup from vllm.model_executor.warmup.kernel_warmup import kernel_warmup
from vllm.platforms import current_platform from vllm.platforms import current_platform
@@ -43,6 +42,7 @@ from vllm.sequence import IntermediateTensors
from vllm.tasks import SupportedTask from vllm.tasks import SupportedTask
from vllm.utils.mem_constants import GiB_bytes from vllm.utils.mem_constants import GiB_bytes
from vllm.utils.mem_utils import MemorySnapshot, memory_profiling from vllm.utils.mem_utils import MemorySnapshot, memory_profiling
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput
from vllm.v1.engine import ReconfigureDistributedRequest, ReconfigureRankType from vllm.v1.engine import ReconfigureDistributedRequest, ReconfigureRankType
from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheSpec from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheSpec
+1 -2
View File
@@ -20,12 +20,11 @@ from vllm.distributed.kv_transfer import (
) )
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.lora.request import LoRARequest from vllm.lora.request import LoRARequest
from vllm.model_executor import set_random_seed
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.platforms.tpu import USE_TPU_INFERENCE from vllm.platforms.tpu import USE_TPU_INFERENCE
from vllm.tasks import SupportedTask from vllm.tasks import SupportedTask
from vllm.utils.math_utils import cdiv from vllm.utils.math_utils import cdiv
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE, set_random_seed
from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput
from vllm.v1.kv_cache_interface import AttentionSpec, KVCacheConfig, KVCacheSpec from vllm.v1.kv_cache_interface import AttentionSpec, KVCacheConfig, KVCacheSpec
from vllm.v1.outputs import ModelRunnerOutput from vllm.v1.outputs import ModelRunnerOutput
+1 -1
View File
@@ -9,9 +9,9 @@ import torch.distributed
from vllm.config import VllmConfig from vllm.config import VllmConfig
from vllm.distributed import get_world_group from vllm.distributed import get_world_group
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.model_executor import set_random_seed
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.profiler.wrapper import TorchProfilerWrapper from vllm.profiler.wrapper import TorchProfilerWrapper
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.worker.gpu_worker import Worker, init_worker_distributed_environment from vllm.v1.worker.gpu_worker import Worker, init_worker_distributed_environment
from vllm.v1.worker.xpu_model_runner import XPUModelRunner from vllm.v1.worker.xpu_model_runner import XPUModelRunner