Fix validate-config pre-commit check (#25157)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-09-18 13:06:28 +01:00
committed by GitHub
parent 5a33ae9a3f
commit 3ed1ec4af2
3 changed files with 19 additions and 10 deletions

View File

@ -164,9 +164,7 @@ repos:
name: Validate configuration has default values and that each field has a docstring
entry: python tools/validate_config.py
language: python
types: [python]
pass_filenames: true
files: vllm/config.py|tests/test_config.py|vllm/entrypoints/openai/cli_args.py
additional_dependencies: [regex]
# Keep `suggestion` last
- id: suggestion
name: Suggestion

View File

@ -9,6 +9,8 @@ import ast
import inspect
import sys
import regex as re
def get_attr_docs(cls_node: ast.ClassDef) -> dict[str, str]:
"""
@ -88,11 +90,12 @@ def validate_class(class_node: ast.ClassDef):
for stmt in class_node.body:
# A field is defined as a class variable that has a type annotation.
if isinstance(stmt, ast.AnnAssign):
# Skip ClassVar
# Skip ClassVar and InitVar
# see https://docs.python.org/3/library/dataclasses.html#class-variables
if isinstance(stmt.annotation, ast.Subscript) and isinstance(
stmt.annotation.value,
ast.Name) and stmt.annotation.value.id == "ClassVar":
# and https://docs.python.org/3/library/dataclasses.html#init-only-variables
if (isinstance(stmt.annotation, ast.Subscript)
and isinstance(stmt.annotation.value, ast.Name)
and stmt.annotation.value.id in {"ClassVar", "InitVar"}):
continue
if isinstance(stmt.target, ast.Name):
@ -132,7 +135,7 @@ def validate_ast(tree: ast.stmt):
def validate_file(file_path: str):
try:
print(f"validating {file_path} config dataclasses ", end="")
print(f"Validating {file_path} config dataclasses ", end="")
with open(file_path, encoding="utf-8") as f:
source = f.read()
@ -140,7 +143,7 @@ def validate_file(file_path: str):
validate_ast(tree)
except ValueError as e:
print(e)
SystemExit(2)
raise SystemExit(1) from e
else:
print("")
@ -151,7 +154,13 @@ def fail(message: str, node: ast.stmt):
def main():
for filename in sys.argv[1:]:
validate_file(filename)
# Only run for Python files in vllm/ or tests/
if not re.match(r"^(vllm|tests)/.*\.py$", filename):
continue
# Only run if the file contains @config
with open(filename, encoding="utf-8") as f:
if "@config" in f.read():
validate_file(filename)
if __name__ == "__main__":

View File

@ -450,6 +450,8 @@ class ModelConfig:
# Multimodal config and init vars
multimodal_config: Optional[MultiModalConfig] = None
"""Configuration for multimodal model. If `None`, this will be inferred
from the architecture of `self.model`."""
limit_mm_per_prompt: InitVar[Optional[dict[str, int]]] = None
media_io_kwargs: InitVar[Optional[dict[str, dict[str, Any]]]] = None
mm_processor_kwargs: InitVar[Optional[dict[str, Any]]] = None