A LoRA-adapted SmolLM2-360M-Instruct model fine-tuned on CodeAlpaca-20k.
| 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) |
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))
chat_template.jinja handles this automatically when using tokenizer.apply_chat_template().model_merged = model.merge_and_unload()
SmolLM2-360M-Instruct has limited model capacity (360M parameters).SmolLM2 – Apache-2.0CodeAlpaca-20k): MITIf 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}
}
HuggingFaceTB/SmolLM2-360M-Instruct