Tiny Models
Collection
Tiny models used for testing • 4 items • Updated
How to use inference-optimization/Llama-3.2-0.5B-Instruct with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="inference-optimization/Llama-3.2-0.5B-Instruct")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForMultimodalLM
tokenizer = AutoTokenizer.from_pretrained("inference-optimization/Llama-3.2-0.5B-Instruct")
model = AutoModelForMultimodalLM.from_pretrained("inference-optimization/Llama-3.2-0.5B-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]:]))How to use inference-optimization/Llama-3.2-0.5B-Instruct with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "inference-optimization/Llama-3.2-0.5B-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": "inference-optimization/Llama-3.2-0.5B-Instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/inference-optimization/Llama-3.2-0.5B-Instruct
How to use inference-optimization/Llama-3.2-0.5B-Instruct with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "inference-optimization/Llama-3.2-0.5B-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": "inference-optimization/Llama-3.2-0.5B-Instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "inference-optimization/Llama-3.2-0.5B-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": "inference-optimization/Llama-3.2-0.5B-Instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use inference-optimization/Llama-3.2-0.5B-Instruct with Docker Model Runner:
docker model run hf.co/inference-optimization/Llama-3.2-0.5B-Instruct
This is a tiny version of meta-llama/Llama-3.2-1B-Instruct created for testing and development.
The following parameters were reduced from the original model:
| Parameter | Original | Tiny |
|---|---|---|
| num_hidden_layers | 16 | 4 |
| hidden_size | 2048 | 2048 |
| intermediate_size | 8192 | 8192 |
| num_attention_heads | 32 | 32 |
| num_key_value_heads | 8 | 8 |
This model uses a single model.safetensors file containing all weights. The checkpoint structure is identical to the original model, with the standard Llama architecture tensors:
model.embed_tokens.weightmodel.layers.*.self_attn.{q,k,v,o}_proj.weightmodel.layers.*.mlp.{gate,up,down}_proj.weightmodel.layers.*.{input,post_attention}_layernorm.weightmodel.norm.weightfrom transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("inference-optimization/Llama-3.2-0.5B-Instruct", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("inference-optimization/Llama-3.2-0.5B-Instruct")
input_ids = tokenizer("According to all known laws", return_tensors="pt").input_ids.to(model.device)
output = model.generate(input_ids, max_new_tokens=20)
print(tokenizer.decode(output[0]))
Success: 1.0247299671173096 <= 10.0
==================================================
Generating sample text:
According to all known laws of aviation, there is no way a bee should be able to fly
==================================================
This model was created using the llm-compressor create-tiny-model claude skill:
num_hidden_layers from 16 to 4Base model
meta-llama/Llama-3.2-1B-Instruct