smol-math-sft-merged
SmolLM2-1.7B fine-tuned for math reasoning with SFT + LoRA, then merged into the base weights.
Model Details
- Developed by: yas1988
- Model type: causal language model (Llama architecture)
- Language: English
- License: Apache 2.0 (same as the base model)
- Finetuned from: HuggingFaceTB/SmolLM2-1.7B
- Part of: Hugging Face smol course, Chapter 1 submission
Uses
Direct use: step-by-step solutions to grade-school math word problems.
Out of scope: it is a small model. It can make arithmetic and reasoning mistakes, so don't use it for anything where a wrong answer matters. It was not trained for general chat, safety alignment or other languages.
How to use
from transformers import pipeline
pipe = pipeline("text-generation", model="yas1988/smol-math-sft-merged", device_map="auto")
msgs = [{"role": "user", "content": "Tom has 5 apples and buys 3 more. How many does he have?"}]
print(pipe(msgs, max_new_tokens=200, return_full_text=False)[0]["generated_text"])
Training Details
- Method: SFT with LoRA (TRL
SFTTrainer), adapter merged into the base weights afterwards - Data: first 20,000 samples of the
metamathqa-50ksubset ofHuggingFaceTB/smoltalk(math reasoning, chat format) - LoRA: r=16, alpha=32, dropout 0.05, target modules
all-linear - Hyperparameters: 1 epoch (1,250 steps), learning rate 2e-4, per-device batch 2 x gradient accumulation 8 (effective batch 16), fp16, gradient checkpointing, max length 1024
- Chat template: copied from SmolLM2-1.7B-Instruct, since the base model has none
- Training loss: 2.03 -> 0.38 (smooth, no spikes)
- Training time: about 1 h 50 min on one Colab T4 GPU
- Generation fix:
<|im_end|>set as the end-of-sequence token (tokenizer,config.json,generation_config.json) so the model stops after its answer instead of repeating it
Evaluation
- Benchmark: GSM8K, 0-shot, full test set (1,319 questions)
- Metric: extractive_match
- Result: 0.4268 ± 0.0136
- Results dataset: yas1988/details_yas1988__smol-math-sft-merged_private
Command (Colab T4):
lighteval accelerate \
"model_name=yas1988/smol-math-sft-merged,dtype=float16" \
"gsm8k|0" \
--push-to-hub --results-org yas1988
Limitations
- Trained for one epoch on a 20k subset, so there is room for improvement with more data or epochs.
- LoRA changes only a small set of weights, so the model is mostly the base model plus a math-style update.
- Outputs follow the MetaMathQA style (
#### answerandThe answer is: ...).
Software
TRL, PEFT, Transformers and PyTorch on Google Colab.
Base model comparison
| Model | GSM8K (0-shot, 1,319 questions) |
|---|---|
| Base SmolLM2-1.7B | 0.0872 ± 0.0078 |
| This model (v1, submitted) | 0.4268 ± 0.0136 |
Part of the gain is format: the base model has no chat template or stop token and often rambles, while the tuned model reasons step by step and ends with "#### answer".
Further attempts to improve this model
| Version | Model | What I did | GSM8K |
|---|---|---|---|
| v2 | smol-math-sft-v2-merged | Continued from v1 on 15,000 more MetaMathQA examples it had not seen (LoRA r=32) | 0.4428 |
| v3 | smol-math-sft-v3-merged | Continued from v2 on the GSM8K train split, 2 epochs, answer-only loss | 0.3571 (worse, probably overfitting) |
- v2 results: dataset, adapter: smol-math-sft-v2
- v3 results: dataset, adapter: smol-math-sft-v3
v2 is only about 1.6 points above v1, which is within the margin of error, so I kept v1 as my submission (leaderboard PR #98).
Before/after samples (base vs this model, 8 GSM8K test questions)
Base model: 0/8 (bare guesses such as "$16", and one question where it loops forever). This model: 4/8, with step-by-step reasoning ending in "#### answer", for example Janet's ducks (answer 18) and the robe question (answer 3).