Text Generation
Transformers
Safetensors
English
k2_horizon
k2-horizon
3.7b
dense
open-weights
ifm
conversational
custom_code
Instructions to use IFM/K2-Horizon-3.7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IFM/K2-Horizon-3.7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IFM/K2-Horizon-3.7B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("IFM/K2-Horizon-3.7B", trust_remote_code=True, device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IFM/K2-Horizon-3.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-3.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-3.7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/IFM/K2-Horizon-3.7B
- SGLang
How to use IFM/K2-Horizon-3.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-3.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-3.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-3.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-3.7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use IFM/K2-Horizon-3.7B with Docker Model Runner:
docker model run hf.co/IFM/K2-Horizon-3.7B
Commit ·
9d280ff
1
Parent(s): d6e5432
Support OpenAI-style text content lists (#7)
Browse files- Support OpenAI-style text content lists (f3f919efceb5a91e3ec20424ad93dde931199cea)
Co-authored-by: Seungwook Han <hanseungwook@users.noreply.huggingface.co>
- chat_template.jinja +27 -7
chat_template.jinja
CHANGED
|
@@ -888,6 +888,26 @@ false
|
|
| 888 |
{{- "\n</ifm|tool_calls>" }}
|
| 889 |
{%- endmacro -%}
|
| 890 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 891 |
{%- macro render_tool_response_messages(raw_content) -%}
|
| 892 |
{%- if raw_content is string -%}
|
| 893 |
{{- '<|ifm|im_start|>tool\n' + raw_content + '<|ifm|im_end|>' }}
|
|
@@ -916,22 +936,22 @@ false
|
|
| 916 |
{%- if (not available_tools) and messages[0].role == 'system' and messages[0].get('tools') -%}
|
| 917 |
{%- set available_tools = messages[0]['tools'] -%}
|
| 918 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 919 |
{%- if available_tools -%}
|
| 920 |
{{- validate_tools(available_tools, tool_presentation_fmt != 'json') }}
|
| 921 |
-
{%- set system_content = '' -%}
|
| 922 |
-
{%- if messages[0].role == 'system' and messages[0].content -%}
|
| 923 |
-
{%- set system_content = messages[0].content -%}
|
| 924 |
-
{%- endif -%}
|
| 925 |
{{- render_system_with_tools(available_tools, system_content, tool_presentation_fmt, tool_call_fmt) }}
|
| 926 |
{%- else -%}
|
| 927 |
{%- if messages[0].role == 'system' -%}
|
| 928 |
-
{{- '<|ifm|im_start|>system\n' +
|
| 929 |
{%- endif -%}
|
| 930 |
{%- endif -%}
|
| 931 |
|
| 932 |
{%- for message in messages -%}
|
| 933 |
-
{%- if message.
|
| 934 |
-
{%- set content = message.content -%}
|
| 935 |
{%- else -%}
|
| 936 |
{%- set content = '' -%}
|
| 937 |
{%- endif -%}
|
|
|
|
| 888 |
{{- "\n</ifm|tool_calls>" }}
|
| 889 |
{%- endmacro -%}
|
| 890 |
|
| 891 |
+
{#- Normalize text content for user, system, and assistant messages. File text -#}
|
| 892 |
+
{#- must be extracted upstream and supplied as strings or typed text parts. -#}
|
| 893 |
+
{%- macro render_text_content(raw_content, role) -%}
|
| 894 |
+
{%- if raw_content is string -%}
|
| 895 |
+
{{- raw_content -}}
|
| 896 |
+
{%- elif role == 'assistant' and (raw_content is none or raw_content is undefined) -%}
|
| 897 |
+
{{- '' -}}
|
| 898 |
+
{%- elif raw_content is defined and raw_content is sequence and raw_content is not mapping -%}
|
| 899 |
+
{%- for part in raw_content -%}
|
| 900 |
+
{%- if part is mapping and part.type == 'text' and part.text is string -%}
|
| 901 |
+
{{- part.text -}}
|
| 902 |
+
{%- else -%}
|
| 903 |
+
{{- raise_exception("Unsupported " ~ role ~ " content part at index " ~ loop.index0 ~ ". Expected type='text' with a string text field; extract file contents to text before templating.") -}}
|
| 904 |
+
{%- endif -%}
|
| 905 |
+
{%- endfor -%}
|
| 906 |
+
{%- else -%}
|
| 907 |
+
{{- raise_exception("Unsupported " ~ role ~ " message content. Expected a string or a list of text parts.") -}}
|
| 908 |
+
{%- endif -%}
|
| 909 |
+
{%- endmacro -%}
|
| 910 |
+
|
| 911 |
{%- macro render_tool_response_messages(raw_content) -%}
|
| 912 |
{%- if raw_content is string -%}
|
| 913 |
{{- '<|ifm|im_start|>tool\n' + raw_content + '<|ifm|im_end|>' }}
|
|
|
|
| 936 |
{%- if (not available_tools) and messages[0].role == 'system' and messages[0].get('tools') -%}
|
| 937 |
{%- set available_tools = messages[0]['tools'] -%}
|
| 938 |
{%- endif -%}
|
| 939 |
+
{%- set system_content = '' -%}
|
| 940 |
+
{%- if messages[0].role == 'system' -%}
|
| 941 |
+
{%- set system_content = render_text_content(messages[0].content, 'system') -%}
|
| 942 |
+
{%- endif -%}
|
| 943 |
{%- if available_tools -%}
|
| 944 |
{{- validate_tools(available_tools, tool_presentation_fmt != 'json') }}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 945 |
{{- render_system_with_tools(available_tools, system_content, tool_presentation_fmt, tool_call_fmt) }}
|
| 946 |
{%- else -%}
|
| 947 |
{%- if messages[0].role == 'system' -%}
|
| 948 |
+
{{- '<|ifm|im_start|>system\n' + system_content + '<|ifm|im_end|>' }}
|
| 949 |
{%- endif -%}
|
| 950 |
{%- endif -%}
|
| 951 |
|
| 952 |
{%- for message in messages -%}
|
| 953 |
+
{%- if message.role == 'user' or message.role == 'assistant' or (message.role == 'system' and not loop.first) -%}
|
| 954 |
+
{%- set content = render_text_content(message.content, message.role) -%}
|
| 955 |
{%- else -%}
|
| 956 |
{%- set content = '' -%}
|
| 957 |
{%- endif -%}
|