Files
vLLM/vllm/v1/watermarking/prfs/base.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

20 lines
542 B
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from abc import ABC, abstractmethod
import torch
_UINT32_MASK = 2**32 - 1
class WatermarkPRF(ABC):
@abstractmethod
def uniform(self, contexts: torch.Tensor, token_ids: torch.Tensor) -> torch.Tensor:
raise NotImplementedError
def uint32_to_uniform(values: torch.Tensor) -> torch.Tensor:
mantissas = (values & _UINT32_MASK) >> 8
return ((mantissas.to(torch.float64) + 1.0) / (2**24 + 1)).to(torch.float32)