KristianS7 commited on
Commit
8652748
·
verified ·
1 Parent(s): 85a074d

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()`.

Files changed (2) hide show
  1. config.json +3 -4
  2. tokenizer_config.json +4 -4
config.json CHANGED
@@ -8,8 +8,8 @@
8
  "AutoModel": "modeling_ouro.OuroModel",
9
  "AutoModelForCausalLM": "modeling_ouro.OuroForCausalLM"
10
  },
11
- "bos_token_id": 0,
12
- "eos_token_id": 0,
13
  "head_dim": 128,
14
  "hidden_act": "silu",
15
  "hidden_size": 2048,
@@ -83,5 +83,4 @@
83
  "use_cache": true,
84
  "use_sliding_window": false,
85
  "vocab_size": 49152
86
-
87
- }
 
8
  "AutoModel": "modeling_ouro.OuroModel",
9
  "AutoModelForCausalLM": "modeling_ouro.OuroForCausalLM"
10
  },
11
+ "bos_token_id": 1,
12
+ "eos_token_id": 2,
13
  "head_dim": 128,
14
  "hidden_act": "silu",
15
  "hidden_size": 2048,
 
83
  "use_cache": true,
84
  "use_sliding_window": false,
85
  "vocab_size": 49152
86
+ }
 
tokenizer_config.json CHANGED
@@ -157,13 +157,13 @@
157
  "<jupyter_script>",
158
  "<empty_output>"
159
  ],
160
- "bos_token": "<|endoftext|>",
161
  "clean_up_tokenization_spaces": false,
162
- "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 -%}",
163
- "eos_token": "<|endoftext|>",
164
  "extra_special_tokens": {},
165
  "model_max_length": 131072,
166
  "tokenizer_class": "GPT2Tokenizer",
167
  "unk_token": "<|endoftext|>",
168
  "vocab_size": 49152
169
- }
 
157
  "<jupyter_script>",
158
  "<empty_output>"
159
  ],
160
+ "bos_token": "<|im_start|>",
161
  "clean_up_tokenization_spaces": false,
162
+ "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 -%}",
163
+ "eos_token": "<|im_end|>",
164
  "extra_special_tokens": {},
165
  "model_max_length": 131072,
166
  "tokenizer_class": "GPT2Tokenizer",
167
  "unk_token": "<|endoftext|>",
168
  "vocab_size": 49152
169
+ }