mirror of
https://github.com/deepseek-ai/DeepInfer.git
synced 2026-10-31 00:36:20 +08:00
A negative seq_seed was silently masked to a huge positive value by seed & 0xFFFF_FFFF_FFFF_FFFF, so the seq_seed < 0 check in _verify_args could never trigger. Validate the seed before masking, and give the bare TypeError a message. Positive-seed masking behavior is unchanged. Add unit tests for seq_seed handling in tests/engine/test_sampling_params.py.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Unit tests for SamplingParams seq_seed handling."""
|
|
|
|
import pytest
|
|
import torch # noqa: F401 Load torch's shared libraries before deepinfer.
|
|
|
|
from deepinfer.sampling_params import SamplingParams
|
|
|
|
pytestmark = [pytest.mark.ci, pytest.mark.ci_npu]
|
|
|
|
|
|
def test_seq_seed_none_is_random_uint64() -> None:
|
|
params = SamplingParams()
|
|
assert 0 <= params.seq_seed < 2**64
|
|
|
|
|
|
def test_seq_seed_valid_is_preserved() -> None:
|
|
assert SamplingParams(seq_seed=42).seq_seed == 42
|
|
assert SamplingParams(seq_seed=2**64 - 1).seq_seed == 2**64 - 1
|
|
|
|
|
|
def test_seq_seed_wraps_to_uint64() -> None:
|
|
assert SamplingParams(seq_seed=2**64 + 5).seq_seed == 5
|
|
|
|
|
|
def test_seq_seed_negative_raises() -> None:
|
|
with pytest.raises(ValueError, match="seq_seed"):
|
|
SamplingParams(seq_seed=-1)
|
|
with pytest.raises(ValueError, match="seq_seed"):
|
|
SamplingParams(seq_seed=-(2**64) + 5)
|
|
|
|
|
|
def test_seq_seed_wrong_type_raises() -> None:
|
|
with pytest.raises(TypeError, match="seq_seed"):
|
|
SamplingParams(seq_seed="42") # type: ignore[arg-type]
|
|
with pytest.raises(TypeError, match="seq_seed"):
|
|
SamplingParams(seq_seed=1.5) # type: ignore[arg-type]
|