From d054da1992175787f936d18aead51bef663a0399 Mon Sep 17 00:00:00 2001 From: CYJiang <86391540+googs1025@users.noreply.github.com> Date: Wed, 4 Jun 2025 02:02:07 +0800 Subject: [PATCH] [Misc] fix: add miss best_of param validation (#18555) Signed-off-by: googs1025 --- vllm/sampling_params.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vllm/sampling_params.py b/vllm/sampling_params.py index dc38daa388ced..4294465f68fcf 100644 --- a/vllm/sampling_params.py +++ b/vllm/sampling_params.py @@ -389,6 +389,17 @@ class SamplingParams( f"type {type(self.n)}") if self.n < 1: raise ValueError(f"n must be at least 1, got {self.n}.") + if self.best_of is not None: + if not isinstance(self.best_of, int): + raise ValueError( + f"best_of must be an integer, got {type(self.best_of)}") + if self.best_of < 1: + raise ValueError( + f"best_of must be at least 1, got {self.best_of}") + if self.best_of < self.n: + raise ValueError( + f"best_of must be greater than or equal to n, " + f"got n={self.n} and best_of={self.best_of}.") if not -2.0 <= self.presence_penalty <= 2.0: raise ValueError("presence_penalty must be in [-2, 2], got " f"{self.presence_penalty}.")