main
py 91 lines 1.38 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 from vllm.v1.watermarking import GumbelWatermarkDetector
5
6 _NON_WATERMARKED_TOKEN_IDS = list(range(64))
7 _WATERMARKED_TOKEN_IDS = [
8 85,
9 56,
10 123,
11 77,
12 105,
13 62,
14 9,
15 104,
16 16,
17 98,
18 123,
19 22,
20 16,
21 35,
22 47,
23 127,
24 77,
25 67,
26 19,
27 2,
28 10,
29 8,
30 75,
31 22,
32 127,
33 30,
34 95,
35 9,
36 101,
37 14,
38 113,
39 122,
40 85,
41 66,
42 122,
43 50,
44 38,
45 119,
46 15,
47 58,
48 68,
49 62,
50 24,
51 126,
52 80,
53 126,
54 68,
55 83,
56 81,
57 126,
58 62,
59 31,
60 18,
61 81,
62 64,
63 47,
64 22,
65 70,
66 47,
67 109,
68 54,
69 21,
70 65,
71 38,
72 ]
73
74
75 def test_detection_on_known_sequence():
76 detector = GumbelWatermarkDetector(key=42, context_width=4, prf="philox")
77
78 assert detector.detect(_WATERMARKED_TOKEN_IDS).is_watermarked
79 assert not detector.detect(_NON_WATERMARKED_TOKEN_IDS).is_watermarked
80
81
82 def test_detector_handles_empty_input():
83 detector = GumbelWatermarkDetector(key=42, context_width=4, prf="philox")
84 contexts, targets = detector._prepare_inputs([])
85 detection = detector.detect([])
86
87 assert contexts.shape == (0, 4)
88 assert targets.shape == (0,)
89 assert detection.score == 0
90 assert detection.p_value == 1
91 assert not detection.is_watermarked