Text Generation
Transformers
Safetensors
English
k2_horizon
k2-horizon
7b
dense
open-weights
ifm
conversational
custom_code
Instructions to use IFM/K2-Horizon-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IFM/K2-Horizon-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IFM/K2-Horizon-7B", 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-7B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IFM/K2-Horizon-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IFM/K2-Horizon-7B" # 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-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/IFM/K2-Horizon-7B
- SGLang
How to use IFM/K2-Horizon-7B 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-7B" \ --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-7B", "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-7B" \ --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-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use IFM/K2-Horizon-7B with Docker Model Runner:
docker model run hf.co/IFM/K2-Horizon-7B
docs: update SGLang quickstart
#1
by akhauriyash - opened
README.md
CHANGED
|
@@ -318,108 +318,41 @@ The source checkout is immutable at `d9fd5f11423a1a5628fe29e7296ceb9de91aac3c`.
|
|
| 318 |
|
| 319 |
### SGLang
|
| 320 |
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
<details>
|
| 324 |
-
<summary>Show SGLang
|
| 325 |
|
| 326 |
```bash
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
path
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
old_class = "K2" + "V3"
|
| 347 |
-
old_id = "k2" + "_v3"
|
| 348 |
-
old_label = "K2-" + "v3"
|
| 349 |
-
contracts = (
|
| 350 |
-
(
|
| 351 |
-
Path("python/sglang/srt/parser/reasoning_parser.py"),
|
| 352 |
-
"8bd1894b7d8c2935d4800e44616ba18c8eebaedde9d7c95c5d270864e928a25c",
|
| 353 |
-
"e448c562fd5a994dec67a3ebf5d6539a4acbac0bbc2204d67ba801dd502ca7f5",
|
| 354 |
-
),
|
| 355 |
-
(
|
| 356 |
-
Path("python/sglang/srt/function_call/function_call_parser.py"),
|
| 357 |
-
"0957d87b0e5dbcf761dc4871f4e48a7cc1f8c7e0a7badbfb5d3982b10f4d10eb",
|
| 358 |
-
"177dabfc3c73461ecbb7da14c4009e4b6c109502a1d6bed65de0dfba6f9e7785",
|
| 359 |
-
),
|
| 360 |
-
(
|
| 361 |
-
Path("python/sglang/srt/function_call/multi_format_detector.py"),
|
| 362 |
-
"306d310748ba84d3c2084d111a23fb6e2dead2e316bd0bdf69356b3c6e6eeab1",
|
| 363 |
-
"b6e5650366afe8f7abf878172e70bdde527df1e1484514625e49178606ba847e",
|
| 364 |
-
),
|
| 365 |
-
)
|
| 366 |
-
replacements = (
|
| 367 |
-
(old_class, "K2Horizon"),
|
| 368 |
-
(old_id, "k2_horizon"),
|
| 369 |
-
(old_label, "K2-Horizon"),
|
| 370 |
-
)
|
| 371 |
-
for source_path, original_hash, migrated_hash in contracts:
|
| 372 |
-
text = source_path.read_text(encoding="utf-8")
|
| 373 |
-
if sha256(text.encode()).hexdigest() != original_hash:
|
| 374 |
-
raise RuntimeError(f"unexpected pinned SGLang parser source: {source_path}")
|
| 375 |
-
for old, new in replacements:
|
| 376 |
-
text = text.replace(old, new)
|
| 377 |
-
if sha256(text.encode()).hexdigest() != migrated_hash:
|
| 378 |
-
raise RuntimeError(f"unexpected Horizon parser migration: {source_path}")
|
| 379 |
-
source_path.write_text(text, encoding="utf-8")
|
| 380 |
-
PY
|
| 381 |
-
|
| 382 |
-
export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SGLANG="0.5.10+ffb41d77.stableonly"
|
| 383 |
-
python -m pip install ./python "safetensors==0.8.0"
|
| 384 |
-
python -m pip check
|
| 385 |
-
python - <<'PY'
|
| 386 |
-
from importlib.metadata import metadata, version
|
| 387 |
-
|
| 388 |
-
from packaging.version import Version
|
| 389 |
-
from sglang.srt.function_call.function_call_parser import FunctionCallParser
|
| 390 |
-
from sglang.srt.parser.reasoning_parser import ReasoningParser
|
| 391 |
-
|
| 392 |
-
assert not Version(version("sglang")).is_prerelease
|
| 393 |
-
requirements = metadata("sglang").get_all("Requires-Dist") or []
|
| 394 |
-
assert not any(requirement.lower().startswith("flash-attn-4") for requirement in requirements)
|
| 395 |
-
assert "k2_horizon" in ReasoningParser.DetectorMap
|
| 396 |
-
assert "k2_horizon_legacy" in ReasoningParser.DetectorMap
|
| 397 |
-
assert "k2_horizon" in FunctionCallParser.ToolCallParserEnum
|
| 398 |
-
PY
|
| 399 |
-
|
| 400 |
-
export MODEL_ID="IFM/K2-Horizon-7B"
|
| 401 |
-
export MODEL_REVISION="mid_4"
|
| 402 |
-
export TP_SIZE=1
|
| 403 |
-
export CONTEXT_LENGTH=131072
|
| 404 |
-
|
| 405 |
-
python -m sglang.launch_server \
|
| 406 |
-
--model-path "$MODEL_ID" \
|
| 407 |
-
--revision "$MODEL_REVISION" \
|
| 408 |
-
--model-impl transformers \
|
| 409 |
-
--tp "$TP_SIZE" \
|
| 410 |
-
--trust-remote-code \
|
| 411 |
-
--dtype bfloat16 \
|
| 412 |
-
--context-length "$CONTEXT_LENGTH" \
|
| 413 |
-
--attention-backend fa3 \
|
| 414 |
-
--reasoning-parser k2_horizon \
|
| 415 |
-
--tool-call-parser k2_horizon \
|
| 416 |
-
--mem-fraction-static 0.85 \
|
| 417 |
-
--disable-piecewise-cuda-graph
|
| 418 |
```
|
| 419 |
|
| 420 |
</details>
|
| 421 |
|
| 422 |
-
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
### Reasoning and Tool Parsers
|
| 425 |
|
|
|
|
| 318 |
|
| 319 |
### SGLang
|
| 320 |
|
| 321 |
+
Native K2 Horizon support is provided by
|
| 322 |
+
[sgl-project/sglang#37654](https://github.com/sgl-project/sglang/pull/37654).
|
| 323 |
+
Use a `lmsysorg/sglang:dev` image built after that PR is merged. Once support is
|
| 324 |
+
included in a tagged SGLang release, use the corresponding versioned image.
|
| 325 |
|
| 326 |
<details>
|
| 327 |
+
<summary>Show the SGLang serving command</summary>
|
| 328 |
|
| 329 |
```bash
|
| 330 |
+
docker run --gpus all \
|
| 331 |
+
--shm-size 32g \
|
| 332 |
+
-p 30000:30000 \
|
| 333 |
+
-v ~/.cache/huggingface:/root/.cache/huggingface \
|
| 334 |
+
--ipc=host \
|
| 335 |
+
lmsysorg/sglang:dev \
|
| 336 |
+
python3 -m sglang.launch_server \
|
| 337 |
+
--model-path "IFM/K2-Horizon-7B" \
|
| 338 |
+
--revision main \
|
| 339 |
+
--tp 1 \
|
| 340 |
+
--dtype bfloat16 \
|
| 341 |
+
--context-length 131072 \
|
| 342 |
+
--attention-backend fa3 \
|
| 343 |
+
--reasoning-parser k2_horizon \
|
| 344 |
+
--tool-call-parser k2_horizon \
|
| 345 |
+
--mem-fraction-static 0.85 \
|
| 346 |
+
--host 0.0.0.0 \
|
| 347 |
+
--port 30000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
```
|
| 349 |
|
| 350 |
</details>
|
| 351 |
|
| 352 |
+
This uses SGLang's native `K2HorizonForCausalLM` implementation; no
|
| 353 |
+
`--trust-remote-code`, source patch, or external parser plugin is required. The
|
| 354 |
+
131,072-token limit is a conservative starting point; increase it only after
|
| 355 |
+
measuring KV-cache capacity.
|
| 356 |
|
| 357 |
### Reasoning and Tool Parsers
|
| 358 |
|