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
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 922 923 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 | |
_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
_unmask_prompt_token(token, all_token_ids_row_ptr, position, prompt_len)
¶
Return the prompt token at position, or token outside the prompt.
Source code in vllm/v1/worker/gpu/sample/watermark.py
_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].
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
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 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | |
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
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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |