Unverified Commit 3ed1ec4a authored by Harry Mellor's avatar Harry Mellor Committed by GitHub
Browse files

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


Signed-off-by: default avatarHarry Mellor <19981378+hmellor@users.noreply.github.com>
parent 5a33ae9a
......@@ -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
......
......@@ -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,6 +154,12 @@ def fail(message: str, node: ast.stmt):
def main():
for filename in sys.argv[1:]:
# 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)
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment