Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
base_model: Qwen/Qwen3.5-0.8B
|
| 6 |
+
tags:
|
| 7 |
+
- reasoning
|
| 8 |
+
- math
|
| 9 |
+
- grpo
|
| 10 |
+
- reinforcement-learning
|
| 11 |
+
- rlvr
|
| 12 |
+
- qwen3.5
|
| 13 |
+
datasets:
|
| 14 |
+
- gsm8k
|
| 15 |
+
- zosmaai/Qwen3.5-0.8B-GRPO-Math-Dataset
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# Qwen3.5-0.8B-GRPO-Math
|
| 20 |
+
|
| 21 |
+
A reasoning-enhanced version of [Qwen3.5-0.8B](https://huggingface.co/Qwen/Qwen3.5-0.8B), trained using **GRPO (Group Relative Policy Optimization)** β the RL technique behind DeepSeek-R1 β on a single RTX 5090 at [Zosma AI](https://zosma.ai).
|
| 22 |
+
|
| 23 |
+
Also available at: [celestialcreator/Qwen3.5-0.8B-GRPO-Math](https://huggingface.co/celestialcreator/Qwen3.5-0.8B-GRPO-Math)
|
| 24 |
+
|
| 25 |
+
## Results
|
| 26 |
+
|
| 27 |
+
| Eval Setting | GSM8K Accuracy | Notes |
|
| 28 |
+
|---|:-:|---|
|
| 29 |
+
| Baseline 8-shot CoT | 53.5% | Pre-trained, no fine-tuning |
|
| 30 |
+
| Baseline zero-shot | 52.1% | Pre-trained, no fine-tuning |
|
| 31 |
+
| **GRPO zero-shot** | **58.0% (+5.9pp)** | Best result β model reasons autonomously |
|
| 32 |
+
| GRPO 8-shot (plain format) | 50.4% (-3.1pp) | Few-shot examples conflict with learned policy |
|
| 33 |
+
| GRPO 8-shot (`<think>` aligned) | 34.1% (-19.4pp) | Format-aligned examples hurt even more |
|
| 34 |
+
|
| 35 |
+
### Key Finding: Demonstration to Policy Shift
|
| 36 |
+
|
| 37 |
+
GRPO training shifted the model from **demonstration-based reasoning** to **policy-based reasoning**.
|
| 38 |
+
|
| 39 |
+
After training, the model:
|
| 40 |
+
- **Performs best in zero-shot** β it reasons autonomously using `<think>` tags
|
| 41 |
+
- **Is hurt by few-shot examples** β any demonstrations conflict with its learned internal reasoning policy
|
| 42 |
+
- **Is hurt even more by format-aligned few-shot** β `<think>` tags in examples caused the model to confuse context with its own generation, dropping to 34.1%
|
| 43 |
+
|
| 44 |
+
This mirrors what DeepSeek-R1 demonstrated at 670B scale.
|
| 45 |
+
|
| 46 |
+
## Training Pipeline
|
| 47 |
+
|
| 48 |
+
### Phase 1: SFT Warmup
|
| 49 |
+
- **Data:** [3,558 reasoning examples](https://huggingface.co/datasets/zosmaai/Qwen3.5-0.8B-GRPO-Math-Dataset) from 3 sources, standardized to `<think>` tags
|
| 50 |
+
- **Purpose:** Solve the cold-start problem β teach the 0.8B model `<think>` tag format before RL exploration
|
| 51 |
+
- **Stats:** 1 epoch, loss 0.932, 78% token accuracy
|
| 52 |
+
|
| 53 |
+
### Phase 2: GRPO Training
|
| 54 |
+
- **Data:** GSM8K train split (7,473 math word problems)
|
| 55 |
+
- **Rewards:** Math correctness (1.0/0.0) + format reward (0.3 for `<think>` tags, 0.2 for `####` answer)
|
| 56 |
+
- **Config:** 8 generations/prompt, batch size 1 x 8 grad accum, lr 1e-6, beta=0.04
|
| 57 |
+
- **Hardware:** Single NVIDIA RTX 5090 (32GB VRAM)
|
| 58 |
+
- **Duration:** ~77 hours, 15,900 steps (epoch 2.13)
|
| 59 |
+
|
| 60 |
+
## Usage
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 64 |
+
|
| 65 |
+
model_name = "zosmaai/Qwen3.5-0.8B-GRPO-Math"
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 67 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 68 |
+
model_name,
|
| 69 |
+
torch_dtype="auto",
|
| 70 |
+
device_map="auto",
|
| 71 |
+
trust_remote_code=True,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# Best used in zero-shot β the model has its own reasoning policy
|
| 75 |
+
messages = [
|
| 76 |
+
{"role": "system", "content": "You are a helpful assistant that thinks step by step. Show your reasoning inside <think> tags before giving your final answer. End math answers with: #### <number>"},
|
| 77 |
+
{"role": "user", "content": "If a train travels at 60 mph for 2.5 hours, how far does it go?"},
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 81 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 82 |
+
outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
|
| 83 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
> **Note:** This model performs best in **zero-shot** mode. Do not use few-shot examples β they conflict with the model's learned reasoning policy and reduce accuracy.
|
| 87 |
+
|
| 88 |
+
## Training Code
|
| 89 |
+
|
| 90 |
+
Full pipeline: [github.com/CelestialCreator/gpu-lab/tree/main/projects/05-grpo-reasoning](https://github.com/CelestialCreator/gpu-lab/tree/main/projects/05-grpo-reasoning)
|
| 91 |
+
|
| 92 |
+
## Acknowledgments
|
| 93 |
+
|
| 94 |
+
- Trained at [Zosma AI](https://zosma.ai) on RTX 5090
|
| 95 |
+
- [TRL](https://github.com/huggingface/trl) for the GRPOTrainer implementation
|
| 96 |
+
- [Qwen Team](https://github.com/QwenLM) for the base model
|
| 97 |
+
- [DeepSeek](https://arxiv.org/abs/2402.03300) for the GRPO algorithm
|