Text Generation
PyTorch
ExecuTorch
Transformers
optimum-executorch
smollm3
smollm
conversational
torchao
Instructions to use pytorch/SmolLM3-3B-INT8-INT4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pytorch/SmolLM3-3B-INT8-INT4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pytorch/SmolLM3-3B-INT8-INT4") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("pytorch/SmolLM3-3B-INT8-INT4") model = AutoModelForCausalLM.from_pretrained("pytorch/SmolLM3-3B-INT8-INT4", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pytorch/SmolLM3-3B-INT8-INT4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pytorch/SmolLM3-3B-INT8-INT4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pytorch/SmolLM3-3B-INT8-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/pytorch/SmolLM3-3B-INT8-INT4
- SGLang
How to use pytorch/SmolLM3-3B-INT8-INT4 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 "pytorch/SmolLM3-3B-INT8-INT4" \ --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": "pytorch/SmolLM3-3B-INT8-INT4", "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 "pytorch/SmolLM3-3B-INT8-INT4" \ --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": "pytorch/SmolLM3-3B-INT8-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use pytorch/SmolLM3-3B-INT8-INT4 with Docker Model Runner:
docker model run hf.co/pytorch/SmolLM3-3B-INT8-INT4
Updated model card
Browse files
README.md
CHANGED
|
@@ -11,25 +11,23 @@ tags:
|
|
| 11 |
- smollm
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
Once ExecuTorch is [set-up](https://pytorch.org/executorch/main/getting-started.html), you can directly download the `*.pte` and tokenizer file and run the model in a mobile app (see [Running in a mobile app](#running-in-a-mobile-app)).
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
```Py
|
| 29 |
-
python install_dev.py
|
| 30 |
-
```
|
| 31 |
|
| 32 |
-
|
| 33 |
```Shell
|
| 34 |
optimum-cli export executorch \
|
| 35 |
--model HuggingFaceTB/SmolLM3-3B \
|
|
|
|
| 11 |
- smollm
|
| 12 |
---
|
| 13 |
|
| 14 |
+
[HuggingFaceTB/SmolLM3-3B](https://huggingface.co/HuggingFaceTB/SmolLM3-3B) is quantized using [torchao](https://huggingface.co/docs/transformers/main/en/quantization/torchao) with 8-bit embeddings and 8-bit dynamic activations with 4-bit weight linears (`8da4w`). It is then lowered to [ExecuTorch](https://github.com/pytorch/executorch) with several optimizations—custom SPDA, custom KV cache, and parallel prefill—to achieve high performance on the CPU backend, making it well-suited for mobile deployment.
|
| 15 |
|
| 16 |
+
We provide the [.pte file](https://huggingface.co/pytorch/SmolLM3-3B-8da4w/blob/main/smollm3-3b-8da4w.pte) for direct use in ExecuTorch. *(The provided pte file is exported with the default max_seq_length/max_context_length of 2k.)*
|
|
|
|
| 17 |
|
| 18 |
+
# Running in a mobile app
|
| 19 |
+
The [.pte file](https://huggingface.co/pytorch/Phi-4-mini-instruct-8da4w/blob/main/phi4-mini-8da4w.pte) can be run with ExecuTorch on a mobile phone. See the instructions for doing this in [iOS](https://pytorch.org/executorch/main/llm/llama-demo-ios.html) and [Android](https://docs.pytorch.org/executorch/main/llm/llama-demo-android.html).
|
| 20 |
|
| 21 |
+
On Google's Pixel 8 Pro, the model runs at 12.7 tokens/s.
|
| 22 |
|
| 23 |
+
# Running with ExecuTorch’s sample runner
|
| 24 |
+
You can also run this model using ExecuTorch’s sample runner following [Step 3&4 in this instruction](https://github.com/pytorch/executorch/blob/main/examples/models/llama/README.md#step-3-run-on-your-computer-to-validate)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Export Recipe
|
| 28 |
+
You can re-create the `.pte` file from eager source using this export recipe.
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
First install `optimum-executorch` by following this [instruction](https://github.com/huggingface/optimum-executorch?tab=readme-ov-file#-quick-installation), then you can use `optimum-cli` to export the model to ExecuTorch:
|
| 31 |
```Shell
|
| 32 |
optimum-cli export executorch \
|
| 33 |
--model HuggingFaceTB/SmolLM3-3B \
|