mirror of
https://github.com/vllm-project/vllm.git
synced 2025-10-20 23:03:52 +08:00
Fix validate-config
pre-commit check (#25157)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@ -164,9 +164,7 @@ repos:
|
|||||||
name: Validate configuration has default values and that each field has a docstring
|
name: Validate configuration has default values and that each field has a docstring
|
||||||
entry: python tools/validate_config.py
|
entry: python tools/validate_config.py
|
||||||
language: python
|
language: python
|
||||||
types: [python]
|
additional_dependencies: [regex]
|
||||||
pass_filenames: true
|
|
||||||
files: vllm/config.py|tests/test_config.py|vllm/entrypoints/openai/cli_args.py
|
|
||||||
# Keep `suggestion` last
|
# Keep `suggestion` last
|
||||||
- id: suggestion
|
- id: suggestion
|
||||||
name: Suggestion
|
name: Suggestion
|
||||||
|
@ -9,6 +9,8 @@ import ast
|
|||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import regex as re
|
||||||
|
|
||||||
|
|
||||||
def get_attr_docs(cls_node: ast.ClassDef) -> dict[str, str]:
|
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:
|
for stmt in class_node.body:
|
||||||
# A field is defined as a class variable that has a type annotation.
|
# A field is defined as a class variable that has a type annotation.
|
||||||
if isinstance(stmt, ast.AnnAssign):
|
if isinstance(stmt, ast.AnnAssign):
|
||||||
# Skip ClassVar
|
# Skip ClassVar and InitVar
|
||||||
# see https://docs.python.org/3/library/dataclasses.html#class-variables
|
# see https://docs.python.org/3/library/dataclasses.html#class-variables
|
||||||
if isinstance(stmt.annotation, ast.Subscript) and isinstance(
|
# and https://docs.python.org/3/library/dataclasses.html#init-only-variables
|
||||||
stmt.annotation.value,
|
if (isinstance(stmt.annotation, ast.Subscript)
|
||||||
ast.Name) and stmt.annotation.value.id == "ClassVar":
|
and isinstance(stmt.annotation.value, ast.Name)
|
||||||
|
and stmt.annotation.value.id in {"ClassVar", "InitVar"}):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(stmt.target, ast.Name):
|
if isinstance(stmt.target, ast.Name):
|
||||||
@ -132,7 +135,7 @@ def validate_ast(tree: ast.stmt):
|
|||||||
|
|
||||||
def validate_file(file_path: str):
|
def validate_file(file_path: str):
|
||||||
try:
|
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:
|
with open(file_path, encoding="utf-8") as f:
|
||||||
source = f.read()
|
source = f.read()
|
||||||
|
|
||||||
@ -140,7 +143,7 @@ def validate_file(file_path: str):
|
|||||||
validate_ast(tree)
|
validate_ast(tree)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(e)
|
print(e)
|
||||||
SystemExit(2)
|
raise SystemExit(1) from e
|
||||||
else:
|
else:
|
||||||
print("✅")
|
print("✅")
|
||||||
|
|
||||||
@ -151,7 +154,13 @@ def fail(message: str, node: ast.stmt):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
for filename in sys.argv[1:]:
|
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__":
|
if __name__ == "__main__":
|
||||||
|
@ -450,6 +450,8 @@ class ModelConfig:
|
|||||||
|
|
||||||
# Multimodal config and init vars
|
# Multimodal config and init vars
|
||||||
multimodal_config: Optional[MultiModalConfig] = None
|
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
|
limit_mm_per_prompt: InitVar[Optional[dict[str, int]]] = None
|
||||||
media_io_kwargs: InitVar[Optional[dict[str, dict[str, Any]]]] = None
|
media_io_kwargs: InitVar[Optional[dict[str, dict[str, Any]]]] = None
|
||||||
mm_processor_kwargs: InitVar[Optional[dict[str, Any]]] = None
|
mm_processor_kwargs: InitVar[Optional[dict[str, Any]]] = None
|
||||||
|
Reference in New Issue
Block a user