fix(security): Add VLLM_MAX_N_SEQUENCES environment variable and enforce limit (#37952)
Signed-off-by: jperezde <jperezde@redhat.com> Signed-off-by: Russell Bryant <rbryant@redhat.com> Co-authored-by: Russell Bryant <rbryant@redhat.com>
This commit is contained in:
co-authored by
Russell Bryant
parent
497e234d38
commit
b111f8a61f
@@ -12,6 +12,7 @@ from typing import Any
|
||||
import msgspec
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import ModelConfig, SpeculativeConfig, StructuredOutputsConfig
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.logger import init_logger
|
||||
@@ -169,6 +170,9 @@ class SamplingParams(
|
||||
n: int = 1
|
||||
"""Number of outputs to return for the given prompt request.
|
||||
|
||||
The maximum allowed value is controlled by the ``VLLM_MAX_N_SEQUENCES``
|
||||
environment variable (default: 16384).
|
||||
|
||||
NOTE:
|
||||
`AsyncLLM` streams outputs by default. When `n > 1`, all `n` outputs
|
||||
are generated and streamed cumulatively per request. To see all `n`
|
||||
@@ -425,6 +429,13 @@ class SamplingParams(
|
||||
raise ValueError(f"n must be an int, but is of type {type(self.n)}")
|
||||
if self.n < 1:
|
||||
raise ValueError(f"n must be at least 1, got {self.n}.")
|
||||
max_n = envs.VLLM_MAX_N_SEQUENCES
|
||||
if self.n > max_n:
|
||||
raise ValueError(
|
||||
f"n must be at most {max_n}, got {self.n}. "
|
||||
"To increase this limit, set the VLLM_MAX_N_SEQUENCES "
|
||||
"environment variable."
|
||||
)
|
||||
if not -2.0 <= self.presence_penalty <= 2.0:
|
||||
raise ValueError(
|
||||
f"presence_penalty must be in [-2, 2], got {self.presence_penalty}."
|
||||
|
||||
Reference in New Issue
Block a user