zhou94539 commited on
Commit
140df16
·
verified ·
1 Parent(s): b09d727

Initialize private staging repo

Browse files
Files changed (1) hide show
  1. README.md +468 -0
README.md ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ pipeline_tag: text-generation
6
+ library_name: transformers
7
+ tags:
8
+ - xllm
9
+ - k2-horizon
10
+ - causal-lm
11
+ - reasoning
12
+ - knowledge-distillation
13
+ - vllm
14
+ - reinforcement-learning
15
+ license: other
16
+ license_name: internal-only
17
+ license_link: LICENSE
18
+ model-index:
19
+ - name: K2-Horizon-0.9B
20
+ results:
21
+ - task:
22
+ type: text-generation
23
+ name: Math Reasoning
24
+ dataset:
25
+ name: AIME 2026
26
+ type: aime26
27
+ metrics:
28
+ - type: accuracy
29
+ name: avg@16
30
+ value: 0.485
31
+ - task:
32
+ type: text-generation
33
+ name: Math Reasoning
34
+ dataset:
35
+ name: AIME 2025
36
+ type: aime25
37
+ metrics:
38
+ - type: accuracy
39
+ name: avg@16
40
+ value: 0.390
41
+ - task:
42
+ type: text-generation
43
+ name: Code Generation
44
+ dataset:
45
+ name: HumanEval+
46
+ type: humaneval_plus
47
+ metrics:
48
+ - type: pass@1
49
+ value: 0.799
50
+ - task:
51
+ type: text-generation
52
+ name: Code Generation
53
+ dataset:
54
+ name: MBPP+
55
+ type: mbpp_plus
56
+ metrics:
57
+ - type: pass@1
58
+ value: 0.680
59
+ - task:
60
+ type: text-generation
61
+ name: Code Generation
62
+ dataset:
63
+ name: LiveCodeBench v6
64
+ type: livecodebench_v6
65
+ metrics:
66
+ - type: pass@1
67
+ value: 0.357
68
+ - task:
69
+ type: text-generation
70
+ name: General Knowledge / Reasoning
71
+ dataset:
72
+ name: GPQA-Diamond
73
+ type: gpqa_diamond
74
+ metrics:
75
+ - type: accuracy
76
+ name: avg@16
77
+ value: 0.273
78
+ - task:
79
+ type: text-generation
80
+ name: General Knowledge / Reasoning
81
+ dataset:
82
+ name: MMLU-Pro
83
+ type: mmlu_pro
84
+ metrics:
85
+ - type: accuracy
86
+ value: 0.455
87
+ - task:
88
+ type: text-generation
89
+ name: General Knowledge / Reasoning
90
+ dataset:
91
+ name: BBH
92
+ type: bbh
93
+ metrics:
94
+ - type: accuracy
95
+ name: zero-shot CoT
96
+ value: 0.660
97
+ - task:
98
+ type: text-generation
99
+ name: Tool Use
100
+ dataset:
101
+ name: BFCL v4
102
+ type: bfcl_v4
103
+ metrics:
104
+ - type: accuracy
105
+ name: overall
106
+ value: 0.280
107
+ - task:
108
+ type: text-generation
109
+ name: Instruction Following
110
+ dataset:
111
+ name: IFEval
112
+ type: ifeval
113
+ metrics:
114
+ - type: accuracy
115
+ name: strict-instruction
116
+ value: 0.808
117
+ - task:
118
+ type: text-generation
119
+ name: Math Reasoning
120
+ dataset:
121
+ name: HMMT February 2026
122
+ type: hmmt_feb_2026
123
+ metrics:
124
+ - type: accuracy
125
+ name: avg@16
126
+ value: 0.258
127
+ ---
128
+
129
+ # K2-Horizon-0.9B
130
+
131
+ K2-Horizon-0.9B is a compact, 0.9-billion-parameter reasoning model designed
132
+ to combine mathematics, code generation, instruction following, and STEM
133
+ knowledge in one checkpoint. It was produced with multi-teacher on-policy
134
+ distillation (mOPD), starting from a merge of specialist models and then
135
+ learning from three domain teachers under a shared objective.
136
+
137
+ ## Model Details
138
+
139
+ | Property | Value |
140
+ |---|---|
141
+ | **Architecture** | `K2HorizonForCausalLM` (`model_type: k2_horizon`) |
142
+ | **Parameters** | 1,078,285,824 (released as 0.9B; counted from the safetensors tensors) |
143
+ | **Hidden size / layers** | 1,536 / 28 |
144
+ | **Attention heads / KV heads** | 32 / 8 |
145
+ | **Context length** | 131,072 tokens with YaRN RoPE scaling; original context length 8,192 tokens |
146
+ | **Vocabulary size** | 64,256 |
147
+ | **Released weight dtype** | BF16 |
148
+ | **Format** | Hugging Face safetensors, one weight shard, with custom configuration and modeling code in the repository root |
149
+ | **Distillation checkpoint** | Step 249 of a 500-step mOPD run |
150
+
151
+ The `main` revision publishes `K2HorizonForCausalLM`,
152
+ `model_type: k2_horizon`, and matching `configuration_k2_horizon.py` and
153
+ `modeling_k2_horizon.py` modules. The Transformers and vLLM preflights below
154
+ validate that public contract before loading weights.
155
+
156
+ ### Training Lineage
157
+
158
+ Training examples were routed to a math-and-code teacher, a STEM teacher, or
159
+ an instruction-following teacher through the example's `opd_domain` metadata.
160
+ The math-and-code teacher was used as the fallback when no recognized domain
161
+ was present.
162
+
163
+ | Domain | Teacher checkpoint step |
164
+ |---|---:|
165
+ | Math and code | 2,739 |
166
+ | STEM | 499 |
167
+ | Instruction following | 1,499 |
168
+
169
+ The base context window was extended in stages from 8,192 to 40,960 and then
170
+ to 131,072 tokens. The `mid1_75k` and `mid2_47k` repository revisions preserve
171
+ the corresponding intermediate checkpoints. The distilled release checkpoint
172
+ is on `main`; all stages use a vocabulary of 64,256 tokens.
173
+
174
+ ## Model Description
175
+
176
+ K2-Horizon-0.9B begins with a task-arithmetic merge of three specialist
177
+ checkpoints. mOPD then trains that merged student against math-and-code, STEM,
178
+ and instruction-following teachers at the same time. The training objective
179
+ combines an on-policy distillation loss with a reference-model KL term so the
180
+ student can learn specialist behavior while remaining close to the merged base
181
+ model.
182
+
183
+ The resulting checkpoint retains most of the specialist teachers' performance
184
+ on the reported math and coding tasks. It also improves every reported IFEval
185
+ submetric over the pre-distillation merge. This makes the model useful for
186
+ research on compact reasoning models, local inference, distillation, and
187
+ task-specific adaptation.
188
+
189
+ ## Model Card Comparison Table
190
+
191
+ | Benchmark | **K2-Horizon-0.9B** | MiniCPM5-1B | Qwen3.5-0.8B | Qwen3.5-2B |
192
+ |---|---:|---:|---:|---:|
193
+ | IFEval (strict instruction) | **80.8†** | 80.41‡ | 44.0‡ | 78.6‡ |
194
+ | GPQA-Diamond (avg@16) | **27.3†** | 26.26‡ | 11.9‡ | 51.6‡ |
195
+ | HMMT February 2026 (avg@16) | **25.8†** | 23.3† | 0.57‡ | 18.56† |
196
+ | AIME 2025 (avg@16) | **41.7†** | 40.42‡ | 1.04‡ | 26.46† |
197
+ | AIME 2026 (avg@16) | **48.5†** | 40.42‡ | 0.21‡ | 25.42† |
198
+ | HumanEval+ (pass@1) | **79.9†** | 65.2† | 26.22† | 42.68† |
199
+ | MBPP+ (pass@1) | **68.0†** | 60.6† | 32.8† | 47.09† |
200
+ | LiveCodeBench v6 (avg@3) | **37.41†** | 33.52‡ | 5.33‡ | 13.08† |
201
+
202
+ - **† Local result.**
203
+ - **‡ Published comparison/model-card value; protocol is not necessarily matched.**
204
+
205
+ ## How to Use
206
+
207
+ K2-Horizon-0.9B emits a reasoning segment before its final answer when the
208
+ chat template is used. The template supports `reasoning_effort` values `high`,
209
+ `medium`, and `low`, which select the model's full, fast, and faster reasoning
210
+ modes respectively.
211
+
212
+ For a deterministic runtime check, use `temperature=0` and generate 20 to 50
213
+ tokens. For general sampled generation, `temperature=0.6` and `top_p=0.95`
214
+ reproduce the GPQA evaluation setting and are reasonable starting points.
215
+ IFBench used `temperature=0.8`. Long math and coding tasks may require several
216
+ thousand output tokens; choose limits from application measurements rather
217
+ than treating an evaluation limit as a universal default.
218
+
219
+ ### Option A - vLLM (recommended, native architecture support)
220
+
221
+ The validated serving image was reconstructed into the following manual
222
+ runtime contract:
223
+
224
+ | Component | Validated value |
225
+ |---|---|
226
+ | Operating system | Ubuntu 24.04, Linux x86-64 |
227
+ | Python | 3.12.13 |
228
+ | CUDA toolkit | 12.9 |
229
+ | PyTorch | 2.13.0+cu129 |
230
+ | Transformers | 5.16.1 |
231
+ | Safetensors | 0.8.0 |
232
+ | FlashInfer | 0.6.17 |
233
+ | Attention backend | vLLM FlashAttention 3; Triton 3.7.1 |
234
+ | vLLM | `0.26.1rc1.dev1212`, [PR #53806](https://github.com/vllm-project/vllm/pull/53806) source commit [`d9fd5f11`](https://github.com/vllm-project/vllm/commit/d9fd5f11423a1a5628fe29e7296ceb9de91aac3c) |
235
+
236
+ That source revision contains the native `K2HorizonForCausalLM` implementation
237
+ and the built-in `k2_horizon` reasoning and tool parsers. Other vLLM revisions
238
+ have not been validated for this checkpoint. Pin the exact commit until the
239
+ integration is available in an upstream release.
240
+
241
+ Use Linux x86-64 with a CUDA 12.9-compatible NVIDIA driver and Git. The setup
242
+ uses vLLM's precompiled extension path while keeping the Python package on the
243
+ exact reviewed source commit.
244
+
245
+ <details>
246
+ <summary>Show the pinned vLLM environment setup</summary>
247
+
248
+ ```bash
249
+ git clone --filter=blob:none --no-checkout \
250
+ https://github.com/vllm-project/vllm.git
251
+ cd vllm
252
+ git fetch origin pull/53806/head:refs/remotes/origin/pr-53806
253
+ git checkout --detach d9fd5f11423a1a5628fe29e7296ceb9de91aac3c
254
+ test "$(git rev-parse HEAD)" = \
255
+ "d9fd5f11423a1a5628fe29e7296ceb9de91aac3c"
256
+
257
+ python3.12 -m venv .venv
258
+ source .venv/bin/activate
259
+ python -m pip install --upgrade pip uv
260
+ export UV_LINK_MODE=copy
261
+ VLLM_USE_PRECOMPILED=1 uv pip install --upgrade --editable . \
262
+ --torch-backend=auto
263
+ uv pip install "transformers==5.16.1" "safetensors==0.8.0"
264
+ python -m pip check
265
+
266
+ python - <<'PY'
267
+ from vllm import ModelRegistry
268
+ from vllm.reasoning import ReasoningParserManager
269
+ from vllm.tool_parsers import ToolParserManager
270
+
271
+ assert "K2HorizonForCausalLM" in ModelRegistry.get_supported_archs()
272
+ assert ReasoningParserManager.get_reasoning_parser("k2_horizon") is not None
273
+ assert ToolParserManager.get_tool_parser("k2_horizon") is not None
274
+ PY
275
+ ```
276
+
277
+ </details>
278
+
279
+ Download the repository chat template explicitly and start the server with one
280
+ GPU. The 8,192-token profile below is a conservative starting point. Increase
281
+ `MAX_MODEL_LEN` only after measuring KV-cache capacity; the checkpoint supports
282
+ up to 131,072 tokens.
283
+
284
+ <details>
285
+ <summary>Show the vLLM serving command</summary>
286
+
287
+ ```bash
288
+ source .venv/bin/activate
289
+
290
+ export MODEL_ID="IFM/K2-Horizon-0.9B"
291
+ export MODEL_REVISION="main"
292
+ export MAX_MODEL_LEN=8192
293
+ export CHAT_TEMPLATE="$(hf download "$MODEL_ID" chat_template.jinja \
294
+ --revision "$MODEL_REVISION")"
295
+
296
+ vllm serve "$MODEL_ID" \
297
+ --revision "$MODEL_REVISION" \
298
+ --model-impl vllm \
299
+ --trust-remote-code \
300
+ --dtype bfloat16 \
301
+ --tensor-parallel-size 1 \
302
+ --max-model-len "$MAX_MODEL_LEN" \
303
+ --max-num-seqs 1 \
304
+ --gpu-memory-utilization 0.85 \
305
+ --served-model-name "$MODEL_ID" \
306
+ --chat-template "$CHAT_TEMPLATE" \
307
+ --reasoning-parser k2_horizon \
308
+ --tool-call-parser k2_horizon \
309
+ --enable-auto-tool-choice
310
+ ```
311
+
312
+ </details>
313
+
314
+ The reasoning parser moves `<ifm|think>`, `<ifm|think_fast>`, or
315
+ `<ifm|think_faster>` text into the OpenAI-compatible response's
316
+ `reasoning_content` field. The tool parser converts generated
317
+ `<ifm|tool_call>` blocks into structured tool calls when tools are supplied in
318
+ the request.
319
+
320
+ <details>
321
+ <summary>Show an OpenAI-compatible request</summary>
322
+
323
+ ```python
324
+ from openai import OpenAI
325
+
326
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
327
+ response = client.chat.completions.create(
328
+ model="IFM/K2-Horizon-0.9B",
329
+ messages=[{"role": "user", "content": "What is the square root of 2?"}],
330
+ max_tokens=50,
331
+ temperature=0,
332
+ extra_body={"chat_template_kwargs": {"reasoning_effort": "high"}},
333
+ )
334
+ message = response.choices[0].message
335
+ print(getattr(message, "reasoning_content", None))
336
+ print(message.content)
337
+ ```
338
+
339
+ </details>
340
+
341
+ ### Option B - plain Transformers (no vLLM, no container)
342
+
343
+ The checkpoint can also be loaded directly from the Hugging Face repository.
344
+ Its `configuration_k2_horizon.py` and `modeling_k2_horizon.py` files are loaded
345
+ through `trust_remote_code=True`. Use a clean environment so the direct path
346
+ does not inherit vLLM's build dependencies. Transformers 4.57.x is not
347
+ compatible with this remote configuration class; use the validated 5.14.1
348
+ version below. Transformers may print nonfatal `cache_position` documentation
349
+ diagnostics while loading the remote code, but BF16 loading and generation
350
+ complete normally.
351
+
352
+ <details>
353
+ <summary>Show the Transformers environment setup</summary>
354
+
355
+ ```bash
356
+ python3.12 -m venv .venv-transformers
357
+ source .venv-transformers/bin/activate
358
+ python -m pip install --upgrade pip
359
+ python -m pip install "torch==2.11.0" \
360
+ --index-url https://download.pytorch.org/whl/cu128
361
+ python -m pip install \
362
+ "transformers==5.14.1" \
363
+ "safetensors==0.8.0"
364
+ python -m pip check
365
+ ```
366
+
367
+ </details>
368
+
369
+ This deterministic sample loads the released weights as BF16 on one CUDA GPU
370
+ and generates only 50 tokens, making it suitable as an end-to-end smoke test.
371
+
372
+ <details>
373
+ <summary>Show the Transformers inference example</summary>
374
+
375
+ ```python
376
+ import torch
377
+ from transformers import AutoModelForCausalLM, AutoTokenizer
378
+
379
+ MODEL_ID = "IFM/K2-Horizon-0.9B"
380
+ REVISION = "main"
381
+
382
+ tokenizer = AutoTokenizer.from_pretrained(
383
+ MODEL_ID,
384
+ revision=REVISION,
385
+ trust_remote_code=True,
386
+ )
387
+ model = AutoModelForCausalLM.from_pretrained(
388
+ MODEL_ID,
389
+ revision=REVISION,
390
+ dtype=torch.bfloat16,
391
+ trust_remote_code=True,
392
+ ).to("cuda").eval()
393
+
394
+ messages = [{"role": "user", "content": "What is the square root of 2?"}]
395
+ inputs = tokenizer.apply_chat_template(
396
+ messages,
397
+ add_generation_prompt=True,
398
+ reasoning_effort="high",
399
+ return_dict=True,
400
+ return_tensors="pt",
401
+ )
402
+ inputs = {name: value.to(model.device) for name, value in inputs.items()}
403
+ inputs.pop("token_type_ids", None)
404
+
405
+ with torch.inference_mode():
406
+ outputs = model.generate(
407
+ **inputs,
408
+ max_new_tokens=50,
409
+ do_sample=False,
410
+ pad_token_id=tokenizer.pad_token_id,
411
+ )
412
+
413
+ new_tokens = outputs[0, inputs["input_ids"].shape[-1]:]
414
+ print(tokenizer.decode(new_tokens, skip_special_tokens=True))
415
+ ```
416
+
417
+ </details>
418
+
419
+ ## Hardware Requirements
420
+
421
+ The BF16 weights occupy approximately 2.0 GiB. One CUDA GPU is sufficient for
422
+ short-context inference; 8 GiB is a practical minimum for a one-request smoke
423
+ test, while 16 GiB or more provides useful room for longer prompts and runtime
424
+ workspaces. The BF16 KV cache is approximately 0.44 GiB per request at 8,192
425
+ tokens and approximately 7 GiB at 131,072 tokens, before allocator, activation,
426
+ CUDA-graph, and framework overhead. Start with a short context and one sequence,
427
+ then increase context length and concurrency from measured memory headroom.
428
+
429
+ ## Repository Contents
430
+
431
+ The model repository stores the checkpoint directly at its root. It includes:
432
+
433
+ - `model.safetensors` and `model.safetensors.index.json`
434
+ - `config.json`, `generation_config.json`, and the K2 architecture code
435
+ - tokenizer files and three chat-template variants
436
+ - `README.md` and `LICENSE`
437
+
438
+ Use `chat_template.jinja` for ordinary chat and OpenAI-compatible serving.
439
+ `chat_template_generation.jinja` and `chat_template_asst_tool_gen.jinja` are
440
+ specialized generation and assistant-tool-generation variants.
441
+
442
+ ## Training and Evaluation Provenance
443
+
444
+ - **Training:** multi-teacher on-policy distillation with OPD loss weight 0.1,
445
+ reference-KL weight 0.01, learning rate `1e-7`, and a 500-step schedule. The
446
+ selected checkpoint is step 249.
447
+ - **Evaluation:** the AIME, coding, and instruction-following evaluations used
448
+ the training evaluation path with SGLang as the rollout engine. GPQA-Diamond
449
+ was evaluated with Eval360-V2 at revision `f5081bf`.
450
+ - **Export:** the distributed training checkpoint was converted to Hugging Face
451
+ safetensors and checked for tensor parity; all 255 expected weight tensors
452
+ matched. The architecture label was later updated from `XllmForCausalLM` to
453
+ `K2HorizonForCausalLM` without changing the weights.
454
+
455
+ ## Limitations
456
+
457
+ - AIME 2025 remains below the math-and-code teacher, and AIME results have high
458
+ sampling uncertainty because each benchmark contains only 30 problems.
459
+ - GPQA-Diamond is statistically close to the pre-distillation base result, so
460
+ the reported run does not demonstrate a clear STEM improvement.
461
+ - Long-horizon tool use remains substantially weaker than single-turn tool
462
+ calling in the BFCL v4 breakdown.
463
+ - Benchmark scores depend on prompt templates, reasoning effort, sampling
464
+ parameters, framework versions, and evaluation harness details. Validate the
465
+ model on representative prompts before deployment.
466
+ - As with other language models, K2-Horizon-0.9B can produce inaccurate,
467
+ biased, or unsafe text. Applications should use task-specific evaluation,
468
+ input and output controls, monitoring, and human review where appropriate.