Turn @config into a dataclass_transform (#31541)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
|
||||
import json
|
||||
from argparse import ArgumentError
|
||||
from contextlib import nullcontext
|
||||
from dataclasses import dataclass, field
|
||||
from contextlib import AbstractContextManager, nullcontext
|
||||
from typing import Annotated, Literal
|
||||
|
||||
import pytest
|
||||
from pydantic import Field
|
||||
|
||||
from vllm.config import AttentionConfig, CompilationConfig, config
|
||||
from vllm.engine.arg_utils import (
|
||||
@@ -96,7 +96,7 @@ def test_get_type(type_hints, type, expected):
|
||||
],
|
||||
)
|
||||
def test_literal_to_kwargs(type_hints, expected):
|
||||
context = nullcontext()
|
||||
context: AbstractContextManager[object] = nullcontext()
|
||||
if expected is Exception:
|
||||
context = pytest.raises(expected)
|
||||
with context:
|
||||
@@ -104,14 +104,12 @@ def test_literal_to_kwargs(type_hints, expected):
|
||||
|
||||
|
||||
@config
|
||||
@dataclass
|
||||
class NestedConfig:
|
||||
field: int = 1
|
||||
"""field"""
|
||||
|
||||
|
||||
@config
|
||||
@dataclass
|
||||
class DummyConfig:
|
||||
regular_bool: bool = True
|
||||
"""Regular bool with default True"""
|
||||
@@ -119,23 +117,23 @@ class DummyConfig:
|
||||
"""Optional bool with default None"""
|
||||
optional_literal: Literal["x", "y"] | None = None
|
||||
"""Optional literal with default None"""
|
||||
tuple_n: tuple[int, ...] = field(default_factory=lambda: (1, 2, 3))
|
||||
tuple_n: tuple[int, ...] = Field(default_factory=lambda: (1, 2, 3))
|
||||
"""Tuple with variable length"""
|
||||
tuple_2: tuple[int, int] = field(default_factory=lambda: (1, 2))
|
||||
tuple_2: tuple[int, int] = Field(default_factory=lambda: (1, 2))
|
||||
"""Tuple with fixed length"""
|
||||
list_n: list[int] = field(default_factory=lambda: [1, 2, 3])
|
||||
list_n: list[int] = Field(default_factory=lambda: [1, 2, 3])
|
||||
"""List with variable length"""
|
||||
list_literal: list[Literal[1, 2]] = field(default_factory=list)
|
||||
list_literal: list[Literal[1, 2]] = Field(default_factory=list)
|
||||
"""List with literal choices"""
|
||||
list_union: list[str | type[object]] = field(default_factory=list)
|
||||
list_union: list[str | type[object]] = Field(default_factory=list)
|
||||
"""List with union type"""
|
||||
set_n: set[int] = field(default_factory=lambda: {1, 2, 3})
|
||||
set_n: set[int] = Field(default_factory=lambda: {1, 2, 3})
|
||||
"""Set with variable length"""
|
||||
literal_literal: Literal[Literal[1], Literal[2]] = 1
|
||||
"""Literal of literals with default 1"""
|
||||
json_tip: dict = field(default_factory=dict)
|
||||
json_tip: dict = Field(default_factory=dict)
|
||||
"""Dict which will be JSON in CLI"""
|
||||
nested_config: NestedConfig = field(default_factory=NestedConfig)
|
||||
nested_config: NestedConfig = Field(default_factory=NestedConfig)
|
||||
"""Nested config"""
|
||||
|
||||
|
||||
@@ -195,7 +193,7 @@ def test_get_kwargs():
|
||||
json_tip = "Should either be a valid JSON string or JSON keys"
|
||||
assert json_tip in kwargs["json_tip"]["help"]
|
||||
# nested config should construct the nested config
|
||||
assert kwargs["nested_config"]["type"]('{"field": 2}') == NestedConfig(2)
|
||||
assert kwargs["nested_config"]["type"]('{"field": 2}') == NestedConfig(2) # type: ignore[call-arg]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -66,9 +66,6 @@ class _TestConfigFields:
|
||||
|
||||
|
||||
def test_get_field():
|
||||
with pytest.raises(ValueError):
|
||||
get_field(_TestConfigFields, "a")
|
||||
|
||||
b = get_field(_TestConfigFields, "b")
|
||||
assert isinstance(b, Field)
|
||||
assert b.default is MISSING
|
||||
@@ -188,7 +185,7 @@ def test_get_pooling_config():
|
||||
)
|
||||
def test_get_pooling_config_from_args():
|
||||
model_id = "sentence-transformers/all-MiniLM-L12-v2"
|
||||
pooler_config = PoolerConfig(seq_pooling_type="CLS", normalize=True)
|
||||
pooler_config = PoolerConfig(seq_pooling_type="CLS", use_activation=False)
|
||||
model_config = ModelConfig(model_id, pooler_config=pooler_config)
|
||||
|
||||
assert asdict(model_config.pooler_config) == asdict(pooler_config)
|
||||
|
||||
@@ -7,31 +7,22 @@ import pytest
|
||||
|
||||
from tools.pre_commit.validate_config import validate_ast
|
||||
|
||||
_TestConfig1 = """
|
||||
_TestConfig1 = '''
|
||||
@config
|
||||
class _TestConfig1:
|
||||
pass
|
||||
"""
|
||||
|
||||
_TestConfig2 = '''
|
||||
@config
|
||||
@dataclass
|
||||
class _TestConfig2:
|
||||
a: int
|
||||
"""docstring"""
|
||||
'''
|
||||
|
||||
_TestConfig3 = """
|
||||
_TestConfig2 = """
|
||||
@config
|
||||
@dataclass
|
||||
class _TestConfig3:
|
||||
class _TestConfig2:
|
||||
a: int = 1
|
||||
"""
|
||||
|
||||
_TestConfig4 = '''
|
||||
_TestConfig3 = '''
|
||||
@config
|
||||
@dataclass
|
||||
class _TestConfig4:
|
||||
class _TestConfig3:
|
||||
a: Union[Literal[1], Literal[2]] = 1
|
||||
"""docstring"""
|
||||
'''
|
||||
@@ -40,10 +31,9 @@ class _TestConfig4:
|
||||
@pytest.mark.parametrize(
|
||||
("test_config", "expected_error"),
|
||||
[
|
||||
(_TestConfig1, "must be a dataclass"),
|
||||
(_TestConfig2, "must have a default"),
|
||||
(_TestConfig3, "must have a docstring"),
|
||||
(_TestConfig4, "must use a single Literal"),
|
||||
(_TestConfig1, "must have a default"),
|
||||
(_TestConfig2, "must have a docstring"),
|
||||
(_TestConfig3, "must use a single Literal"),
|
||||
],
|
||||
)
|
||||
def test_config(test_config, expected_error):
|
||||
|
||||
@@ -766,8 +766,8 @@ def assert_draft_model_correctness(args: ArgsTest, enforce_eager: bool):
|
||||
"max_model_len": args.max_model_len,
|
||||
"enforce_eager": enforce_eager,
|
||||
"draft_tensor_parallel_size": args.draft_tensor_parallel_size,
|
||||
"max_num_seqs": 100, # limit cudagraph capture runtime
|
||||
},
|
||||
max_num_seqs=100, # limit cudagraph capture runtime
|
||||
max_model_len=args.max_model_len,
|
||||
gpu_memory_utilization=args.gpu_memory_utilization,
|
||||
tensor_parallel_size=args.target_tensor_parallel_size,
|
||||
|
||||
@@ -26,11 +26,8 @@ def test_backend_guidance_rollback_terminated():
|
||||
# guidance backend. In that case we are in a stopped state, but
|
||||
# it should be reverted in case EOS is not accepted by the target
|
||||
# model.
|
||||
vllm_config = VllmConfig(
|
||||
decoding_config=StructuredOutputsConfig(
|
||||
backend="guidance",
|
||||
)
|
||||
)
|
||||
structured_outputs_config = StructuredOutputsConfig(backend="guidance")
|
||||
vllm_config = VllmConfig(structured_outputs_config=structured_outputs_config)
|
||||
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER)
|
||||
|
||||
backend = GuidanceBackend(
|
||||
|
||||
Reference in New Issue
Block a user