A highly customized version of google/gemma-2-2b-it, extended through Reinforcement Learning (GRPO) to excel at structured mathematical reasoning and logic tasks. The model's reasoning capability was further enhanced via knowledge distillation from google/gemma-2-27b-it.
Unlike standard instruction-tuned models that jump straight to an answer, this model is trained to show its work. By explicitly laying out each reasoning step before answering, it performs significantly better on math, logic, and analytical problem-solving.
Output Format:
Section
Tag
Description
Chain-of-Thought
<reasoning> ... </reasoning>
Step-by-step internal reasoning
Final Answer
<answer> ... </answer> or \boxed{}
Concise, boxed final answer
Training Pipeline
This model is the result of a two-stage training framework:
Stage 1 Supervised Fine-Tuning (SFT)
The base model (Phonsiri/gemma-2-2b-SFT-Reasoning-full-Model) was fine-tuned on open-r1/OpenR1-Math-220k, formatted explicitly with <reasoning> and <answer> tags. This stage taught the model the structure of reasoning syntax without yet enforcing correctness.
Building on the SFT base, the model underwent RL training with a custom reward structure:
Reward
Condition
+2.0
Final boxed answer mathematically matches ground truth
+1.0
Strict adherence to <reasoning> XML formatting structure
Quickstart
Important: Use skip_special_tokens=False in the streamer to see the <reasoning> tags in output.
python
1from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
2import torch
34model_id ="Phonsiri/gemma-2-2b-GRPO-Reasoning-full"56tokenizer = AutoTokenizer.from_pretrained(model_id)7model = AutoModelForCausalLM.from_pretrained(8 model_id,9 device_map="auto",10 torch_dtype=torch.bfloat16
11)1213system_prompt =(14"You are a helpful assistant. Please reason step by step, "15"and put your thoughts within <reasoning> and </reasoning> tags, "16"and your final answer within <answer> and </answer> tags or \\boxed{}."17)18prompt ="Solve for x: 3x + 5 = 20"1920messages =[{"role":"user","content":f"{system_prompt}\n\n{prompt}"}]2122text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)23inputs = tokenizer(text, return_tensors="pt").to(model.device)2425streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False)2627with torch.no_grad():28 model.generate(29**inputs,30 streamer=streamer,31 max_new_tokens=4096,32 temperature=0.6,33 top_p=0.9,34 repetition_penalty=1.1,35)
Example Output
<reasoning>
We need to isolate x on one side of the equation.
Step 1: Subtract 5 from both sides.
3x + 5 - 5 = 20 - 5
3x = 15
Step 2: Divide both sides by 3.
x = 15 / 3
x = 5
</reasoning>
<answer> x = 5 </answer>