Views
No views yet
<think> … </think> tags before
giving a final answer.<think> / </think> tags followed by the final answer.Trainer.| Hyperparameter | Value |
|---|---|
| Base model | meta-llama/Llama-3.2-3B |
| Precision | bfloat16 |
| Max context length | 4096 tokens |
| Per-device batch size | 8 |
| Gradient accumulation | 8 steps (effective batch ≈ 64) |
| Optimizer | AdamW (fused) |
| Learning rate | 2e-5 |
| LR scheduler | Cosine |
| Warmup steps | 100 |
| Epochs | 1 |
| Attention | SDPA (no Flash-Attention) |
torch.compile | ✅ (Hopper / H100) |
| Gradient checkpointing | ✅ |
<think> prefix) contributes
to the cross-entropy loss. The user / prompt tokens are masked with -100 so the model
learns to reason, not to parrot the prompt.</think> or missing final answer.<think> hardcoded
into the prompt so the model always begins its response with chain-of-thought reasoning.user: {question}
assistant: <think>
{chain-of-thought reasoning}
</think>
{final answer}user: {question}
Think briefly, then give the final numerical answer after ####.
assistant: <think><think> block and then produce the final answer after </think>.#### answer vs. extracted prediction.| Model | Total | Mean Acc | Std |
|---|---|---|---|
| final_model | 1319 | 39.22% | 0.98% |
| checkpoint-1000 | 1319 | 31.13% | 0.72% |
| checkpoint-2000 | 1319 | 33.46% | 0.36% |
| checkpoint-3000 | 1319 | 35.30% | 0.13% |
| checkpoint-4000 | 1319 | 39.93% | 0.95% |
| checkpoint-5000 | 1319 | 38.49% | 0.93% |
| checkpoint-6000 | 1319 | 39.15% | 1.16% |
| checkpoint-7000 | 1319 | 38.77% | 0.48% |
| base_model (no SFT) | 1319 | 7.23% | 0.70% |
Best checkpoint: checkpoint-4000 at 39.93% mean accuracy.
Final merged model: 39.22% — within 1 pp of the best checkpoint.
SFT improved GSM8K accuracy by ~32 percentage points over the base model.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "PursuitOfDataScience/llama3.2-3b-thinking"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13question = "Janet's ducks lay 16 eggs per day. She eats 3 for breakfast and bakes muffins with 4. She sells the remainder at $2 per egg. How much does she make per day?"
14
15prompt = (
16 f"user: {question}\n"
17 f"Think briefly, then give the final numerical answer after ####.\n"
18 f"assistant: <think>\n"
19)
20
21inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
22with torch.no_grad():
23 outputs = model.generate(
24 **inputs,
25 max_new_tokens=1024,
26 temperature=0.6,
27 top_p=0.9,
28 do_sample=True,
29 )
30
31response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
32print(response)