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.
Source code in vllm/v1/worker/gpu/sample/watermark.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | |
_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.
Source code in vllm/v1/worker/gpu/sample/watermark.py
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.
Source code in vllm/v1/worker/gpu/sample/watermark.py
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 | |
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.
Source code in vllm/v1/worker/gpu/sample/watermark.py
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.
Source code in vllm/v1/worker/gpu/sample/watermark.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |