celestialcreator commited on
Commit
6bc26de
·
verified ·
1 Parent(s): e09b6db

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +107 -0
README.md ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - celestialcreator/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.
22
+
23
+ ## Results
24
+
25
+ | Model | GSM8K 8-shot CoT | GSM8K Zero-shot |
26
+ |-------|:-----------------:|:---------------:|
27
+ | Qwen3.5-0.8B (baseline) | 53.5% | 52.1% |
28
+ | **Qwen3.5-0.8B-GRPO-Math** | 50.4% | **58.0% (+5.9pp)** |
29
+
30
+ The model was trained to reason using `<think>` tags. **Zero-shot performance improved by +5.9 percentage points** because the model internalized step-by-step reasoning — it no longer needs few-shot examples. The 8-shot drop is expected: few-shot examples conflict with the model's learned reasoning format.
31
+
32
+ ## Training Pipeline
33
+
34
+ ### Phase 1: SFT Warmup
35
+ - **Data:** [3,558 reasoning examples](https://huggingface.co/datasets/celestialcreator/Qwen3.5-0.8B-GRPO-Math-Dataset) (Claude-generated math chains + community reasoning data)
36
+ - **Purpose:** Teach the model `<think>` tag format before RL
37
+ - **Stats:** 1 epoch, loss 0.932, 78% token accuracy
38
+
39
+ ### Phase 2: GRPO Training
40
+ - **Data:** GSM8K train split (7,473 math word problems)
41
+ - **Rewards:** Math correctness (1.0/0.0) + format reward (0.3 for `<think>` tags, 0.2 for `####` answer)
42
+ - **Config:** 8 generations/prompt, batch size 1 x 8 grad accum, lr 1e-6, beta=0.04
43
+ - **Hardware:** Single NVIDIA RTX 5090 (32GB VRAM)
44
+ - **Duration:** ~77 hours, 15,900 steps (epoch 2.13)
45
+
46
+ ### What is GRPO?
47
+
48
+ GRPO eliminates the need for a separate reward model and critic network (unlike PPO). For each prompt, it:
49
+ 1. Samples G completions from the policy
50
+ 2. Scores each with a verifiable reward (exact math answer checking)
51
+ 3. Normalizes rewards within the group (relative advantage)
52
+ 4. Updates the policy using a clipped surrogate objective
53
+
54
+ This means only 2 models in memory (policy + reference) instead of 4, making it feasible on consumer GPUs.
55
+
56
+ ## Usage
57
+
58
+ ```python
59
+ from transformers import AutoModelForCausalLM, AutoTokenizer
60
+
61
+ model_name = "celestialcreator/Qwen3.5-0.8B-GRPO-Math"
62
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
63
+ model = AutoModelForCausalLM.from_pretrained(
64
+ model_name,
65
+ torch_dtype="auto",
66
+ device_map="auto",
67
+ trust_remote_code=True,
68
+ )
69
+
70
+ messages = [
71
+ {"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>"},
72
+ {"role": "user", "content": "If a train travels at 60 mph for 2.5 hours, how far does it go?"},
73
+ ]
74
+
75
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
76
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
77
+ outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
78
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
79
+ ```
80
+
81
+ ## Training Code
82
+
83
+ Full training pipeline (Dockerfile, k8s configs, scripts): [github.com/CelestialCreator/gpu-lab/tree/main/projects/05-grpo-reasoning](https://github.com/CelestialCreator/gpu-lab/tree/main/projects/05-grpo-reasoning)
84
+
85
+ ## Key Findings
86
+
87
+ - **Qwen3.5-0.8B uses DeltaNet** (hybrid Gated DeltaNet + Gated Attention layers). Install `flash-linear-attention` + `causal-conv1d` for fast generation.
88
+ - **SDPA > FLA for inference** — 3.6x faster on first call. Use `attn_implementation="sdpa"`.
89
+ - **Zero-shot is the right eval for RL-trained reasoning models** — few-shot examples conflict with learned reasoning patterns.
90
+ - **0.8B is near the capacity ceiling for GRPO** — the model internalizes reasoning format but has limited room for math accuracy gains. Consider 1.5B+ for stronger results.
91
+
92
+ ## Acknowledgments
93
+
94
+ - [TRL](https://github.com/huggingface/trl) for the GRPOTrainer implementation
95
+ - [Qwen Team](https://github.com/QwenLM) for the base model
96
+ - [DeepSeek](https://arxiv.org/abs/2402.03300) for the GRPO algorithm
97
+
98
+ ## Citation
99
+
100
+ ```bibtex
101
+ @misc{qwen35-grpo-math-2026,
102
+ author = {Akshay Mhaskar},
103
+ title = {Qwen3.5-0.8B-GRPO-Math: Teaching a Small Model to Reason with RL},
104
+ year = {2026},
105
+ url = {https://huggingface.co/celestialcreator/Qwen3.5-0.8B-GRPO-Math},
106
+ }
107
+ ```