smollm2-sft
A LoRA-adapted SmolLM2-360M-Instruct model fine-tuned on CodeAlpaca-20k.
Model Card
| Property | Value |
|---|---|
| Model type | Causal LM (instruction-tuned) |
| Base model | HuggingFaceTB/SmolLM2-360M-Instruct |
| Fine-tuning method | LoRA (Parameter-Efficient Fine-Tuning) |
| Training data | sahil2801/CodeAlpaca-20k (train[:1000]) |
| LoRA config | r=8, alpha=16, dropout=0.05, target modules q_proj, v_proj |
| Training steps | 250 |
| Batch size | 2 (per device) |
| Gradient accumulation | 4 |
| Loss function | Causal language modeling (labels with -100 for padded tokens) |
| Hardware | Not documented (run with bf16=True) |
How to Use This Model
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# 1. Load the base model
base_model_name = "HuggingFaceTB/SmolLM2-360M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype="auto",
device_map="cpu", # or "cuda" if available
)
# 2. Load the LoRA adapters from the Hub
model = PeftModel.from_pretrained(model, "your-username/smollm2-sft")
# 3. Generate text
prompt = "Write a Python function to find the maximum of three numbers."
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=100, temperature=0.7)
print(tokenizer.decode(output[0], skip_special_tokens=True))
Tips
- The model expects chat-formatted prompts using the SmolLM2 template. The tokenizer's
chat_template.jinjahandles this automatically when usingtokenizer.apply_chat_template(). - LoRA adds minimal overhead (~2-5% latency) during inference.
- To get a fully merged model (no PEFT dependency), run:
model_merged = model.merge_and_unload()
Limitations
- Trained on only 1,000 of 20,000 CodeAlpaca examples – performance may be modest.
- Base model
SmolLM2-360M-Instructhas limited model capacity (360M parameters). - No explicit safety fine-tuning – use appropriate guardrails for production use.
License
- Base model:
SmolLM2– Apache-2.0 - Dataset (
CodeAlpaca-20k): MIT - This model: MIT (or whatever license your data uses)
Citation
If you use this model, please cite the base model and dataset:
@article{smolLM2,
author = {HuggingFaceTB},
title = {SmolLM2: Pure On-device Language Models},
year = {2024},
publisher = {Hugging Face}
}
@dataset{CodeAlpaca-20k,
author = {Sahil2801},
title = {CodeAlpaca-20k},
year = {2023},
publisher = {Hugging Face Datasets}
}