@@ -69,6 +69,9 @@ def encode(self, text: str, add_special_tokens: bool = False) -> list[int]:
6969 assert add_special_tokens is False
7070 marker_ids = {
7171 "<|assistant|>" : [ASSISTANT_START ],
72+ "<|system|>" : [40 ],
73+ "<|user|>" : [USER_START ],
74+ "<|observation|>" : [TOOL_RESULT ],
7275 '<|open|>message role="assistant"<|sep|>' : [ASSISTANT_START ],
7376 "<|close|>message<|sep|><|end_of_msg|>" : [TURN_END ],
7477 "]~b]ai\n " : [ASSISTANT_START ],
@@ -268,6 +271,29 @@ def test_model_chat_four_way_rendering_and_loss_boundaries(model: str, tools: bo
268271 assert all ("enable_thinking" not in entry for entry in semantic_kwargs )
269272
270273
274+ def test_glm_history_thinking_truncation_preserves_historical_answer_loss () -> None :
275+ tokenizer = _ModelChatTokenizer ("glm" )
276+ example = {
277+ "messages" : _messages (tools = False , thinking = True ),
278+ "chat_template_kwargs" : {
279+ "enable_thinking" : True ,
280+ "truncate_history_thinking" : True ,
281+ },
282+ }
283+
284+ tokenized = tokenize_chat_example (example , tokenizer , warn_on_all_masked = False )
285+
286+ assert tokenized .input_ids [tokenized .assistant_mask ].tolist () == [
287+ THINK_OPEN ,
288+ THINK_CLOSE ,
289+ TEXT_IDS ["answer one" ],
290+ THINK_OPEN ,
291+ TEXT_IDS ["reason two" ],
292+ THINK_CLOSE ,
293+ TEXT_IDS ["answer two" ],
294+ ]
295+
296+
271297@pytest .mark .parametrize ("model" , ["glm" , "kimi" , "minimax" ])
272298def test_model_chat_right_truncation_and_padding_preserve_loss_alignment (model : str ) -> None :
273299 tokenizer = _ModelChatTokenizer (model )
0 commit comments