Text Generation
Transformers
Safetensors
English
Chinese
k2_horizon
k2-horizon
0.9b
dense
reasoning
knowledge-distillation
ifm
conversational
custom_code
Instructions to use IFM/K2-Horizon-0.9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IFM/K2-Horizon-0.9B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IFM/K2-Horizon-0.9B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("IFM/K2-Horizon-0.9B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IFM/K2-Horizon-0.9B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IFM/K2-Horizon-0.9B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IFM/K2-Horizon-0.9B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/IFM/K2-Horizon-0.9B
- SGLang
How to use IFM/K2-Horizon-0.9B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "IFM/K2-Horizon-0.9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IFM/K2-Horizon-0.9B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "IFM/K2-Horizon-0.9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IFM/K2-Horizon-0.9B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use IFM/K2-Horizon-0.9B with Docker Model Runner:
docker model run hf.co/IFM/K2-Horizon-0.9B
Upload APPENDIX.md
Browse files- APPENDIX.md +383 -0
APPENDIX.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# K2-Horizon-0.9B Technical Appendix
|
| 2 |
+
|
| 3 |
+
This appendix contains the detailed architecture, checkpoint, training, deployment, hardware, evaluation, dataset, source-code, intended-use, and safety material moved from the full model card. The short [README](README.md) follows the common K2-Horizon release format.
|
| 4 |
+
|
| 5 |
+
## Model Series Overview
|
| 6 |
+
|
| 7 |
+
K2-Horizon spans compact and larger dense models for transparent foundation-model research, staged checkpoint analysis, and practical deployment. The repositories share a common release structure while preserving model-specific training and serving guidance.
|
| 8 |
+
|
| 9 |
+
| Model | Architecture | Parameters | Context length | Intended use |
|
| 10 |
+
| --- | --- | ---: | ---: | --- |
|
| 11 |
+
| **K2-Horizon-0.9B** | Dense decoder-only | 1.08B including embeddings | 131,072 | Compact reasoning, local inference, and distillation research |
|
| 12 |
+
| K2-Horizon-3.7B | Dense decoder-only | 3.78B core | 524,288 | Efficient research, evaluation, and single-node serving |
|
| 13 |
+
| K2-Horizon-7B | Dense decoder-only | 7B core | 524,288 | General research, fine-tuning, and cost-conscious deployment |
|
| 14 |
+
| K2-Horizon-32B | Dense decoder-only | 32B core | 524,288 | Stronger long-context and reasoning experiments |
|
| 15 |
+
|
| 16 |
+
## This Repository
|
| 17 |
+
|
| 18 |
+
| Property | Value |
|
| 19 |
+
|---|---|
|
| 20 |
+
| **Architecture** | `K2HorizonForCausalLM` (`model_type: k2_horizon`) |
|
| 21 |
+
| **Parameters** | 1,078,285,824 (released as 0.9B; counted from the safetensors tensors) |
|
| 22 |
+
| **Hidden size / layers** | 1,536 / 28 |
|
| 23 |
+
| **Attention heads / KV heads** | 32 / 8 |
|
| 24 |
+
| **Context length** | 131,072 tokens with YaRN RoPE scaling; original context length 8,192 tokens |
|
| 25 |
+
| **Vocabulary size** | 64,256 |
|
| 26 |
+
| **Released weight dtype** | BF16 |
|
| 27 |
+
| **Format** | Hugging Face safetensors, one weight shard, with custom configuration and modeling code in the repository root |
|
| 28 |
+
| **Distillation checkpoint** | Step 249 of a 500-step mOPD run |
|
| 29 |
+
|
| 30 |
+
The `main` revision publishes `K2HorizonForCausalLM`,
|
| 31 |
+
`model_type: k2_horizon`, and matching `configuration_k2_horizon.py` and
|
| 32 |
+
`modeling_k2_horizon.py` modules. The Transformers and vLLM preflights below
|
| 33 |
+
validate that public contract before loading weights.
|
| 34 |
+
|
| 35 |
+
## Checkpoint Revisions
|
| 36 |
+
|
| 37 |
+
| Revision | Stage | Max context |
|
| 38 |
+
| --- | --- | ---: |
|
| 39 |
+
| `main` | Distilled release checkpoint, step 249 | 128K |
|
| 40 |
+
| `mid2_47k` | Second context-extension stage | 128K |
|
| 41 |
+
| `mid1_75k` | First context-extension stage | 40K |
|
| 42 |
+
| Base model | Pre-distillation specialist merge | 8K |
|
| 43 |
+
|
| 44 |
+
## Training Provenance
|
| 45 |
+
|
| 46 |
+
Training examples were routed to a math-and-code teacher, a STEM teacher, or
|
| 47 |
+
an instruction-following teacher through the example's `opd_domain` metadata.
|
| 48 |
+
The math-and-code teacher was used as the fallback when no recognized domain
|
| 49 |
+
was present.
|
| 50 |
+
|
| 51 |
+
| Domain | Teacher checkpoint step |
|
| 52 |
+
|---|---:|
|
| 53 |
+
| Math and code | 2,739 |
|
| 54 |
+
| STEM | 499 |
|
| 55 |
+
| Instruction following | 1,499 |
|
| 56 |
+
|
| 57 |
+
The base context window was extended in stages from 8,192 to 40,960 and then
|
| 58 |
+
to 131,072 tokens. The `mid1_75k` and `mid2_47k` repository revisions preserve
|
| 59 |
+
the corresponding intermediate checkpoints. The distilled release checkpoint
|
| 60 |
+
is on `main`; all stages use a vocabulary of 64,256 tokens.
|
| 61 |
+
|
| 62 |
+
## Training Loss
|
| 63 |
+
|
| 64 |
+
K2-Horizon-0.9B begins with a task-arithmetic merge of three specialist
|
| 65 |
+
checkpoints. mOPD then trains that merged student against math-and-code, STEM,
|
| 66 |
+
and instruction-following teachers at the same time. The training objective
|
| 67 |
+
combines an on-policy distillation loss with a reference-model KL term so the
|
| 68 |
+
student can learn specialist behavior while remaining close to the merged base
|
| 69 |
+
model.
|
| 70 |
+
|
| 71 |
+
The resulting checkpoint retains most of the specialist teachers' performance
|
| 72 |
+
on the reported math and coding tasks. It also improves every reported IFEval
|
| 73 |
+
submetric over the pre-distillation merge. This makes the model useful for
|
| 74 |
+
research on compact reasoning models, local inference, distillation, and
|
| 75 |
+
task-specific adaptation.
|
| 76 |
+
|
| 77 |
+
## Deployment Guide
|
| 78 |
+
|
| 79 |
+
K2-Horizon-0.9B emits a reasoning segment before its final answer when the
|
| 80 |
+
chat template is used. The template supports `reasoning_effort` values `high`,
|
| 81 |
+
`medium`, and `low`, which select the model's full, fast, and faster reasoning
|
| 82 |
+
modes respectively.
|
| 83 |
+
|
| 84 |
+
For a deterministic runtime check, use `temperature=0` and generate 20 to 50
|
| 85 |
+
tokens. For general sampled generation, `temperature=0.6` and `top_p=0.95`
|
| 86 |
+
reproduce the GPQA evaluation setting and are reasonable starting points.
|
| 87 |
+
IFBench used `temperature=0.8`. Long math and coding tasks may require several
|
| 88 |
+
thousand output tokens; choose limits from application measurements rather
|
| 89 |
+
than treating an evaluation limit as a universal default.
|
| 90 |
+
|
| 91 |
+
### vLLM
|
| 92 |
+
|
| 93 |
+
The validated serving image was reconstructed into the following manual
|
| 94 |
+
runtime contract:
|
| 95 |
+
|
| 96 |
+
| Component | Validated value |
|
| 97 |
+
|---|---|
|
| 98 |
+
| Operating system | Ubuntu 24.04, Linux x86-64 |
|
| 99 |
+
| Python | 3.12.13 |
|
| 100 |
+
| CUDA toolkit | 12.9 |
|
| 101 |
+
| PyTorch | 2.13.0+cu129 |
|
| 102 |
+
| Transformers | 5.16.1 |
|
| 103 |
+
| Safetensors | 0.8.0 |
|
| 104 |
+
| FlashInfer | 0.6.17 |
|
| 105 |
+
| Attention backend | vLLM FlashAttention 3; Triton 3.7.1 |
|
| 106 |
+
| 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) |
|
| 107 |
+
|
| 108 |
+
That source revision contains the native `K2HorizonForCausalLM` implementation
|
| 109 |
+
and the built-in `k2_horizon` reasoning and tool parsers. Other vLLM revisions
|
| 110 |
+
have not been validated for this checkpoint. Pin the exact commit until the
|
| 111 |
+
integration is available in an upstream release.
|
| 112 |
+
|
| 113 |
+
Use Linux x86-64 with a CUDA 12.9-compatible NVIDIA driver and Git. The setup
|
| 114 |
+
uses vLLM's precompiled extension path while keeping the Python package on the
|
| 115 |
+
exact reviewed source commit.
|
| 116 |
+
|
| 117 |
+
<details>
|
| 118 |
+
<summary>Show the pinned vLLM environment setup</summary>
|
| 119 |
+
|
| 120 |
+
```bash
|
| 121 |
+
git clone --filter=blob:none --no-checkout \
|
| 122 |
+
https://github.com/vllm-project/vllm.git
|
| 123 |
+
cd vllm
|
| 124 |
+
git fetch origin pull/53806/head:refs/remotes/origin/pr-53806
|
| 125 |
+
git checkout --detach d9fd5f11423a1a5628fe29e7296ceb9de91aac3c
|
| 126 |
+
test "$(git rev-parse HEAD)" = \
|
| 127 |
+
"d9fd5f11423a1a5628fe29e7296ceb9de91aac3c"
|
| 128 |
+
|
| 129 |
+
python3.12 -m venv .venv
|
| 130 |
+
source .venv/bin/activate
|
| 131 |
+
python -m pip install --upgrade pip uv
|
| 132 |
+
export UV_LINK_MODE=copy
|
| 133 |
+
VLLM_USE_PRECOMPILED=1 uv pip install --upgrade --editable . \
|
| 134 |
+
--torch-backend=auto
|
| 135 |
+
uv pip install "transformers==5.16.1" "safetensors==0.8.0"
|
| 136 |
+
python -m pip check
|
| 137 |
+
|
| 138 |
+
python - <<'PY'
|
| 139 |
+
from vllm import ModelRegistry
|
| 140 |
+
from vllm.reasoning import ReasoningParserManager
|
| 141 |
+
from vllm.tool_parsers import ToolParserManager
|
| 142 |
+
|
| 143 |
+
assert "K2HorizonForCausalLM" in ModelRegistry.get_supported_archs()
|
| 144 |
+
assert ReasoningParserManager.get_reasoning_parser("k2_horizon") is not None
|
| 145 |
+
assert ToolParserManager.get_tool_parser("k2_horizon") is not None
|
| 146 |
+
PY
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
</details>
|
| 150 |
+
|
| 151 |
+
Download the repository chat template explicitly and start the server with one
|
| 152 |
+
GPU. The 8,192-token profile below is a conservative starting point. Increase
|
| 153 |
+
`MAX_MODEL_LEN` only after measuring KV-cache capacity; the checkpoint supports
|
| 154 |
+
up to 131,072 tokens.
|
| 155 |
+
|
| 156 |
+
<details>
|
| 157 |
+
<summary>Show the vLLM serving command</summary>
|
| 158 |
+
|
| 159 |
+
```bash
|
| 160 |
+
source .venv/bin/activate
|
| 161 |
+
|
| 162 |
+
export MODEL_ID="IFM/K2-Horizon-0.9B"
|
| 163 |
+
export MODEL_REVISION="main"
|
| 164 |
+
export MAX_MODEL_LEN=8192
|
| 165 |
+
export CHAT_TEMPLATE="$(hf download "$MODEL_ID" chat_template.jinja \
|
| 166 |
+
--revision "$MODEL_REVISION")"
|
| 167 |
+
|
| 168 |
+
vllm serve "$MODEL_ID" \
|
| 169 |
+
--revision "$MODEL_REVISION" \
|
| 170 |
+
--model-impl vllm \
|
| 171 |
+
--trust-remote-code \
|
| 172 |
+
--dtype bfloat16 \
|
| 173 |
+
--tensor-parallel-size 1 \
|
| 174 |
+
--max-model-len "$MAX_MODEL_LEN" \
|
| 175 |
+
--max-num-seqs 1 \
|
| 176 |
+
--gpu-memory-utilization 0.85 \
|
| 177 |
+
--served-model-name "$MODEL_ID" \
|
| 178 |
+
--chat-template "$CHAT_TEMPLATE" \
|
| 179 |
+
--reasoning-parser k2_horizon \
|
| 180 |
+
--tool-call-parser k2_horizon \
|
| 181 |
+
--enable-auto-tool-choice
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
</details>
|
| 185 |
+
|
| 186 |
+
The reasoning parser moves `<ifm|think>`, `<ifm|think_fast>`, or
|
| 187 |
+
`<ifm|think_faster>` text into the OpenAI-compatible response's
|
| 188 |
+
`reasoning_content` field. The tool parser converts generated
|
| 189 |
+
`<ifm|tool_call>` blocks into structured tool calls when tools are supplied in
|
| 190 |
+
the request.
|
| 191 |
+
|
| 192 |
+
<details>
|
| 193 |
+
<summary>Show an OpenAI-compatible request</summary>
|
| 194 |
+
|
| 195 |
+
```python
|
| 196 |
+
from openai import OpenAI
|
| 197 |
+
|
| 198 |
+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
|
| 199 |
+
response = client.chat.completions.create(
|
| 200 |
+
model="IFM/K2-Horizon-0.9B",
|
| 201 |
+
messages=[{"role": "user", "content": "What is the square root of 2?"}],
|
| 202 |
+
max_tokens=50,
|
| 203 |
+
temperature=0,
|
| 204 |
+
extra_body={"chat_template_kwargs": {"reasoning_effort": "high"}},
|
| 205 |
+
)
|
| 206 |
+
message = response.choices[0].message
|
| 207 |
+
print(getattr(message, "reasoning_content", None))
|
| 208 |
+
print(message.content)
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
</details>
|
| 212 |
+
|
| 213 |
+
### SGLang
|
| 214 |
+
|
| 215 |
+
Native K2 Horizon support is provided by
|
| 216 |
+
[sgl-project/sglang#37654](https://github.com/sgl-project/sglang/pull/37654).
|
| 217 |
+
Use a `lmsysorg/sglang:dev` image built after that PR is merged. Once support is
|
| 218 |
+
included in a tagged SGLang release, use the corresponding versioned image.
|
| 219 |
+
|
| 220 |
+
<details>
|
| 221 |
+
<summary>Show the SGLang serving command</summary>
|
| 222 |
+
|
| 223 |
+
```bash
|
| 224 |
+
docker run --gpus all \
|
| 225 |
+
--shm-size 32g \
|
| 226 |
+
-p 30000:30000 \
|
| 227 |
+
-v ~/.cache/huggingface:/root/.cache/huggingface \
|
| 228 |
+
--ipc=host \
|
| 229 |
+
lmsysorg/sglang:dev \
|
| 230 |
+
python3 -m sglang.launch_server \
|
| 231 |
+
--model-path "IFM/K2-Horizon-0.9B" \
|
| 232 |
+
--revision main \
|
| 233 |
+
--tp 1 \
|
| 234 |
+
--dtype bfloat16 \
|
| 235 |
+
--context-length 8192 \
|
| 236 |
+
--attention-backend fa3 \
|
| 237 |
+
--reasoning-parser k2_horizon \
|
| 238 |
+
--tool-call-parser k2_horizon \
|
| 239 |
+
--mem-fraction-static 0.85 \
|
| 240 |
+
--host 0.0.0.0 \
|
| 241 |
+
--port 30000
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
</details>
|
| 245 |
+
|
| 246 |
+
This uses SGLang's native `K2HorizonForCausalLM` implementation; no
|
| 247 |
+
`--trust-remote-code`, source patch, or external parser plugin is required. The
|
| 248 |
+
8,192-token limit is a conservative starting point; increase it only after
|
| 249 |
+
measuring KV-cache capacity.
|
| 250 |
+
|
| 251 |
+
### Transformers
|
| 252 |
+
|
| 253 |
+
The checkpoint can also be loaded directly from the Hugging Face repository.
|
| 254 |
+
Its `configuration_k2_horizon.py` and `modeling_k2_horizon.py` files are loaded
|
| 255 |
+
through `trust_remote_code=True`. Use a clean environment so the direct path
|
| 256 |
+
does not inherit vLLM's build dependencies. Transformers 4.57.x is not
|
| 257 |
+
compatible with this remote configuration class; use the validated 5.14.1
|
| 258 |
+
version below. Transformers may print nonfatal `cache_position` documentation
|
| 259 |
+
diagnostics while loading the remote code, but BF16 loading and generation
|
| 260 |
+
complete normally.
|
| 261 |
+
|
| 262 |
+
<details>
|
| 263 |
+
<summary>Show the Transformers environment setup</summary>
|
| 264 |
+
|
| 265 |
+
```bash
|
| 266 |
+
python3.12 -m venv .venv-transformers
|
| 267 |
+
source .venv-transformers/bin/activate
|
| 268 |
+
python -m pip install --upgrade pip
|
| 269 |
+
python -m pip install "torch==2.11.0" \
|
| 270 |
+
--index-url https://download.pytorch.org/whl/cu128
|
| 271 |
+
python -m pip install \
|
| 272 |
+
"transformers==5.14.1" \
|
| 273 |
+
"safetensors==0.8.0"
|
| 274 |
+
python -m pip check
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
</details>
|
| 278 |
+
|
| 279 |
+
This deterministic sample loads the released weights as BF16 on one CUDA GPU
|
| 280 |
+
and generates only 50 tokens, making it suitable as an end-to-end smoke test.
|
| 281 |
+
|
| 282 |
+
<details>
|
| 283 |
+
<summary>Show the Transformers inference example</summary>
|
| 284 |
+
|
| 285 |
+
```python
|
| 286 |
+
import torch
|
| 287 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 288 |
+
|
| 289 |
+
MODEL_ID = "IFM/K2-Horizon-0.9B"
|
| 290 |
+
REVISION = "main"
|
| 291 |
+
|
| 292 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 293 |
+
MODEL_ID,
|
| 294 |
+
revision=REVISION,
|
| 295 |
+
trust_remote_code=True,
|
| 296 |
+
)
|
| 297 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 298 |
+
MODEL_ID,
|
| 299 |
+
revision=REVISION,
|
| 300 |
+
dtype=torch.bfloat16,
|
| 301 |
+
trust_remote_code=True,
|
| 302 |
+
).to("cuda").eval()
|
| 303 |
+
|
| 304 |
+
messages = [{"role": "user", "content": "What is the square root of 2?"}]
|
| 305 |
+
inputs = tokenizer.apply_chat_template(
|
| 306 |
+
messages,
|
| 307 |
+
add_generation_prompt=True,
|
| 308 |
+
reasoning_effort="high",
|
| 309 |
+
return_dict=True,
|
| 310 |
+
return_tensors="pt",
|
| 311 |
+
)
|
| 312 |
+
inputs = {name: value.to(model.device) for name, value in inputs.items()}
|
| 313 |
+
inputs.pop("token_type_ids", None)
|
| 314 |
+
|
| 315 |
+
with torch.inference_mode():
|
| 316 |
+
outputs = model.generate(
|
| 317 |
+
**inputs,
|
| 318 |
+
max_new_tokens=50,
|
| 319 |
+
do_sample=False,
|
| 320 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
new_tokens = outputs[0, inputs["input_ids"].shape[-1]:]
|
| 324 |
+
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
|
| 325 |
+
```
|
| 326 |
+
|
| 327 |
+
</details>
|
| 328 |
+
|
| 329 |
+
## Hardware Planning
|
| 330 |
+
|
| 331 |
+
The BF16 weights occupy approximately 2.0 GiB. One CUDA GPU is sufficient for
|
| 332 |
+
short-context inference; 8 GiB is a practical minimum for a one-request smoke
|
| 333 |
+
test, while 16 GiB or more provides useful room for longer prompts and runtime
|
| 334 |
+
workspaces. The BF16 KV cache is approximately 0.44 GiB per request at 8,192
|
| 335 |
+
tokens and approximately 7 GiB at 131,072 tokens, before allocator, activation,
|
| 336 |
+
CUDA-graph, and framework overhead. Start with a short context and one sequence,
|
| 337 |
+
then increase context length and concurrency from measured memory headroom.
|
| 338 |
+
|
| 339 |
+
## Source Code
|
| 340 |
+
|
| 341 |
+
The model repository stores the checkpoint directly at its root. It includes:
|
| 342 |
+
|
| 343 |
+
- `model.safetensors` and `model.safetensors.index.json`
|
| 344 |
+
- `config.json`, `generation_config.json`, and the K2 architecture code
|
| 345 |
+
- tokenizer files and three chat-template variants
|
| 346 |
+
- `README.md` and `LICENSE`
|
| 347 |
+
|
| 348 |
+
Use `chat_template.jinja` for ordinary chat and OpenAI-compatible serving.
|
| 349 |
+
`chat_template_generation.jinja` and `chat_template_asst_tool_gen.jinja` are
|
| 350 |
+
specialized generation and assistant-tool-generation variants.
|
| 351 |
+
|
| 352 |
+
## Evaluation
|
| 353 |
+
|
| 354 |
+
- **Training:** multi-teacher on-policy distillation with OPD loss weight 0.1,
|
| 355 |
+
reference-KL weight 0.01, learning rate `1e-7`, and a 500-step schedule. The
|
| 356 |
+
selected checkpoint is step 249.
|
| 357 |
+
- **Evaluation:** the AIME, coding, and instruction-following evaluations used
|
| 358 |
+
the training evaluation path with SGLang as the rollout engine. GPQA-Diamond
|
| 359 |
+
was evaluated with Eval360-V2 at revision `f5081bf`.
|
| 360 |
+
- **Export:** the distributed training checkpoint was converted to Hugging Face
|
| 361 |
+
safetensors and checked for tensor parity; all 255 expected weight tensors
|
| 362 |
+
matched. The architecture label was later updated from `XllmForCausalLM` to
|
| 363 |
+
`K2HorizonForCausalLM` without changing the weights.
|
| 364 |
+
|
| 365 |
+
## Intended Use
|
| 366 |
+
|
| 367 |
+
K2-Horizon-0.9B is intended for compact reasoning research, local inference, evaluation dry runs, distillation studies, and task-specific adaptation. It is a research release and should be evaluated on representative prompts before deployment.
|
| 368 |
+
|
| 369 |
+
## Limitations and Safety
|
| 370 |
+
|
| 371 |
+
- AIME 2025 remains below the math-and-code teacher, and AIME results have high
|
| 372 |
+
sampling uncertainty because each benchmark contains only 30 problems.
|
| 373 |
+
- GPQA-Diamond is statistically close to the pre-distillation base result, so
|
| 374 |
+
the reported run does not demonstrate a clear STEM improvement.
|
| 375 |
+
- Long-horizon tool use remains substantially weaker than single-turn tool
|
| 376 |
+
calling in the BFCL v4 breakdown.
|
| 377 |
+
- Benchmark scores depend on prompt templates, reasoning effort, sampling
|
| 378 |
+
parameters, framework versions, and evaluation harness details. Validate the
|
| 379 |
+
model on representative prompts before deployment.
|
| 380 |
+
- As with other language models, K2-Horizon-0.9B can produce inaccurate,
|
| 381 |
+
biased, or unsafe text. Applications should use task-specific evaluation,
|
| 382 |
+
input and output controls, monitoring, and human review where appropriate.
|
| 383 |
+
|