Text Generation
Transformers
Safetensors
apertus
multilingual
compliant
swiss-ai
conversational
3-bit
Instructions to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3 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-INT3 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-INT3") 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-INT3") model = AutoModelForCausalLM.from_pretrained("swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3", 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-INT3 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-INT3" # 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-INT3", "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-INT3
- SGLang
How to use swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3 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-INT3" \ --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-INT3", "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-INT3" \ --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-INT3", "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-INT3 with Docker Model Runner:
docker model run hf.co/swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3
Update README for swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3
Browse files
README.md
CHANGED
|
@@ -54,7 +54,7 @@ Instead of standard pre-training, Apertus-v1.1 models were created using pre-tra
|
|
| 54 |
|
| 55 |
This model family includes base pre-trained models and instruction-tuned models.
|
| 56 |
|
| 57 |
-
For instruction-tuned models, we additionally provide high-quality quantization-aware distillation (QAD) checkpoints, obtained via the official [`qat-suite`](https://github.com/swiss-ai/qat-suite). We provide FP8 and NVFP4A16 checkpoints with vLLM inference in mind and INT3-6 checkpoints optimized for mobile usage on Apple devices.
|
| 58 |
|
| 59 |
The full list of released checkpoints is shown below:
|
| 60 |
|
|
@@ -73,22 +73,18 @@ For more details refer to the original Apertus [technical report](https://arxiv.
|
|
| 73 |
|
| 74 |
## How to use
|
| 75 |
|
| 76 |
-
The modeling code for Apertus is available
|
| 77 |
```bash
|
| 78 |
-
pip install -
|
| 79 |
```
|
| 80 |
|
| 81 |
```python
|
| 82 |
-
from
|
| 83 |
|
| 84 |
model_name = "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3"
|
| 85 |
-
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
| 86 |
|
| 87 |
-
# load the
|
| 88 |
-
tokenizer =
|
| 89 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 90 |
-
model_name,
|
| 91 |
-
).to(device)
|
| 92 |
|
| 93 |
# prepare the model input
|
| 94 |
prompt = "Give me a brief explanation of gravity in simple terms."
|
|
@@ -101,14 +97,9 @@ text = tokenizer.apply_chat_template(
|
|
| 101 |
tokenize=False,
|
| 102 |
add_generation_prompt=True,
|
| 103 |
)
|
| 104 |
-
model_inputs = tokenizer([text], return_tensors="pt", add_special_tokens=False).to(model.device)
|
| 105 |
|
| 106 |
# Generate the output
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# Get and decode the output
|
| 110 |
-
output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
|
| 111 |
-
print(tokenizer.decode(output_ids, skip_special_tokens=True))
|
| 112 |
```
|
| 113 |
|
| 114 |
>[!TIP]
|
|
|
|
| 54 |
|
| 55 |
This model family includes base pre-trained models and instruction-tuned models.
|
| 56 |
|
| 57 |
+
For instruction-tuned models, we additionally provide high-quality quantization-aware distillation (QAD) checkpoints, obtained via the official [`qat-suite`]([https://github.com/swiss-ai/qat-suite](https://github.com/swiss-ai/qat-suite)). We provide FP8 and NVFP4A16 checkpoints with vLLM inference in mind and INT3-6 checkpoints optimized for mobile usage on Apple devices.
|
| 58 |
|
| 59 |
The full list of released checkpoints is shown below:
|
| 60 |
|
|
|
|
| 73 |
|
| 74 |
## How to use
|
| 75 |
|
| 76 |
+
The modeling code for this Apertus MLX quantization is available via `mlx-lm`.
|
| 77 |
```bash
|
| 78 |
+
pip install mlx-lm
|
| 79 |
```
|
| 80 |
|
| 81 |
```python
|
| 82 |
+
from mlx_lm import load, generate
|
| 83 |
|
| 84 |
model_name = "swiss-ai/Apertus-v1.1-0.5B-Instruct-MLX-INT3"
|
|
|
|
| 85 |
|
| 86 |
+
# load the model and tokenizer
|
| 87 |
+
model, tokenizer = load(model_name)
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# prepare the model input
|
| 90 |
prompt = "Give me a brief explanation of gravity in simple terms."
|
|
|
|
| 97 |
tokenize=False,
|
| 98 |
add_generation_prompt=True,
|
| 99 |
)
|
|
|
|
| 100 |
|
| 101 |
# Generate the output
|
| 102 |
+
response = generate(model, tokenizer, prompt=text, verbose=True, max_tokens=32768)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
```
|
| 104 |
|
| 105 |
>[!TIP]
|