Text Generation
Transformers
Safetensors
apertus
multilingual
compliant
swiss-ai
conversational
6-bit
Instructions to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6") model = AutoModelForCausalLM.from_pretrained("swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6
- SGLang
How to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6 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 "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6" \ --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": "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6", "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 "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6" \ --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": "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6 with Docker Model Runner:
docker model run hf.co/swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6
Download chat_template.jinja from swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6: direct link, hf CLI and curl.
- Browser
- Download file 5.25 kB
-
https://huggingface.co/swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6/resolve/main/chat_template.jinja
- Command line
-
hf download hf://swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6/chat_template.jinja
-
curl -L -o chat_template.jinja https://huggingface.co/swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT6/resolve/main/chat_template.jinja
5.25 kB
| {{ bos_token }}{%- set system_token = '<SPECIAL_61>' -%}{%- set end_system_token = '<SPECIAL_62>' -%}{%- set developer_token = '<SPECIAL_63>' -%}{%- set end_developer_token = '<SPECIAL_64>' -%}{%- set user_token = '<SPECIAL_65>' -%}{%- set end_user_token = '<SPECIAL_66>' -%}{%- set assistant_token = '<SPECIAL_67>' -%}{%- set end_assistant_token = '<SPECIAL_68>' -%}{%- set inner_token = '<SPECIAL_69>' -%}{%- set outer_token = '<SPECIAL_70>' -%}{%- set tool_calls_token = '<SPECIAL_71>' -%}{%- set end_tool_calls_token = '<SPECIAL_72>' -%}{%- if messages and messages[0].role == 'system' -%} {%- set system_content = messages[0].content -%} {{ system_token }} {%- if system_content is string -%} {{ system_content }} {%- elif system_content is mapping and "text" in system_content -%} {{ system_content.text }} {%- else -%} {{- raise_exception("Invalid system content: " + str(system_content)) -}} {%- endif -%} {{ end_system_token }} {%- set messages_without_system = messages[1:] -%}{%- else -%} {{ system_token + end_system_token }} {%- set messages_without_system = messages -%}{%- endif -%}{%- if messages_without_system and messages_without_system[0].role == 'developer' -%} {%- set developer_content = messages_without_system[0].content -%} {{ developer_token }} {%- if "has_thinking" in developer_content -%} {{ 'Deliberation: ' }} {%- if developer_content.has_thinking -%} {{ 'enabled' }} {%- else -%} {{ 'disabled' }} {%- endif -%} {{ ' | |
| ' }} {%- else -%} {{ 'Deliberation: disabled | |
| ' }} {%- endif -%} {%- if "formatted_tools" in developer_content and developer_content.formatted_tools -%} {{ 'Tool Capabilities: | |
| ' + developer_content.formatted_tools }} {%- else -%} {{ 'Tool Capabilities: disabled' }} {%- endif -%} {{ end_developer_token }} {%- set loop_messages = messages_without_system[1:] -%}{%- else -%} {{ developer_token + 'Deliberation: disabled | |
| Tool Capabilities: disabled' + end_developer_token }} {%- set loop_messages = messages_without_system -%}{%- endif -%}{%- for message in loop_messages -%} {%- set content = message.content -%} {%- if message.role == 'user' -%} {{ user_token }} {%- if content is string -%} {{ content }} {%- elif content is sequence -%} {%- for part in content.parts -%} {%- if part.type == 'text' -%} {{ part.text }} {%- endif -%} {%- endfor -%} {%- else -%} {{- raise_exception("Invalid user content: " + str(content)) -}} {%- endif -%} {{ end_user_token }} {%- elif message.role == 'assistant' -%} {{ assistant_token }} {%- if content is string -%} {{ content }} {%- elif content is sequence -%} {%- set ns = namespace(in_inner=false) -%} {%- for block in content.blocks -%} {%- if block.type == 'thoughts' -%} {%- if not ns.in_inner -%} {%- set ns.in_inner = true -%} {{ inner_token }} {%- endif -%} {{ block.text }} {%- elif block.type == 'tool_calls' -%} {%- if ns.in_inner and not loop.first and block.calls|length == 1 and block.calls[0].name == 'display_answers' -%} {%- set ns.in_inner = false -%} {{ outer_token }} {%- endif -%} {{ tool_calls_token + '[' }} {%- for tool_call in block.calls -%} {{- '{"' + tool_call.name + '": ' + tool_call.arguments + '}' }} {%- if not loop.last -%} {{- ", " }} {%- endif -%} {%- endfor -%} {{ ']' + end_tool_calls_token }} {%- elif block.type == 'tool_outputs' -%} {{ '[' }} {%- for tool_output in block.outputs -%} {{- tool_output.output }} {%- if not loop.last -%} {{- ", " }} {%- endif -%} {%- endfor -%} {{- ']' }} {%- if not loop.last -%} {{- ' ' }} {%- endif -%} {%- elif block.type == 'response' -%} {%- if not loop.first and ns.in_inner -%} {%- set ns.in_inner = false -%} {{ outer_token }} {%- endif -%} {{ block.text }} {%- else -%} {{- raise_exception("Invalid block type: " + block.type) -}} {%- endif -%} {%- endfor -%} {%- else -%} {{- raise_exception("Invalid assistant content: " + str(content)) -}} {%- endif -%} {{ end_assistant_token }} {%- else -%} {{- raise_exception("Invalid message role: " + message.role) -}} {%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%} {{ assistant_token }}{%- endif -%} |