[Bugfix] Account for truncate_prompt_tokens when computing max_tokens (#41800)
Signed-off-by: Viktor Pus <viktorpus@tenstorrent.com>
This commit is contained in:
@@ -289,6 +289,7 @@ class OpenAIServingChat(OpenAIServing):
|
||||
self._extract_prompt_len(engine_input),
|
||||
self.default_sampling_params,
|
||||
self.override_max_tokens,
|
||||
truncate_prompt_tokens=request.truncate_prompt_tokens,
|
||||
)
|
||||
|
||||
sampling_params: SamplingParams | BeamSearchParams
|
||||
|
||||
@@ -151,6 +151,7 @@ class OpenAIServingCompletion(OpenAIServing):
|
||||
self._extract_prompt_len(engine_input),
|
||||
self.default_sampling_params,
|
||||
self.override_max_tokens,
|
||||
truncate_prompt_tokens=request.truncate_prompt_tokens,
|
||||
)
|
||||
|
||||
sampling_params: SamplingParams | BeamSearchParams
|
||||
|
||||
@@ -416,6 +416,9 @@ class OpenAIServingResponses(OpenAIServing):
|
||||
self._extract_prompt_len(engine_input),
|
||||
self.default_sampling_params,
|
||||
self.override_max_tokens,
|
||||
truncate_prompt_tokens=(
|
||||
-1 if request.truncation != "disabled" else None
|
||||
),
|
||||
)
|
||||
|
||||
sampling_params = request.to_sampling_params(
|
||||
@@ -700,6 +703,9 @@ class OpenAIServingResponses(OpenAIServing):
|
||||
self._extract_prompt_len(engine_input),
|
||||
self.default_sampling_params, # type: ignore
|
||||
self.override_max_tokens, # type: ignore
|
||||
truncate_prompt_tokens=(
|
||||
-1 if context.request.truncation != "disabled" else None
|
||||
),
|
||||
)
|
||||
|
||||
# OPTIMIZATION
|
||||
|
||||
@@ -164,6 +164,7 @@ class OpenAIServingRender:
|
||||
input_length,
|
||||
self.default_sampling_params,
|
||||
self.override_max_tokens,
|
||||
truncate_prompt_tokens=request.truncate_prompt_tokens,
|
||||
)
|
||||
params = request.to_sampling_params(max_tokens, self.default_sampling_params)
|
||||
|
||||
@@ -298,6 +299,7 @@ class OpenAIServingRender:
|
||||
input_length,
|
||||
self.default_sampling_params,
|
||||
self.override_max_tokens,
|
||||
truncate_prompt_tokens=request.truncate_prompt_tokens,
|
||||
)
|
||||
params = request.to_sampling_params(
|
||||
max_tokens, self.default_sampling_params
|
||||
|
||||
@@ -177,7 +177,14 @@ def get_max_tokens(
|
||||
input_length: int,
|
||||
default_sampling_params: dict,
|
||||
override_max_tokens: int | None = None,
|
||||
truncate_prompt_tokens: int | None = None,
|
||||
) -> int:
|
||||
if truncate_prompt_tokens is not None:
|
||||
limit = truncate_prompt_tokens
|
||||
input_length = min(
|
||||
input_length,
|
||||
max_model_len if limit == -1 else limit,
|
||||
)
|
||||
if max_model_len < input_length:
|
||||
raise ValueError(
|
||||
f"Input length ({input_length}) exceeds model's maximum "
|
||||
|
||||
Reference in New Issue
Block a user