A full-parameter reasoning fine-tune of
HuggingFaceTB/SmolLM2-135M-Instruct using 5,000 examples
sampled from
SupraLabs/reasoning-corpus-4K-5M-v1.
The system and user portions were masked from the loss. Samples exceeding the
maximum context length were rejected instead of being cut through the middle of
a reasoning trace.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "YOUR_USERNAME/SmolLM2-135M-Reasoning-5K"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype="auto",
10 device_map="auto",
11)
12
13messages = [
14 {
15 "role": "system",
16 "content": 'You are a helpful AI assistant. For difficult problems, reason carefully inside <think> and </think> tags, then provide a clear final answer.',
17 },
18 {
19 "role": "user",
20 "content": "A farmer has 17 sheep. All but 9 run away. How many remain?",
21 },
22]
23
24inputs = tokenizer.apply_chat_template(
25 messages,
26 tokenize=True,
27 add_generation_prompt=True,
28 return_tensors="pt",
29 return_dict=True,
30).to(model.device)
31
32with torch.inference_mode():
33 output = model.generate(
34 **inputs,
35 max_new_tokens=256,
36 do_sample=False,
37 repetition_penalty=1.05,
38 )
39
40new_tokens = output[0, inputs["input_ids"].shape[1]:]
41print(tokenizer.decode(new_tokens, skip_special_tokens=False))
1<think>
2Internal reasoning trace
3</think>
4
5Final answer
This small model is experimental. It should not be assumed to produce correct
reasoning merely because it emits a structured reasoning trace.
The model follows the Apache 2.0 license used by the base SmolLM2 model. Review
the base model repository and source dataset for their complete terms.