Files
vLLM/vllm/config/watermarking.py
T
Raphaël RiallandOpenAI Codexmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ea40bb9e90 [feature] Watermarked generation and detection (Gumbel-max algorithm) (#54053)
Signed-off-by: Raphael Rialland <raphael.rialland@mistral.ai>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2026-09-09 21:00:15 -07:00

50 lines
1.6 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Literal
from pydantic import Field, model_validator
from typing_extensions import Self
from vllm.config.utils import config
from vllm.logger import init_logger
logger = init_logger(__name__)
WatermarkingAlgorithm = Literal["gumbel"]
WatermarkPRFName = Literal["philox"]
_SPECULATIVE_DECODING_SUPPORT: dict[WatermarkingAlgorithm, bool] = {
"gumbel": False,
}
@config
class WatermarkConfig:
"""Configuration for text watermark generation."""
key: int = Field(ge=0, repr=False, exclude=True)
"""Secret key used to watermark generated text."""
algorithm: WatermarkingAlgorithm = "gumbel"
"""Algorithm used to watermark generated text."""
context_width: int = Field(default=4, ge=1)
"""Number of prior output tokens used by the watermark PRF."""
prf: WatermarkPRFName = "philox"
"""Pseudorandom function used by the watermarking algorithm."""
@model_validator(mode="after")
def validate_key(self) -> Self:
if self.key > 2**64 - 1:
raise ValueError("philox keys must fit in 64 bits")
if self.algorithm == "gumbel":
logger.warning_once(
"Single-key Gumbel-max watermarking may increase the frequency of "
"degenerate generations, including repetition loops.",
scope="global",
)
return self
@property
def supports_speculative_decoding(self) -> bool:
return _SPECULATIVE_DECODING_SUPPORT[self.algorithm]