vllm.v1.worker.gpu.sample.watermark
¶
Functions:
-
draft_philox_gumbel_sample–Sample
num_stepsdraft steps flattened as (request, step), in step order. -
philox_gumbel_block_argmax–Apply the detector-compatible PRF to one vocabulary block.
-
repeated_context_mask–Return, per row, whether the row's context already occurred in its history.
_draft_step_kernel(sampled_ptr, sampled_stride, step, local_argmax_ptr, local_max_ptr, num_blocks, contexts_ptr, context_stride, skip_mask_ptr, next_req_indices_ptr, next_steps_ptr, temp_ptr, enabled_ptr, all_token_ids_ptr, all_token_ids_stride, prompt_lens_ptr, total_lens_ptr, prior_contexts_ptr, prior_contexts_stride_0, prior_contexts_stride_1, CONTEXT_WIDTH, NUM_SPECULATIVE_STEPS, MAX_HISTORY, INCLUDE_PROMPT, DEDUPLICATE, SAMPLE, PREPARE_NEXT, BLOCKS_POW2)
¶
Finish draft step step (if SAMPLE) and build the next step's skip mask.
_repeated_context_mask_cpu(all_token_ids, req_indices, prompt_lens, total_lens, contexts, max_history=None, include_prompt=False, skip_partial_context=False, history_offsets=None)
¶
Reference implementation; the parity tests check the Triton kernel against it.
_unmask_prompt_token(token, all_token_ids_row_ptr, position, prompt_len)
¶
Return the prompt token at position, or token outside the prompt.
_unmask_prompt_tokens_cpu(all_token_ids, req_indices, prompt_lens, total_lens, contexts, local_positions)
¶
Reference for _unmask_prompt_token on contexts at local_positions.
req_indices and local_positions have the shape of contexts[..., 0].
draft_philox_gumbel_sample(logits, contexts, key, *, num_steps, expanded_idx_mapping, temperatures, seeds, positions, enabled, logits_cache, logits_cache_col, use_fp64, prior_contexts, all_token_ids, prompt_lens, total_lens, deduplicate, max_history, include_prompt)
¶
Sample num_steps draft steps flattened as (request, step), in step order.
Bit-exact with sampling each step by DraftWatermarker.sample, but with two
kernel launches per step: the Philox block argmax (with the temperature
divide and the logits cache write), then a per-row kernel that picks the
token, shifts contexts and builds the next step's skip mask. Padding rows
(index -1) read temperature 0 and are never watermarked, so they may differ.
philox_gumbel_block_argmax(logits, mask, block_idx, contexts_row_ptr, key_0, key_1, CONTEXT_WIDTH, BLOCK_SIZE)
¶
Apply the detector-compatible PRF to one vocabulary block.
repeated_context_mask(all_token_ids, req_indices, prompt_lens, total_lens, contexts, max_history=None, include_prompt=False, skip_partial_context=False, history_offsets=None, local_positions=None, num_speculative_steps=0)
¶
Return, per row, whether the row's context already occurred in its history.
Parameters:
-
(all_token_ids¶Tensor) –[max_num_reqs, max_model_len]token ids of every request. -
(req_indices¶Tensor) –Request slot per sampled row; -1 marks a padding row, which is reported as not repeated.
-
(prompt_lens¶Tensor) –Prompt length per request slot.
-
(total_lens¶Tensor) –Prompt plus generated length per request slot.
-
(contexts¶Tensor) –[num_rows, context_width]context per row, padded with -1 before the start of the scanned history. -
(max_history¶int | None, default:None) –Number of most recent history positions searched, or
Nonefor all of them. The window compared at each position reachescontext_widthtokens further back. -
(include_prompt¶bool, default:False) –Search the prompt as well as the generated tokens.
-
(skip_partial_context¶bool, default:False) –Mark contexts containing start padding so they use ordinary sampling.
-
(history_offsets¶Tensor | None, default:None) –Number of newer, non-committed positions preceding each context. These positions count toward
max_history. Must be 1-D over rows; a stride-0 broadcast row is fine. -
(local_positions¶Tensor | None, default:None) –Position within each request's speculative block. When provided, compare each context with earlier contexts in that block.
-
(num_speculative_steps¶int, default:0) –Maximum number of draft tokens in the block.