jmurray10 commited on
Commit
443a4d3
·
verified ·
1 Parent(s): 2cc8415

Serving compat: transformers-4.x config keys, inline chat template, ChatML eos

Browse files

The repo was saved by transformers 5.13.1, whose schema TGI / vLLM / the HF
inference toolkit do not read:
* config.json used `dtype` + nested `rope_parameters`; 4.x stacks look for
`torch_dtype` + top-level `rope_theta` and silently fell back to the
default rope_theta=10000.0 (should be 1e6) and fp32 loading. Both key
sets are now present, so 4.x and 5.x both load correctly.
* the chat template lived only in chat_template.jinja -> served with no
template at all. Now also inlined in tokenizer_config.json.
* `extra_special_tokens` (5.x list) replaced with `added_tokens_decoder` +
`additional_special_tokens`, plus a special_tokens_map.json.
* generation_config eos_token_id -> [151645, 151643] so a server halts on
<|im_end|> as well as <|endoftext|>.

Files changed (5) hide show
  1. README.md +45 -3
  2. config.json +5 -34
  3. generation_config.json +11 -2
  4. special_tokens_map.json +31 -0
  5. tokenizer_config.json +207 -30
README.md CHANGED
@@ -1,6 +1,8 @@
1
  ---
2
  license: apache-2.0
3
  base_model: Qwen/Qwen2.5-Coder-7B
 
 
4
  tags: [code, qwen2.5-coder, qlora]
5
  ---
6
 
@@ -12,9 +14,34 @@ Fine-tune of Qwen/Qwen2.5-Coder-7B (base): filtered OpenCodeInstruct SFT + scaff
12
  | MBPP+ pass@1 | 39.7% | 68.3% |
13
  | HumanEval+ pass@1 | 64.6% | 70.1% |
14
 
15
- ## IMPORTANT — use a stopping criterion
16
- This model writes correct code first, then keeps generating (trained without a
17
- reliable end-of-turn token). Stop at the end of the first code block:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ```python
20
  from transformers import StoppingCriteria, StoppingCriteriaList
@@ -27,3 +54,18 @@ class StopAfterCodeBlock(StoppingCriteria):
27
  # model.generate(**enc, max_new_tokens=1024,
28
  # stopping_criteria=StoppingCriteriaList([StopAfterCodeBlock(tok, enc.input_ids.shape[1])]))
29
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  base_model: Qwen/Qwen2.5-Coder-7B
4
+ library_name: transformers
5
+ pipeline_tag: text-generation
6
  tags: [code, qwen2.5-coder, qlora]
7
  ---
8
 
 
14
  | MBPP+ pass@1 | 39.7% | 68.3% |
15
  | HumanEval+ pass@1 | 64.6% | 70.1% |
16
 
17
+ ## IMPORTANT — this model does not reliably stop on its own
18
+ It writes correct code first, then keeps generating (trained without a reliable
19
+ end-of-turn token). **How you stop it depends on how you run it.**
20
+
21
+ ### Served behind an endpoint (TGI / vLLM / Inference Endpoints)
22
+ There is no `StoppingCriteria` hook over HTTP — you must pass stop sequences on
23
+ every request, and cap `max_tokens`:
24
+
25
+ ```python
26
+ from openai import OpenAI
27
+
28
+ client = OpenAI(base_url="https://<your-endpoint>.endpoints.huggingface.cloud/v1/", api_key="hf_...")
29
+
30
+ resp = client.chat.completions.create(
31
+ model="tgi", # vLLM: use the served model name
32
+ messages=[{"role": "user", "content": "Write a Python function that ..."}],
33
+ max_tokens=1024, # hard ceiling — it will use all of it otherwise
34
+ temperature=0.2,
35
+ stop=["\n```\n", "\n```", "<|im_end|>", "<|endoftext|>"],
36
+ )
37
+ ```
38
+
39
+ `eos_token_id` is `[151645, 151643]` (`<|im_end|>`, `<|endoftext|>`) so the server
40
+ halts on either if the model emits one — but do not rely on that alone, hence the
41
+ `stop` list above.
42
+
43
+ ### Local `transformers`
44
+ Stop at the end of the first code block:
45
 
46
  ```python
47
  from transformers import StoppingCriteria, StoppingCriteriaList
 
54
  # model.generate(**enc, max_new_tokens=1024,
55
  # stopping_criteria=StoppingCriteriaList([StopAfterCodeBlock(tok, enc.input_ids.shape[1])]))
56
  ```
57
+
58
+ ## Serving notes
59
+ - **Prompt format:** ChatML (`<|im_start|>role\n...<|im_end|>`). The chat template
60
+ ships both inline in `tokenizer_config.json` (for TGI / vLLM / the HF inference
61
+ toolkit) and as `chat_template.jinja` (for transformers 5.x).
62
+ - **Precision:** bf16, 15.2 GB of weights. Needs a >16 GB GPU (T4 is out). KV
63
+ cache is ~57 KB/token (28 layers × 4 KV heads × 128 dim × 2 × 2 bytes), i.e.
64
+ ~1.9 GB for a full 32k sequence — so L4 / A10G (24 GB) serves 32k at low
65
+ concurrency, and L40S (48 GB) gives room for real batching.
66
+ - **Context:** 32768 tokens, RoPE theta 1e6.
67
+ - The config carries **both** the transformers 4.x keys (`torch_dtype`,
68
+ top-level `rope_theta`) and the 5.x keys (`dtype`, `rope_parameters`), so it
69
+ loads correctly on either. Do not drop the 4.x keys — every current serving
70
+ stack reads those, and without `rope_theta` they silently fall back to 10000.0
71
+ (wrong RoPE base → degraded output).
config.json CHANGED
@@ -4,57 +4,28 @@
4
  ],
5
  "attention_dropout": 0.0,
6
  "bos_token_id": 151643,
7
- "dtype": "bfloat16",
8
  "eos_token_id": 151643,
9
  "hidden_act": "silu",
10
  "hidden_size": 3584,
11
  "initializer_range": 0.02,
12
  "intermediate_size": 18944,
13
- "layer_types": [
14
- "full_attention",
15
- "full_attention",
16
- "full_attention",
17
- "full_attention",
18
- "full_attention",
19
- "full_attention",
20
- "full_attention",
21
- "full_attention",
22
- "full_attention",
23
- "full_attention",
24
- "full_attention",
25
- "full_attention",
26
- "full_attention",
27
- "full_attention",
28
- "full_attention",
29
- "full_attention",
30
- "full_attention",
31
- "full_attention",
32
- "full_attention",
33
- "full_attention",
34
- "full_attention",
35
- "full_attention",
36
- "full_attention",
37
- "full_attention",
38
- "full_attention",
39
- "full_attention",
40
- "full_attention",
41
- "full_attention"
42
- ],
43
  "max_position_embeddings": 32768,
44
  "max_window_layers": 28,
45
  "model_type": "qwen2",
46
  "num_attention_heads": 28,
47
  "num_hidden_layers": 28,
48
  "num_key_value_heads": 4,
49
- "pad_token_id": null,
50
  "rms_norm_eps": 1e-06,
 
51
  "rope_parameters": {
52
  "rope_theta": 1000000.0,
53
  "rope_type": "default"
54
  },
55
- "sliding_window": null,
56
  "tie_word_embeddings": false,
57
- "transformers_version": "5.13.1",
 
 
58
  "use_cache": true,
59
  "use_sliding_window": false,
60
  "vocab_size": 152064
 
4
  ],
5
  "attention_dropout": 0.0,
6
  "bos_token_id": 151643,
 
7
  "eos_token_id": 151643,
8
  "hidden_act": "silu",
9
  "hidden_size": 3584,
10
  "initializer_range": 0.02,
11
  "intermediate_size": 18944,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  "max_position_embeddings": 32768,
13
  "max_window_layers": 28,
14
  "model_type": "qwen2",
15
  "num_attention_heads": 28,
16
  "num_hidden_layers": 28,
17
  "num_key_value_heads": 4,
 
18
  "rms_norm_eps": 1e-06,
19
+ "rope_theta": 1000000.0,
20
  "rope_parameters": {
21
  "rope_theta": 1000000.0,
22
  "rope_type": "default"
23
  },
24
+ "sliding_window": 131072,
25
  "tie_word_embeddings": false,
26
+ "torch_dtype": "bfloat16",
27
+ "dtype": "bfloat16",
28
+ "transformers_version": "4.45.0",
29
  "use_cache": true,
30
  "use_sliding_window": false,
31
  "vocab_size": 152064
generation_config.json CHANGED
@@ -1,6 +1,15 @@
1
  {
2
  "bos_token_id": 151643,
3
- "eos_token_id": 151643,
 
 
 
 
 
 
 
 
 
4
  "max_new_tokens": 2048,
5
- "transformers_version": "5.13.1"
6
  }
 
1
  {
2
  "bos_token_id": 151643,
3
+ "pad_token_id": 151643,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "do_sample": true,
9
+ "temperature": 0.2,
10
+ "top_p": 0.95,
11
+ "top_k": 20,
12
+ "repetition_penalty": 1.05,
13
  "max_new_tokens": 2048,
14
+ "transformers_version": "4.45.0"
15
  }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer_config.json CHANGED
@@ -1,30 +1,207 @@
1
- {
2
- "add_prefix_space": false,
3
- "backend": "tokenizers",
4
- "bos_token": null,
5
- "clean_up_tokenization_spaces": false,
6
- "eos_token": "<|endoftext|>",
7
- "errors": "replace",
8
- "extra_special_tokens": [
9
- "<|im_start|>",
10
- "<|im_end|>",
11
- "<|object_ref_start|>",
12
- "<|object_ref_end|>",
13
- "<|box_start|>",
14
- "<|box_end|>",
15
- "<|quad_start|>",
16
- "<|quad_end|>",
17
- "<|vision_start|>",
18
- "<|vision_end|>",
19
- "<|vision_pad|>",
20
- "<|image_pad|>",
21
- "<|video_pad|>"
22
- ],
23
- "is_local": false,
24
- "local_files_only": false,
25
- "model_max_length": 32768,
26
- "pad_token": "<|endoftext|>",
27
- "split_special_tokens": false,
28
- "tokenizer_class": "Qwen2Tokenizer",
29
- "unk_token": null
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "model_max_length": 32768,
203
+ "pad_token": "<|endoftext|>",
204
+ "split_special_tokens": false,
205
+ "tokenizer_class": "Qwen2Tokenizer",
206
+ "unk_token": null
207
+ }