[watermark] compatibility validation (#56801)

Signed-off-by: Raphael Rialland <raphael.rialland@mistral.ai>
Signed-off-by: Simon Veitner <sveitner@redhat.com>
Co-authored-by: Simon Veitner <sveitner@redhat.com>
This commit is contained in:
Raphaël Rialland
2026-10-05 14:37:13 -04:00
committed by GitHub
co-authored by Simon Veitner
parent 88f3c601b3
commit c32495d58f
45 changed files with 1670 additions and 101 deletions
+42 -4
View File
@@ -25,7 +25,7 @@ from vllm.platforms import current_platform
from vllm.pooling_params import PoolingParams
from vllm.renderers import BaseRenderer, renderer_from_config
from vllm.renderers.inputs.preprocess import parse_model_prompt
from vllm.sampling_params import SamplingParams
from vllm.sampling_params import BeamSearchParams, SamplingParams
from vllm.tasks import GENERATION_TASKS, POOLING_TASKS, SupportedTask
from vllm.tokenizers import TokenizerLike
from vllm.utils import length_from_prompt_token_ids_or_embeds, random_uuid
@@ -112,12 +112,41 @@ class InputProcessor:
return partial(validate_logits_processors_parameters, custom_logitsprocs)
def resolve_watermarking(self, params: SamplingParams | BeamSearchParams) -> bool:
"""Return whether watermarking will be applied to this request.
``None`` and ``True`` request watermarking, while ``False`` opts out.
If watermarking is unavailable or incompatible with the request, emit
a warning and return ``False``.
"""
return self.vllm_config._check_supports_watermarking(params)
def apply_watermarking(self, params: SamplingParams, watermarking: bool) -> None:
"""Store the resolved `watermarking` on request-local params.
Also records whether watermarking was requested on a watermarking
engine but could not be applied, as opposed to an explicit opt-out.
"""
# Sticky, so resolving an already resolved request keeps the flag.
params._watermarking_skipped = params._watermarking_skipped or (
self.vllm_config.watermark_config is not None
and params.watermarking is not False
and not watermarking
)
params.watermarking = watermarking
def _validate_params(
self,
params: SamplingParams | PoolingParams,
supported_tasks: tuple[SupportedTask, ...],
) -> None:
"""Raise `ValueError` if SamplingParams or PoolingParams is not valid."""
) -> bool | None:
"""Raise `ValueError` if SamplingParams or PoolingParams is not valid.
Returns the resolved `watermarking` value for `SamplingParams` (`None`
for `PoolingParams`). The caller applies it to its private copy of the
params so that a caller-owned params object is never mutated.
"""
watermarking: bool | None = None
if isinstance(params, SamplingParams):
supported_generation_tasks = [
task for task in supported_tasks if task in GENERATION_TASKS
@@ -189,6 +218,9 @@ class InputProcessor:
"enabled. Start the engine with --enable-trace-replay "
"to use it."
)
# Resolved last so that feature gates above report the missing
# feature rather than its incompatibility with watermarking.
watermarking = self.resolve_watermarking(params)
elif isinstance(params, PoolingParams):
supported_pooling_tasks = [
task for task in supported_tasks if task in POOLING_TASKS
@@ -217,6 +249,8 @@ class InputProcessor:
f"but got {type(params).__name__}"
)
return watermarking
def _normalize_trace_replay_params(
self, sampling_params: SamplingParams, prompt_len: int
) -> None:
@@ -352,7 +386,7 @@ class InputProcessor:
session_id: str | None = None,
kv_hints: KvHintsEnvelope | None = None,
) -> EngineCoreRequest:
self._validate_params(params, supported_tasks)
watermarking = self._validate_params(params, supported_tasks)
self._validate_lora(lora_request)
parallel_config = self.vllm_config.parallel_config
@@ -413,6 +447,10 @@ class InputProcessor:
if isinstance(params, SamplingParams):
# TODO: can we avoid cloning here in multiproc case?
sampling_params = params.clone()
# Resolve on the request-local copy: `params` may be shared across
# prompts, requests and even engines by the caller.
assert watermarking is not None
self.apply_watermarking(sampling_params, watermarking)
prompt_len = length_from_prompt_token_ids_or_embeds(
prompt_token_ids, prompt_embeds
)