Text Generation
Transformers
ONNX
Safetensors
English
llama
alignment-handbook
trl
sft
conversational
text-generation-inference
Instructions to use HuggingFaceTB/SmolLM-360M-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceTB/SmolLM-360M-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HuggingFaceTB/SmolLM-360M-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM-360M-Instruct") model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM-360M-Instruct") 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
- vLLM
How to use HuggingFaceTB/SmolLM-360M-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceTB/SmolLM-360M-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceTB/SmolLM-360M-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HuggingFaceTB/SmolLM-360M-Instruct
- SGLang
How to use HuggingFaceTB/SmolLM-360M-Instruct 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 "HuggingFaceTB/SmolLM-360M-Instruct" \ --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": "HuggingFaceTB/SmolLM-360M-Instruct", "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 "HuggingFaceTB/SmolLM-360M-Instruct" \ --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": "HuggingFaceTB/SmolLM-360M-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HuggingFaceTB/SmolLM-360M-Instruct with Docker Model Runner:
docker model run hf.co/HuggingFaceTB/SmolLM-360M-Instruct
Update README.md
Browse files
README.md
CHANGED
|
@@ -29,70 +29,6 @@ To build SmolLM-Instruct, we instruction tuned the models using publicly availab
|
|
| 29 |
|
| 30 |
This is the SmolLM-360M-Instruct.
|
| 31 |
|
| 32 |
-
### Generation
|
| 33 |
-
```bash
|
| 34 |
-
pip install transformers
|
| 35 |
-
```
|
| 36 |
-
|
| 37 |
-
#### Running the model on CPU/GPU/multi GPU
|
| 38 |
-
* _Using full precision_
|
| 39 |
-
```python
|
| 40 |
-
# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main
|
| 41 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 42 |
-
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
| 43 |
-
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
| 44 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 45 |
-
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
|
| 46 |
-
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
| 47 |
-
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
|
| 48 |
-
outputs = model.generate(inputs)
|
| 49 |
-
print(tokenizer.decode(outputs[0]))
|
| 50 |
-
```
|
| 51 |
-
```bash
|
| 52 |
-
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
| 53 |
-
Memory footprint: 12624.81 MB
|
| 54 |
-
```
|
| 55 |
-
* _Using `torch.bfloat16`_
|
| 56 |
-
```python
|
| 57 |
-
# pip install accelerate
|
| 58 |
-
import torch
|
| 59 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 60 |
-
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
| 61 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 62 |
-
# for fp16 use `torch_dtype=torch.float16` instead
|
| 63 |
-
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
|
| 64 |
-
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
| 65 |
-
outputs = model.generate(inputs)
|
| 66 |
-
print(tokenizer.decode(outputs[0]))
|
| 67 |
-
```
|
| 68 |
-
```bash
|
| 69 |
-
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
| 70 |
-
Memory footprint: 269.03 MB
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
#### Quantized Versions through `bitsandbytes`
|
| 74 |
-
* _Using 8-bit precision (int8)_
|
| 75 |
-
|
| 76 |
-
```python
|
| 77 |
-
# pip install bitsandbytes accelerate
|
| 78 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 79 |
-
# to use 4bit use `load_in_4bit=True` instead
|
| 80 |
-
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
| 81 |
-
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
| 82 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 83 |
-
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
|
| 84 |
-
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
| 85 |
-
outputs = model.generate(inputs)
|
| 86 |
-
print(tokenizer.decode(outputs[0]))
|
| 87 |
-
```
|
| 88 |
-
```bash
|
| 89 |
-
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
| 90 |
-
# load_in_8bit
|
| 91 |
-
Memory footprint: 162.87 MB
|
| 92 |
-
# load_in_4bit
|
| 93 |
-
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
| 94 |
-
Memory footprint: 109.78 MB
|
| 95 |
-
```
|
| 96 |
|
| 97 |
# Limitations
|
| 98 |
|
|
|
|
| 29 |
|
| 30 |
This is the SmolLM-360M-Instruct.
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Limitations
|
| 34 |
|