Add platform manual_seed_all API (#38468)
Signed-off-by: Yan Ma <yan.ma@intel.com>
This commit is contained in:
@@ -122,8 +122,6 @@ def test_linear_decode_forward_triton(
|
||||
dtype: torch.dtype,
|
||||
):
|
||||
torch.set_default_device("cuda")
|
||||
torch.manual_seed(42)
|
||||
torch.cuda.manual_seed_all(42)
|
||||
set_random_seed(42)
|
||||
base = 0.01
|
||||
q = base * torch.randn(batch_size, num_heads, 1, head_size, dtype=dtype)
|
||||
@@ -165,8 +163,6 @@ def test_linear_decode_forward_triton_with_padding(
|
||||
dtype: torch.dtype,
|
||||
):
|
||||
torch.set_default_device("cuda")
|
||||
torch.manual_seed(42)
|
||||
torch.cuda.manual_seed_all(42)
|
||||
set_random_seed(42)
|
||||
|
||||
batch_size = 4
|
||||
@@ -229,8 +225,6 @@ def test_lightning_attention_reference(
|
||||
dtype: torch.dtype,
|
||||
):
|
||||
torch.set_default_device("cuda")
|
||||
torch.manual_seed(42)
|
||||
torch.cuda.manual_seed_all(42)
|
||||
set_random_seed(42)
|
||||
|
||||
base = 0.01
|
||||
|
||||
@@ -17,6 +17,7 @@ from vllm.model_executor.layers.quantization.utils.int8_utils import (
|
||||
per_token_group_quant_int8,
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.torch_utils import set_random_seed
|
||||
|
||||
DTYPES = [torch.bfloat16, torch.float]
|
||||
QUANT_DTYPES = [torch.int8, current_platform.fp8_dtype()]
|
||||
@@ -180,9 +181,7 @@ def test_rms_norm(
|
||||
device: str,
|
||||
strided_input: bool,
|
||||
) -> None:
|
||||
torch.random.manual_seed(seed)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.manual_seed(seed)
|
||||
set_random_seed(seed)
|
||||
torch.set_default_device(device)
|
||||
torch.accelerator.set_device_index(device)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from vllm.model_executor.layers.quantization.utils.flashinfer_mxint4_moe import
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.scalar_type import scalar_types
|
||||
from vllm.utils.torch_utils import set_random_seed
|
||||
|
||||
|
||||
def mxint4_quantize(
|
||||
@@ -134,7 +135,7 @@ def test_marlin_vs_trtllm_mxint4_moe_kimik2(monkeypatch, m, n, k, e, topk, group
|
||||
pytest.importorskip("flashinfer")
|
||||
monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_INT4", "1")
|
||||
|
||||
torch.cuda.manual_seed(0)
|
||||
set_random_seed(0)
|
||||
|
||||
dtype = torch.bfloat16
|
||||
|
||||
@@ -289,7 +290,7 @@ def test_flashinfer_trtllm_mxint4_moe_wrapper(m, n, k, e, topk):
|
||||
flashinfer_trtllm_mxint4_moe,
|
||||
)
|
||||
|
||||
torch.cuda.manual_seed(0)
|
||||
set_random_seed(0)
|
||||
dtype = torch.bfloat16
|
||||
|
||||
a = torch.randn((m, k), device="cuda", dtype=dtype) * 0.5
|
||||
|
||||
@@ -1031,7 +1031,7 @@ def test_fused_marlin_moe(
|
||||
act_order: bool,
|
||||
is_k_full: bool,
|
||||
):
|
||||
torch.cuda.manual_seed(1)
|
||||
set_random_seed(1)
|
||||
group_size = group_blocks if group_blocks <= 0 else group_blocks * 16
|
||||
|
||||
if c_type == scalar_types.float16:
|
||||
@@ -1131,7 +1131,7 @@ def test_fused_marlin_moe(
|
||||
@pytest.mark.skipif(current_platform.is_rocm(), reason="Skip for rocm")
|
||||
@pytest.mark.parametrize("m", [1, 256])
|
||||
def test_fused_marlin_moe_with_bias(m):
|
||||
torch.cuda.manual_seed(0)
|
||||
set_random_seed(0)
|
||||
|
||||
e, topk = 32, 4
|
||||
n, k = 2048, 2048
|
||||
@@ -1213,7 +1213,7 @@ def test_fused_marlin_moe_non_gated(
|
||||
Non-gated activations like relu2 don't have the gate-up projection pattern,
|
||||
so w1 has shape (e, n, k) instead of (e, 2*n, k).
|
||||
"""
|
||||
torch.cuda.manual_seed(42)
|
||||
set_random_seed(42)
|
||||
|
||||
group_size = 16 # NVFP4 group size
|
||||
is_k_full = True
|
||||
@@ -1397,7 +1397,7 @@ def test_cpu_fused_moe_basic(
|
||||
from vllm.model_executor.layers.fused_moe.cpu_fused_moe import CPUFusedMOE
|
||||
|
||||
device = "cpu"
|
||||
torch.manual_seed(7)
|
||||
set_random_seed(7)
|
||||
|
||||
a = torch.randn((m, k), device=device, dtype=dtype) / 10
|
||||
w13 = torch.randn((e, 2 * n, k), device=device, dtype=dtype) / 10
|
||||
@@ -1469,7 +1469,7 @@ def test_batched_fused_marlin_moe(
|
||||
f"topk={topk}, "
|
||||
f"max_tokens_per_batch={max_tokens_per_batch}"
|
||||
)
|
||||
torch.cuda.manual_seed(0)
|
||||
set_random_seed(0)
|
||||
|
||||
dtype = torch.bfloat16
|
||||
quant_dtype = scalar_types.float4_e2m1f
|
||||
|
||||
@@ -15,7 +15,7 @@ from vllm.config import VllmConfig, set_current_vllm_config
|
||||
from vllm.forward_context import set_forward_context
|
||||
from vllm.model_executor.layers.fused_moe.shared_fused_moe import SharedFusedMoE
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.torch_utils import is_torch_equal_or_newer
|
||||
from vllm.utils.torch_utils import is_torch_equal_or_newer, set_random_seed
|
||||
|
||||
|
||||
class SimpleLinear(nn.Module):
|
||||
@@ -144,8 +144,7 @@ def test_routed_input_transform_inside_vs_outside(
|
||||
|
||||
rocm_aiter_ops.refresh_env_variables()
|
||||
|
||||
torch.manual_seed(42)
|
||||
torch.cuda.manual_seed(42)
|
||||
set_random_seed(42)
|
||||
|
||||
num_experts = 8
|
||||
top_k = 2
|
||||
|
||||
@@ -7,6 +7,7 @@ import vllm._custom_ops as ops
|
||||
from tests.kernels.utils import opcheck
|
||||
from vllm.model_executor.layers.activation import SiluAndMul
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.torch_utils import set_random_seed
|
||||
|
||||
DTYPES = [torch.bfloat16, torch.float16]
|
||||
QUANT_DTYPES = [current_platform.fp8_dtype()]
|
||||
@@ -49,9 +50,7 @@ def test_silu_and_mul(
|
||||
seed: int,
|
||||
device: str,
|
||||
) -> None:
|
||||
torch.random.manual_seed(seed)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.manual_seed(seed)
|
||||
set_random_seed(seed)
|
||||
torch.set_default_device(device)
|
||||
|
||||
layer = SiluAndMul()
|
||||
|
||||
Reference in New Issue
Block a user