|
15 | 15 | end_token = "</think>"
|
16 | 16 |
|
17 | 17 | SIMPLE_REASONING = {
|
18 |
| - "output": "<think>This is a reasoning section</think>This is the rest", |
| 18 | + "output": "This is a reasoning section</think>This is the rest", |
19 | 19 | "reasoning_content": "This is a reasoning section",
|
20 | 20 | "content": "This is the rest",
|
21 | 21 | }
|
22 | 22 | COMPLETE_REASONING = {
|
23 |
| - "output": "<think>This is a reasoning section</think>", |
| 23 | + "output": "This is a reasoning section</think>", |
24 | 24 | "reasoning_content": "This is a reasoning section",
|
25 | 25 | "content": None,
|
26 | 26 | }
|
27 | 27 | NO_REASONING = {
|
28 |
| - "output": "This is a reasoning section", |
| 28 | + "output": "This is content", |
29 | 29 | "reasoning_content": None,
|
30 |
| - "content": "This is a reasoning section", |
| 30 | + "content": "This is content", |
| 31 | +} |
| 32 | +NO_REASONING_STREAMING = { |
| 33 | + "output": "This is a reasoning section", |
| 34 | + "reasoning_content": "This is a reasoning section", |
| 35 | + "content": None, |
31 | 36 | }
|
32 | 37 | MULTIPLE_LINES = {
|
33 |
| - "output": "<think>This\nThat</think>This is the rest\nThat", |
| 38 | + "output": "This\nThat</think>This is the rest\nThat", |
34 | 39 | "reasoning_content": "This\nThat",
|
35 | 40 | "content": "This is the rest\nThat",
|
36 | 41 | }
|
37 | 42 | SHORTEST_REASONING_NO_STREAMING = {
|
38 |
| - "output": "<think></think>This is the rest", |
| 43 | + "output": "</think>This is the rest", |
39 | 44 | "reasoning_content": "",
|
40 | 45 | "content": "This is the rest",
|
41 | 46 | }
|
42 | 47 | SHORTEST_REASONING = {
|
43 |
| - "output": "<think></think>This is the rest", |
| 48 | + "output": "</think>This is the rest", |
| 49 | + "reasoning_content": None, |
| 50 | + "content": "This is the rest", |
| 51 | +} |
| 52 | +REASONING_WITH_THINK = { |
| 53 | + "output": "<think>This is a reasoning section</think>This is the rest", |
| 54 | + "reasoning_content": "This is a reasoning section", |
| 55 | + "content": "This is the rest", |
| 56 | +} |
| 57 | +COMPLETE_REASONING_WITH_THINK = { |
| 58 | + "output": "<think>This is a reasoning section</think>", |
| 59 | + "reasoning_content": "This is a reasoning section", |
| 60 | + "content": None, |
| 61 | +} |
| 62 | +MULTIPLE_LINES_WITH_THINK = { |
| 63 | + "output": "<think>This\nThat</think>This is the rest\nThat", |
| 64 | + "reasoning_content": "This\nThat", |
| 65 | + "content": "This is the rest\nThat", |
| 66 | +} |
| 67 | +SHORTEST_REASONING_NO_STREAMING_WITH_THINK = { |
| 68 | + "output": "</think>This is the rest", |
| 69 | + "reasoning_content": "", |
| 70 | + "content": "This is the rest", |
| 71 | +} |
| 72 | +SHORTEST_REASONING_WITH_THINK = { |
| 73 | + "output": "</think>This is the rest", |
44 | 74 | "reasoning_content": None,
|
45 | 75 | "content": "This is the rest",
|
46 | 76 | }
|
|
49 | 79 | pytest.param(
|
50 | 80 | False,
|
51 | 81 | SIMPLE_REASONING,
|
52 |
| - id="simple_streaming", |
| 82 | + id="simple_reasoning", |
53 | 83 | ),
|
54 | 84 | pytest.param(
|
55 | 85 | True,
|
56 | 86 | SIMPLE_REASONING,
|
57 |
| - id="simple_streaming", |
| 87 | + id="simple_reasoning_streaming", |
58 | 88 | ),
|
59 | 89 | pytest.param(
|
60 | 90 | False,
|
61 | 91 | COMPLETE_REASONING,
|
62 |
| - id="complete_streaming", |
| 92 | + id="complete_reasoning", |
63 | 93 | ),
|
64 | 94 | pytest.param(
|
65 | 95 | True,
|
66 | 96 | COMPLETE_REASONING,
|
67 |
| - id="complete_streaming", |
| 97 | + id="complete_reasoning_streaming", |
68 | 98 | ),
|
69 | 99 | pytest.param(
|
70 | 100 | False,
|
71 | 101 | NO_REASONING,
|
72 |
| - id="no_streaming", |
| 102 | + id="no_reasoning_token", |
73 | 103 | ),
|
74 | 104 | pytest.param(
|
75 | 105 | True,
|
76 |
| - NO_REASONING, |
77 |
| - id="no_streaming", |
| 106 | + NO_REASONING_STREAMING, |
| 107 | + id="no_reasoning_token_streaming", |
78 | 108 | ),
|
79 | 109 | pytest.param(
|
80 | 110 | False,
|
81 | 111 | MULTIPLE_LINES,
|
82 |
| - id="multiple_lines_streaming", |
| 112 | + id="multiple_lines", |
83 | 113 | ),
|
84 | 114 | pytest.param(
|
85 | 115 | True,
|
|
89 | 119 | pytest.param(
|
90 | 120 | True,
|
91 | 121 | SHORTEST_REASONING,
|
92 |
| - id="shortest_streaming", |
| 122 | + id="shortest", |
93 | 123 | ),
|
94 | 124 | pytest.param(
|
95 | 125 | False,
|
96 | 126 | SHORTEST_REASONING_NO_STREAMING,
|
97 | 127 | id="shortest_streaming",
|
98 | 128 | ),
|
| 129 | + pytest.param( |
| 130 | + False, |
| 131 | + REASONING_WITH_THINK, |
| 132 | + id="reasoning_with_think", |
| 133 | + ), |
| 134 | + pytest.param( |
| 135 | + True, |
| 136 | + REASONING_WITH_THINK, |
| 137 | + id="reasoning_with_think_streaming", |
| 138 | + ), |
| 139 | + pytest.param( |
| 140 | + False, |
| 141 | + COMPLETE_REASONING_WITH_THINK, |
| 142 | + id="complete_reasoning_with_think", |
| 143 | + ), |
| 144 | + pytest.param( |
| 145 | + True, |
| 146 | + COMPLETE_REASONING_WITH_THINK, |
| 147 | + id="complete_reasoning_with_think_streaming", |
| 148 | + ), |
| 149 | + pytest.param( |
| 150 | + False, |
| 151 | + MULTIPLE_LINES_WITH_THINK, |
| 152 | + id="multiple_lines_with_think", |
| 153 | + ), |
| 154 | + pytest.param( |
| 155 | + True, |
| 156 | + MULTIPLE_LINES_WITH_THINK, |
| 157 | + id="multiple_lines_with_think_streaming", |
| 158 | + ), |
| 159 | + pytest.param( |
| 160 | + False, |
| 161 | + SHORTEST_REASONING_NO_STREAMING_WITH_THINK, |
| 162 | + id="shortest_with_think", |
| 163 | + ), |
| 164 | + pytest.param( |
| 165 | + True, |
| 166 | + SHORTEST_REASONING_WITH_THINK, |
| 167 | + id="shortest_with_think_streaming", |
| 168 | + ), |
99 | 169 | ]
|
100 | 170 |
|
| 171 | +# Global tokenizer initialization to avoid repeated loading |
| 172 | +tokenizer = AutoTokenizer.from_pretrained("facebook/opt-125m") |
| 173 | +tokenizer.add_tokens([start_token, end_token]) |
| 174 | + |
101 | 175 |
|
102 | 176 | @pytest.mark.parametrize("streaming, param_dict", TEST_CASES)
|
103 | 177 | def test_reasoning(
|
104 | 178 | streaming: bool,
|
105 | 179 | param_dict: dict,
|
106 | 180 | ):
|
107 |
| - tokenizer = AutoTokenizer.from_pretrained("facebook/opt-125m") |
108 |
| - tokenizer.add_tokens([start_token, end_token]) |
109 | 181 | output = tokenizer.tokenize(param_dict["output"])
|
110 | 182 | # decode everything to tokens
|
111 | 183 | output_tokens: List[str] = [
|
|
0 commit comments