Fix bos/eos token IDs + add enable_thinking to chat template
Browse files## Summary
Fix token configuration and add `enable_thinking` support for the chat template.
### Token ID fixes
The current `bos_token` and `eos_token` are both set to `<|endoftext|>` (id=0), which is incorrect for a ChatML-style model. This PR fixes them to match the actual chat format:
| Field | Before | After |
|-------|--------|-------|
| `bos_token` | `<\|endoftext\|>` (0) | `<\|im_start\|>` (1) |
| `eos_token` | `<\|endoftext\|>` (0) | `<\|im_end\|>` (2) |
| `bos_token_id` | 0 | 1 |
| `eos_token_id` | 0 | 2 |
These are also set in `config.json`.
(Subsumes PRs #3, #4, #5)
### `enable_thinking` chat template support
The Ouro-Thinking model enters chain-of-thought reasoning mode when `<think>` is prepended to the assistant turn, but the current chat template does not support triggering this.
This PR adds `enable_thinking` parameter support (following the convention from Qwen3 and DeepSeek-R1), so that:
```python
tokenizer.apply_chat_template(messages, add_generation_prompt=True, enable_thinking=True)
# produces: ...<|im_start|>assistant\n<think>\n
```
**Backward compatible** — default behavior is unchanged (no `<think>` unless explicitly requested).
This also enables proper integration with `vLLM` and `lm-eval-harness`, which pass `enable_thinking=True` to `apply_chat_template()`.
- config.json +3 -3
- tokenizer_config.json +3 -3
|
@@ -8,8 +8,8 @@
|
|
| 8 |
"AutoModelForCausalLM": "modeling_ouro.OuroForCausalLM",
|
| 9 |
"AutoModel": "modeling_ouro.OuroModel"
|
| 10 |
},
|
| 11 |
-
"bos_token_id":
|
| 12 |
-
"eos_token_id":
|
| 13 |
"head_dim": 128,
|
| 14 |
"hidden_act": "silu",
|
| 15 |
"hidden_size": 2048,
|
|
@@ -59,4 +59,4 @@
|
|
| 59 |
"use_cache": true,
|
| 60 |
"use_sliding_window": false,
|
| 61 |
"vocab_size": 49152
|
| 62 |
-
}
|
|
|
|
| 8 |
"AutoModelForCausalLM": "modeling_ouro.OuroForCausalLM",
|
| 9 |
"AutoModel": "modeling_ouro.OuroModel"
|
| 10 |
},
|
| 11 |
+
"bos_token_id": 1,
|
| 12 |
+
"eos_token_id": 2,
|
| 13 |
"head_dim": 128,
|
| 14 |
"hidden_act": "silu",
|
| 15 |
"hidden_size": 2048,
|
|
|
|
| 59 |
"use_cache": true,
|
| 60 |
"use_sliding_window": false,
|
| 61 |
"vocab_size": 49152
|
| 62 |
+
}
|
|
@@ -157,8 +157,8 @@
|
|
| 157 |
"<jupyter_script>",
|
| 158 |
"<empty_output>"
|
| 159 |
],
|
| 160 |
-
"bos_token": "<|
|
| 161 |
-
"chat_template": "{%- if messages[0]['role'] == 'system' -%}{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}{%- else -%}{{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}{%- endif -%}{%- for message in messages -%}{%- if message.role == 'system' and loop.first -%}{# Skip #}{%- else -%}{{- '<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n' }}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\\n' }}{%- endif -%}",
|
| 162 |
"clean_up_tokenization_spaces": false,
|
| 163 |
"eos_token": "<|im_end|>",
|
| 164 |
"extra_special_tokens": {},
|
|
@@ -169,4 +169,4 @@
|
|
| 169 |
"tokenizer_class": "GPT2Tokenizer",
|
| 170 |
"unk_token": "<|endoftext|>",
|
| 171 |
"vocab_size": 49152
|
| 172 |
-
}
|
|
|
|
| 157 |
"<jupyter_script>",
|
| 158 |
"<empty_output>"
|
| 159 |
],
|
| 160 |
+
"bos_token": "<|im_start|>",
|
| 161 |
+
"chat_template": "{%- if messages[0]['role'] == 'system' -%}{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}{%- else -%}{{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}{%- endif -%}{%- for message in messages -%}{%- if message.role == 'system' and loop.first -%}{# Skip #}{%- else -%}{{- '<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n' }}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\\n' }}{%- if enable_thinking is defined and enable_thinking is true -%}{{- '<think>\\n' }}{%- endif -%}{%- endif -%}",
|
| 162 |
"clean_up_tokenization_spaces": false,
|
| 163 |
"eos_token": "<|im_end|>",
|
| 164 |
"extra_special_tokens": {},
|
|
|
|
| 169 |
"tokenizer_class": "GPT2Tokenizer",
|
| 170 |
"unk_token": "<|endoftext|>",
|
| 171 |
"vocab_size": 49152
|
| 172 |
+
}
|