Validate against some config fields being set to 0 (#43794)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
+16
-8
@@ -1,10 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import field
|
||||
from typing import ClassVar, Literal
|
||||
from typing import Any, ClassVar, Literal
|
||||
|
||||
from pydantic import Field, SkipValidation, field_validator, model_validator
|
||||
from pydantic import Field, field_validator, model_validator
|
||||
|
||||
from vllm.config.utils import config
|
||||
from vllm.logger import init_logger
|
||||
@@ -44,14 +45,14 @@ class CacheConfig:
|
||||
|
||||
DEFAULT_BLOCK_SIZE: ClassVar[int] = 16
|
||||
|
||||
block_size: SkipValidation[int] = None # type: ignore[assignment]
|
||||
block_size: int = Field(default=None, gt=0) # type: ignore[assignment]
|
||||
"""Size of a contiguous cache block in number of tokens.
|
||||
Accepts None (meaning "use default"). After construction, always int."""
|
||||
user_specified_block_size: bool = field(default=False, init=False)
|
||||
"""Whether block_size was explicitly provided. Derived automatically."""
|
||||
user_specified_mamba_block_size: bool = field(default=False, init=False)
|
||||
"""Whether mamba_block_size was explicitly provided. Derived automatically."""
|
||||
hash_block_size: SkipValidation[int] | None = None # type: ignore
|
||||
hash_block_size: int | None = Field(default=None, gt=0)
|
||||
"""Block size (in tokens) used for computing Request's block_hashes.
|
||||
|
||||
This can be set to a finer granularity than the physical KV cache block
|
||||
@@ -220,19 +221,26 @@ class CacheConfig:
|
||||
_block_size_resolved: bool = field(default=False, init=False)
|
||||
"""Guard against pydantic re-running _apply_block_size_default."""
|
||||
|
||||
@field_validator("block_size", mode="wrap")
|
||||
@classmethod
|
||||
def _skip_none_validation(cls, value: Any, handler: Callable) -> Any:
|
||||
if value is None:
|
||||
return value
|
||||
return handler(value)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _apply_block_size_default(self) -> "CacheConfig":
|
||||
# Pydantic re-runs validators when CacheConfig is nested inside
|
||||
# another pydantic model (e.g. VllmConfig). Guard against that.
|
||||
if self._block_size_resolved:
|
||||
return self
|
||||
object.__setattr__(self, "_block_size_resolved", True)
|
||||
self._block_size_resolved = True
|
||||
if self.block_size is None:
|
||||
object.__setattr__(self, "block_size", self.DEFAULT_BLOCK_SIZE)
|
||||
self.block_size = self.DEFAULT_BLOCK_SIZE
|
||||
else:
|
||||
object.__setattr__(self, "user_specified_block_size", True)
|
||||
self.user_specified_block_size = True
|
||||
if self.mamba_block_size is not None:
|
||||
object.__setattr__(self, "user_specified_mamba_block_size", True)
|
||||
self.user_specified_mamba_block_size = True
|
||||
return self
|
||||
|
||||
@field_validator("calculate_kv_scales", mode="after")
|
||||
|
||||
@@ -791,7 +791,7 @@ class ModelConfig:
|
||||
f"{type(self.tokenizer).__name__}: {self.tokenizer!r}. "
|
||||
"Please provide a valid tokenizer path or HuggingFace model ID."
|
||||
)
|
||||
if not isinstance(self.max_model_len, int):
|
||||
if not isinstance(self.max_model_len, int) or self.max_model_len < 1:
|
||||
raise ValueError(
|
||||
f"max_model_len must be a positive integer, "
|
||||
f"got {type(self.max_model_len).__name__}: {self.max_model_len!r}. "
|
||||
|
||||
Reference in New Issue
Block a user