[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>
This commit is contained in:
Raphaël Rialland
2026-09-09 21:00:15 -07:00
committed by GitHub
co-authored by OpenAI Codex mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 8c34a37232
commit ea40bb9e90
32 changed files with 1693 additions and 15 deletions
+20 -1
View File
@@ -307,7 +307,26 @@ class Sampler:
or self.sampling_states.any_explicit_seed(idx_mapping_np)
)
# Sample the next token.
return self._sample_random(
processed_logits,
expanded_idx_mapping,
idx_mapping_np,
pos,
top_k,
top_p,
use_flashinfer,
)
def _sample_random(
self,
processed_logits: torch.Tensor,
expanded_idx_mapping: torch.Tensor,
idx_mapping_np: np.ndarray,
pos: torch.Tensor,
top_k: torch.Tensor | None,
top_p: torch.Tensor | None,
use_flashinfer: bool,
) -> tuple[torch.Tensor, torch.Tensor]:
if use_flashinfer:
sampled = flashinfer_sample(processed_logits, top_k, top_p).to(torch.int64)
else: