smollm2_1_7b-alpaca-it
HuggingFaceTB/SmolLM2-1.7B-Instruct fully fine-tuned on Stanford Alpaca with torchdistill.
It is the task-adapted teacher for the knowledge distillation (KD) configs configs/sample/alpaca/on_policy_kd/smollm2_135m_from_smollm2_1_7b.yaml and configs/sample/alpaca/off_policy_kd/smollm2_135m_from_smollm2_1_7b.yaml, which load it from the Hub. The off-the-shelf instruct checkpoint never saw Alpaca's reference style, so its KL term would pull the student toward a distribution the task loss pulls it away from; fine-tuning the teacher on the same data first removes that conflict.
Model details
| Base model | HuggingFaceTB/SmolLM2-1.7B-Instruct (1.7B parameters, Llama architecture) |
| Fine-tuning | Full-parameter instruction tuning, cross-entropy on response tokens only |
| Training data | tatsu-lab/alpaca, 90% of the train split (46,801 examples) |
| Language | English |
| Context used in training | 512 tokens (prompt up to 256) |
| Weights | model.safetensors, float32 |
| License | CC BY-NC 4.0 (see License) |
Usage
The model was trained with the system prompt "You are a helpful assistant.". The bundled chat template falls back
to SmolLM's default system prompt when none is given, so pass the training one explicitly:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = 'yoshitomo-matsubara/smollm2_1_7b-alpaca-it'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype='bfloat16', device_map='auto')
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Give three tips for staying healthy.'},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors='pt', return_dict=True
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True))
The tokenizer pads on the right (the default). That is fine for a single prompt, but for batched generation set left padding, so that every prompt ends at the last position and generation continues from the prompt rather than from pad tokens:
tokenizer.padding_side = 'left'
batch = [
[{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': instruction}]
for instruction in ['Give three tips for staying healthy.', 'What is the capital of France?']
]
inputs = tokenizer.apply_chat_template(
batch, add_generation_prompt=True, padding=True, return_tensors='pt', return_dict=True
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.batch_decode(outputs[:, inputs['input_ids'].shape[1]:], skip_special_tokens=True))
Training itself used left padding too (torchdistill's instruction pipeline sets it for batched on-policy rollouts), but the side does not matter there: padded positions are excluded by the attention mask and from the loss.
Training data and split
tatsu-lab/alpaca ships only a train split (52,002 examples), so it was split 90/5/5 into train, validation and
test at run time with torchdistill's split_dataset (lengths: [90, 5, 5], generator_seed: 42). The equivalent
in plain PyTorch:
import torch
from datasets import load_dataset
from torch.utils.data import random_split
dataset = load_dataset('tatsu-lab/alpaca', split='train', revision='dce01c9b08f87459cf36a430d809084718273017')
subsets = random_split(dataset, [46801, 2600, 2601], generator=torch.Generator().manual_seed(42))
train, validation, test = (dataset.select(subset.indices) for subset in subsets)
# train: 46,801 examples, validation: 2,600 examples, test: 2,601 examples
The training run did not pin revision; the commit above is the one it resolved to. The same seed reproduces the
same split only for the same dataset revision (and a PyTorch version that keeps the randperm stream unchanged).
The SmolLM2 Alpaca models (the 135M baseline, the 360M and 1.7B teachers and the distilled 135M students) all use
this split.
Each example is formatted with SmolLM2's chat template: the system prompt above, the instruction field as the
user turn (prompt_key: 'instruction') and the output field as the assistant turn (response_key: 'output').
Prompt tokens are masked out of the loss.
Training procedure
| Hyperparameter | Value |
|---|---|
| Epochs | 3 (checkpoint kept from epoch 1, see Evaluation) |
| Optimizer | AdamW, lr 1e-5, weight decay 0.0 |
| Schedule | Linear decay with 100 warmup steps |
| Batch size | 4 per device x 2 device(s) x gradient accumulation 4 = 32 |
| Gradient clipping | max norm 1.0 |
| Precision | fp32 master weights, bf16 autocast |
| Hardware | 2x 24 GB GPUs, FSDP FULL_SHARD (LlamaDecoderLayer auto-wrap, full state dict), bf16 mixed precision |
| Time per epoch | ~1 h 34 min |
| Seed | 42 |
The full torchdistill config, CLI arguments, training log and per-step metrics are in logs/:
config.yaml, args.json, train.log, metrics.json and trackio/summary.csv. To reproduce the run with
torchdistill, use the command in the header of logs/config.yaml.
Evaluation
Perplexity over the response tokens. The 2,600-example validation split was measured after each epoch and used to pick the checkpoint:
| Epoch | Validation perplexity |
|---|---|
| 1 (released) | 3.7859 |
| 2 | 3.8101 |
| 3 | 3.9677 |
The checkpoint with the lowest validation perplexity (epoch 1) is the one released here. Evaluated once on the 2,601-example test split, its perplexity is 3.8179.
The test split is disjoint from both the training data and the checkpoint selection, so this is a held-out score;
it is still in-distribution (Alpaca-style instructions and text-davinci-003 references). Both validation and
test perplexities come from the 2-process distributed evaluation. No downstream benchmarks (e.g. AlpacaEval,
MT-Bench) have been run.
Limitations
- Alpaca's responses were generated by OpenAI's
text-davinci-003and inherit its factual errors, biases and short, generic style. The model may produce incorrect, harmful or biased text. - No safety tuning was performed beyond what the base SmolLM2-Instruct model already has.
- English only; trained on sequences of at most 512 tokens.
- Validation perplexity rose in epoch 3, so three epochs over-train at this learning rate.
- Intended for research, in particular as a reference point for knowledge-distillation experiments. Not intended for production or commercial use.
License
The weights are released under CC BY-NC 4.0 (LICENSE),
because the training data, tatsu-lab/alpaca, is licensed under CC BY-NC 4.0 and its outputs were generated with
OpenAI's text-davinci-003, whose terms restrict use for developing competing models.
This model is a modification of HuggingFaceTB/SmolLM2-1.7B-Instruct by Hugging Face, which is licensed under the
Apache License 2.0; a copy is included in LICENSE.SmolLM2. The modification is full-parameter
fine-tuning on the data described above.
Citation
If you use this model, please cite torchdistill, as well as SmolLM2 and Alpaca:
@inproceedings{matsubara2021torchdistill,
title={torchdistill: A Modular, Configuration-Driven Framework for Knowledge Distillation},
author={Matsubara, Yoshitomo},
booktitle={International Workshop on Reproducible Research in Pattern Recognition},
pages={24--44},
year={2021},
organization={Springer}
}
@inproceedings{matsubara2023torchdistill,
title={{torchdistill Meets Hugging Face Libraries for Reproducible, Coding-Free Deep Learning Studies: A Case Study on NLP}},
author={Matsubara, Yoshitomo},
booktitle={Proceedings of the 3rd Workshop for Natural Language Processing Open Source Software (NLP-OSS 2023)},
publisher={Empirical Methods in Natural Language Processing},
pages={153--164},
year={2023}
}
@misc{allal2025smollm2,
title={SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model},
author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Gabriel Mart\'in Bl\'azquez and Guilherme Penedo and Lewis Tunstall and Andr\'es Marafioti and Hynek Kydl\'i\v{c}ek and Agust\'in Piqueres Lajar\'in and Vaibhav Srivastav and Joshua Lochner and Caleb Fahlgren and Xuan-Son Nguyen and Cl\'ementine Fourrier and Ben Burtenshaw and Hugo Larcher and Haojun Zhao and Cyril Zakka and Mathieu Morlon and Colin Raffel and Leandro von Werra and Thomas Wolf},
year={2025},
eprint={2502.02737},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@misc{alpaca,
author={Rohan Taori and Ishaan Gulrajani and Tianyi Zhang and Yann Dubois and Xuechen Li and Carlos Guestrin and Percy Liang and Tatsunori B. Hashimoto},
title={Stanford Alpaca: An Instruction-following LLaMA model},
year={2023},
publisher={GitHub},
journal={GitHub repository},
howpublished={\url{https://github.com/tatsu-lab/stanford_alpaca}}
}