[watermarking] Dual-key gumbel-max watermarking for speculative decoding support (#56122)

Signed-off-by: Raphael Rialland <raphael.rialland@mistral.ai>
Signed-off-by: Simon Veitner <sveitner@redhat.com>
Signed-off-by: Tomas Ruiz <tomas.ruiz.te@gmail.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Simon Veitner <sveitner@redhat.com>
Co-authored-by: Tomas Ruiz <tomas.ruiz.te@gmail.com>
This commit is contained in:
Raphaël Rialland
2026-09-12 18:42:01 +00:00
committed by GitHub
co-authored by OpenAI Codex Simon Veitner Tomas Ruiz
parent 1ee4be4dbc
commit 7ee8a6dd01
28 changed files with 3460 additions and 245 deletions
+62 -9
View File
@@ -50,7 +50,7 @@ from .reasoning import ReasoningConfig
from .scheduler import SchedulerConfig
from .speculative import EagleModelTypes, NgramGPUTypes, SpeculativeConfig
from .structured_outputs import StructuredOutputsConfig
from .utils import SupportsHash, config, replace
from .utils import SupportsHash, config, get_field, replace
from .watermarking import WatermarkConfig
from .weight_transfer import WeightTransferConfig
@@ -1142,14 +1142,67 @@ class VllmConfig:
watermark_config = getattr(self, "watermark_config", None)
if watermark_config is None:
return
if (
self.speculative_config is not None
and not watermark_config.supports_speculative_decoding
):
raise ValueError(
f"The {watermark_config.algorithm} watermarking algorithm "
"does not support speculative decoding."
)
if self.speculative_config is not None:
speculative_config = self.speculative_config
if speculative_config.draft_sample_method != "probabilistic":
raise ValueError(
"Speculative decoding with watermarking requires "
"draft_sample_method='probabilistic'."
)
if speculative_config.rejection_sample_method != "standard":
raise ValueError(
"Speculative decoding with watermarking requires "
"rejection_sample_method='standard'."
)
if (
speculative_config.parallel_drafting
and speculative_config.method != "dspark"
):
raise ValueError(
"Parallel speculative drafting is not supported with watermarking."
)
if speculative_config.method not in ("dspark", "eagle", "eagle3", "mtp"):
raise ValueError(
"Watermarking supports only autoregressive model-based "
"speculative decoding."
)
if (
not watermark_config.allow_target_only_watermarking
and not watermark_config.supports_speculative_decoding
):
raise ValueError(
f"The '{watermark_config.algorithm}' watermarking algorithm "
"does not support speculative decoding. Set "
"allow_target_only_watermarking=true to leave draft tokens "
"unwatermarked."
)
if (
watermark_config.allow_target_only_watermarking
and not watermark_config.supports_speculative_decoding
):
logger.warning_once(
"Target-only watermarking leaves accepted draft tokens "
"unwatermarked, weakening detectability in proportion to the "
"share of output tokens supplied by accepted drafts.",
scope="global",
)
if watermark_config.deduplicate_contexts != "none":
logger.warning_once(
"Context deduplication is not supported with speculative "
"decoding and will not be applied to accepted drafts, "
"rejection-recovery tokens, or bonus tokens.",
scope="global",
)
if watermark_config.algorithm == "dual_key_gumbel" and (
watermark_config.alpha != get_field(WatermarkConfig, "alpha").default
):
logger.warning_once(
"Speculative decoding selects the watermark key by token role: "
"draft tokens use key A, recovery and bonus tokens use key B. "
"The configured alpha=%s is not used.",
watermark_config.alpha,
scope="global",
)
if beam_search:
raise ValueError("Beam search is not supported with watermarking.")
if custom_sampler:
+49 -18
View File
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import hashlib
from typing import Literal
from pydantic import Field, model_validator
@@ -11,12 +12,16 @@ from vllm.logger import init_logger
logger = init_logger(__name__)
WatermarkingAlgorithm = Literal["gumbel"]
WatermarkingAlgorithm = Literal["gumbel", "dual_key_gumbel"]
WatermarkPRFName = Literal["philox"]
WatermarkContextScope = Literal["none", "single_turn", "all"]
_SPECULATIVE_DECODING_SUPPORT: dict[WatermarkingAlgorithm, bool] = {
"gumbel": False,
}
_MIN_RECOMMENDED_DEDUP_HISTORY = 1024
def derive_watermark_key(key: int, domain: bytes) -> int:
digest = hashlib.sha256(domain + key.to_bytes(8, "big")).digest()
return int.from_bytes(digest[:8], "big")
@config
@@ -27,23 +32,49 @@ class WatermarkConfig:
"""Secret key used to watermark generated text."""
algorithm: WatermarkingAlgorithm = "gumbel"
"""Algorithm used to watermark generated text."""
alpha: float = Field(default=0.1, ge=0, le=1)
"""Probability of selecting key B for dual-key watermarking."""
context_width: int = Field(default=4, ge=1)
"""Number of prior output tokens used by the watermark PRF."""
"""Number of prior tokens used by the watermark PRF."""
deduplicate_contexts: WatermarkContextScope = "single_turn"
"""Which history is searched for a repeated context before a token is
sampled; a repeated context is sampled without the watermark. `none`
disables the search. `single_turn` (default) searches this request's
generated tokens. `all` also searches the prompt and samples the first
`context_width` generated tokens without watermarking."""
deduplicate_contexts_max_history: int | None = Field(default=8192, ge=1)
"""Number of most recent history positions searched (default 8192), or
`None` for the whole scope. Each position is compared over the
`context_width` tokens before it. Ignored when `deduplicate_contexts` is
`none`."""
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
allow_target_only_watermarking: bool = False
"""Allow speculative decoding without watermarking draft tokens."""
@property
def supports_speculative_decoding(self) -> bool:
return _SPECULATIVE_DECODING_SUPPORT[self.algorithm]
return self.algorithm == "dual_key_gumbel"
@model_validator(mode="after")
def validate_watermark_settings(self) -> Self:
if self.key > 2**64 - 1:
raise ValueError("philox keys must fit in 64 bits")
history_is_too_short = (
self.deduplicate_contexts_max_history is not None
and self.deduplicate_contexts_max_history < _MIN_RECOMMENDED_DEDUP_HISTORY
)
if self.algorithm in ("gumbel", "dual_key_gumbel") and (
self.deduplicate_contexts == "none" or history_is_too_short
):
logger.warning_once(
"Gumbel-max watermarking with context deduplication "
"disabled or limited to fewer than "
f"{_MIN_RECOMMENDED_DEDUP_HISTORY} positions may increase the "
"frequency of degenerate generations, including repetition loops. "
"Use deduplicate_contexts='single_turn' or 'all' with "
"deduplicate_contexts_max_history at least "
f"{_MIN_RECOMMENDED_DEDUP_HISTORY} or null to mitigate this.",
scope="global",
)
return self