smollm2-sft
Compact coding adapter for SmolLM2
1 min readupdated
This is a LoRA (a lightweight add-on for a base model) built on the SmolLM2-360M-Instruct language model and fine-tuned on the CodeAlpaca-20k dataset for programming tasks. It generates code and answers technical queries on top of an ultra-compact 360M-parameter model. The adapter is aimed at developers and hobbyists who need a lightweight setup for local coding experiments.
Key features
- Base: SmolLM2-360M-Instruct
- Method: LoRA configured with r=8 and alpha=16
- Training: fine-tuned on 1,000 samples from CodeAlpaca-20k
- Efficiency: minimal system requirements to run on a CPU or GPU
What you can do
- Generate a function or simple script from a text description
- Attach the adapter to the base model using the peft library
- Merge the adapter weights into the base model via merge_and_unload()
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
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",
)
model = PeftModel.from_pretrained(model, "your-username/smollm2-sft")
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))Read more
DetailsTraining: 250 steps, batch size 2, gradient accumulation steps 4
Limitations: trained on 1,000 samples with a modest 360M base capacity
License: MIT










Comments