--- base_model: google/gemma-2-2b library_name: transformers tags: - math - reasoning - sft - gemma datasets: - nohurry/Opus-4.6-Reasoning-3000x-filtered language: - en - th license: gemma --- # Gemma-2-2B SFT Reasoning Model A supervised fine-tuned version of [`google/gemma-2-2b`](https://huggingface.co/google/gemma-2-2b), trained to produce structured chain-of-thought reasoning on mathematical and logical problems. > **Model Lineage:** This SFT model serves as the foundation for downstream training: > [**Phonsiri/gemma-2-2b-GRPO-Reasoning-full**](https://huggingface.co/Phonsiri/gemma-2-2b-GRPO-Reasoning-full) --- ## Model Highlights This model was trained to explicitly separate its reasoning process from its final answer, using a structured output format. It learns the **syntax and structure** of chain-of-thought reasoning before any reinforcement signal is applied. **Output Format:** | Section | Tag | Description | |---|---|---| | Chain-of-Thought | ` ... ` | Step-by-step internal reasoning | | Final Answer | ` ... ` | Concise final answer | --- ## Training Details ### Base Model Fine-tuned from [`google/gemma-2-2b-it`](https://huggingface.co/google/gemma-2-2b-it) using full parameter fine-tuning (no LoRA/PEFT). ### Datasets Training data was combined from the following sources: | Dataset | Type | |---|---| | [`nohurry/Opus-4.6-Reasoning-3000x-filtered`](https://huggingface.co/datasets/nohurry/Opus-4.6-Reasoning-3000x-filtered) | HuggingFace — Reasoning | | `math_combined_2566_2567.json` | Local — Thai math problems | | `problems_1_5.json` | Local — Math problems | | `problems_6_10.json` | Local — Math problems | | `problems_101_125.json` | Local — Math problems | | `combined.json` | Local — Combined problems | | `all_solutions.json` | Local — Solutions | ### Hyperparameters | Parameter | Value | |---|---| | Epochs | 3 | | Learning Rate | 2e-5 | | LR Scheduler | Cosine | | Max Seq Length | 8192 | | Batch Size (per device) | 4 | | Gradient Accumulation | 4 | | Effective Batch Size | 16 | | Warmup Ratio | 0.1 | | Weight Decay | 0.01 | | Precision | bfloat16 | | Gradient Checkpointing | Yes | | Attention | SDPA | | Optimizer | AdamW | --- ## Usage ```python from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer import torch model_id = "Phonsiri/gemma-2-2b-SFT-Reasoning-full-Model" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto", torch_dtype=torch.bfloat16 ) system_prompt = ( "You are a helpful assistant. Please reason step by step, " "and put your thoughts within and tags, " "and your final answer within and tags." ) prompt = "Solve for x: 3x + 5 = 20" messages = [{"role": "user", "content": f"{system_prompt}\n\n{prompt}"}] text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) inputs = tokenizer(text, return_tensors="pt").to(model.device) streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False) with torch.no_grad(): model.generate( **inputs, streamer=streamer, max_new_tokens=4096, temperature=0.6, top_p=0.9, repetition_penalty=1.1, ) ``` ### Example Output ``` 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 x = 5 ``` --- ## Acknowledgements **Authors:** - **Phonsiri Thabunsri** — [@Phonsiriwillbejommarn](https://github.com/Phonsiriwillbejommarn) - **CYP777** — [@CYP777](https://github.com/CYP777) **Project Advisor:** - **Supaporn Bunrit, Ph.D.** — Suranaree University of Technology **Institutions & Credits:** - **Suranaree University of Technology (SUT)** — Research support and computing resources - **Google DeepMind** — Open-weights Gemma 2 model