A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 2, 17:01 UTC
Validate against some config fields being set to 0 (#43794)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
May 27, 2026 at 22:14 UTC
2c2c966669032e863f94919e9225aa12378c9364
2 files changed
+17
-9
vllm/config/cache.py
+16
-8
@@ -1,10 +1,11 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
+from collections.abc import Callable
5
from dataclasses import field
5
-from typing import ClassVar, Literal
6
+from typing import Any, ClassVar, Literal
7
7
-from pydantic import Field, SkipValidation, field_validator, model_validator
8
+from pydantic import Field, field_validator, model_validator
9
10
from vllm.config.utils import config
11
from vllm.logger import init_logger
@@ -44,14 +45,14 @@ class CacheConfig:
45
46
DEFAULT_BLOCK_SIZE: ClassVar[int] = 16
47
47
- block_size: SkipValidation[int] = None # type: ignore[assignment]
48
+ block_size: int = Field(default=None, gt=0) # type: ignore[assignment]
49
"""Size of a contiguous cache block in number of tokens.
50
Accepts None (meaning "use default"). After construction, always int."""
51
user_specified_block_size: bool = field(default=False, init=False)
52
"""Whether block_size was explicitly provided. Derived automatically."""
53
user_specified_mamba_block_size: bool = field(default=False, init=False)
54
"""Whether mamba_block_size was explicitly provided. Derived automatically."""
54
- hash_block_size: SkipValidation[int] | None = None # type: ignore
55
+ hash_block_size: int | None = Field(default=None, gt=0)
56
"""Block size (in tokens) used for computing Request's block_hashes.
57
58
This can be set to a finer granularity than the physical KV cache block
@@ -220,19 +221,26 @@ class CacheConfig:
221
_block_size_resolved: bool = field(default=False, init=False)
222
"""Guard against pydantic re-running _apply_block_size_default."""
223
224
+ @field_validator("block_size", mode="wrap")
225
+ @classmethod
226
+ def _skip_none_validation(cls, value: Any, handler: Callable) -> Any:
227
+ if value is None:
228
+ return value
229
+ return handler(value)
230
+
231
@model_validator(mode="after")
232
def _apply_block_size_default(self) -> "CacheConfig":
233
# Pydantic re-runs validators when CacheConfig is nested inside
234
# another pydantic model (e.g. VllmConfig). Guard against that.
235
if self._block_size_resolved:
236
return self
229
- object.__setattr__(self, "_block_size_resolved", True)
237
+ self._block_size_resolved = True
238
if self.block_size is None:
231
- object.__setattr__(self, "block_size", self.DEFAULT_BLOCK_SIZE)
239
+ self.block_size = self.DEFAULT_BLOCK_SIZE
240
else:
233
- object.__setattr__(self, "user_specified_block_size", True)
241
+ self.user_specified_block_size = True
242
if self.mamba_block_size is not None:
235
- object.__setattr__(self, "user_specified_mamba_block_size", True)
243
+ self.user_specified_mamba_block_size = True
244
return self
245
246
@field_validator("calculate_kv_scales", mode="after")
vllm/config/model.py
+1
-1
@@ -791,7 +791,7 @@ class ModelConfig:
791
f"{type(self.tokenizer).__name__}: {self.tokenizer!r}. "
792
"Please provide a valid tokenizer path or HuggingFace model ID."
793
)
794
- if not isinstance(self.max_model_len, int):
794
+ if not isinstance(self.max_model_len, int) or self.max_model_len < 1:
795
raise ValueError(
796
f"max_model_len must be a positive integer, "
797
f"got {type(self.max_model_len).__name__}: {self.max_model_len!r}. "