jacobeen06 commited on
Commit
25e5874
·
verified ·
1 Parent(s): 504e7f9

Add full plan doc

Browse files
Files changed (1) hide show
  1. genesis-2-rlhf-plan.md +190 -0
genesis-2-rlhf-plan.md ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Genesis-2.0 — Multi-Stage RLHF Implementation Plan
2
+
3
+ **Goal:** Improve Genesis-1.0 (Qwen3.6-35B-A3B, tool-use SFT) with multi-stage RL post-training to add tool-choice discrimination, OOD generalization, and multi-step planning.
4
+
5
+ **Total estimated cost: $6-9** (RTX PRO 6000 Blackwell, ~3.5-5.5 hrs)
6
+ **Total wall time: ~1-2 weeks** (mostly Phase 0 data work on MacBook)
7
+
8
+ ---
9
+
10
+ ## Architecture Overview
11
+
12
+ ### Model
13
+ | Attribute | Value |
14
+ |-----------|-------|
15
+ | Base | Qwen/Qwen3.6-35B-A3B (MoE, 35B total, 3B active) |
16
+ | Current | Genesis-1.0 (SFT, attention-only LoRA r=64, MLX 4-bit) |
17
+ | Target | Genesis-2.0 (SFT + DPO + GRPO, all-linear LoRA r=32, MLX 4-bit) |
18
+
19
+ ### Compute
20
+ | Phase | Hardware | Cost | Time |
21
+ |-------|----------|------|------|
22
+ | 0 (Data prep) | Mac M5 Pro 64GB | $0 | ~1 week |
23
+ | 1 (DPO) | 1× RTX PRO 6000 96GB | ~$3-4 | 1.5-2.5 hrs |
24
+ | 2 (GRPO) | 1× RTX PRO 6000 96GB | ~$3-5 | 2-3 hrs |
25
+ | 3 (Merge+Deploy) | Mac M5 Pro 64GB | $0 | ~1 day |
26
+
27
+ ### Software Stack
28
+ - **Training:** TRL (DPOTrainer, GRPOTrainer) + Unsloth
29
+ - **Inference engine:** vLLM (for GRPO rollouts)
30
+ - **Quantization:** QLoRA NF4 (bitsandbytes 4-bit)
31
+ - **LoRA Config C:** attention (q/k/v/o) + shared expert FFN (gate/up/down) + gate/router — 131M params, r=32
32
+ - **Monitoring:** Weights & Biases
33
+ - **RunPod template:** `axolotl-cloud:main-latest` or `pytorch:2.5-cuda12.4`
34
+
35
+ ---
36
+
37
+ ## Phase 0 — Data & Infrastructure (Local M5 Pro, $0)
38
+
39
+ ### Objectives
40
+ 1. Build DPO preference pairs from existing data
41
+ 2. Implement rule-based reward functions for tool-use
42
+ 3. Create evaluation benchmark
43
+ 4. Document RunPod provisioning procedure
44
+
45
+ ### DPO Data Sources
46
+
47
+ **Source A: Session logs (real tool-use traces)**
48
+ - Extract prompts from existing SFT dataset (20K examples)
49
+ - For each prompt, generate 2 responses with Genesis-1.0 at temperature 0.7
50
+ - Score with rule-based evaluator:
51
+ - +1.0: correct tool call + correct params + task completed
52
+ - +0.5: correct tool call + error recovered
53
+ - 0.0: wrong tool call
54
+ - -0.5: hallucinated tool call
55
+ - -1.0: no meaningful output
56
+ - Pair: highest-scoring = chosen, lowest = rejected
57
+ - Target: 500-2,000 pairs from this method
58
+
59
+ **Source B: Data augmentation (controlled perturbations)**
60
+ - Take successful SFT examples, introduce controlled errors:
61
+ - Wrong tool name for the task
62
+ - Correct tool but missing required parameter
63
+ - Correct call but result ignored
64
+ - Unnecessary tool calls (inefficient trajectory)
65
+ - Correct version = chosen, perturbed = rejected
66
+ - Target: 500-1,000 pairs
67
+
68
+ ### Reward Functions
69
+ ```python
70
+ def tool_call_correctness(trajectory, tools_schema):
71
+ """+1 if all tool calls match valid names and param types. 0 otherwise."""
72
+
73
+ def task_completion(trajectory, expected_outcome):
74
+ """+1 if final answer satisfies the task. 0 if incomplete. -1 if wrong."""
75
+
76
+ def tool_result_usage(trajectory):
77
+ """+0.5 if tool results are referenced in subsequent reasoning. 0 if ignored."""
78
+
79
+ def trajectory_efficiency(trajectory):
80
+ """Normalized score: ideal_steps / actual_steps. Range [0, 1]."""
81
+
82
+ def format_validity(trajectory):
83
+ """+1 if tool calls follow the expected JSON/XML format. 0 otherwise."""
84
+ ```
85
+
86
+ Combined reward: `0.4×completion + 0.3×correctness + 0.15×usage + 0.1×efficiency + 0.05×format`
87
+
88
+ ### Evaluation Benchmark
89
+ - Hold-out set: 100-200 prompts from the same distribution as training
90
+ - Metrics:
91
+ - Tool call accuracy (% of calls with correct tool + params)
92
+ - Task completion rate (% of tasks finished successfully)
93
+ - Trajectory efficiency (avg steps to completion)
94
+ - Format compliance (% of valid tool call syntax)
95
+ - Run before/after each phase to measure improvement
96
+ - Required improvement threshold for phase progression: ≥5% tool call accuracy
97
+
98
+ ---
99
+
100
+ ## Phase 1 — DPO Preference Alignment (RTX PRO 6000, ~$3-4)
101
+
102
+ ### Procedure
103
+ 1. Provision RTX PRO 6000 pod on RunPod (Community Cloud ~$1.69/hr)
104
+ 2. Install dependencies: torch, transformers, trl, unsloth, peft, bitsandbytes, datasets
105
+ 3. Upload Genesis-1.0 SFT adapter (53 MB from HF: `jacobeen06/Genesis-1.0-SFT-adapter`)
106
+ 4. Load base model (Qwen3.6-35B-A3B) with QLoRA NF4
107
+ 5. Merge existing attention-only adapter into base model
108
+ 6. Attach new all-linear LoRA (Config C: attention + shared expert + gate, r=32)
109
+ 7. Train with DPOTrainer:
110
+ - Batch: micro_batch=1, grad_accum=4 (effective 4)
111
+ - Learning rate: 5e-6 (cosine schedule)
112
+ - β (DPO temperature): 0.1-0.3
113
+ - Context: 4096
114
+ - Epochs: 1-2
115
+ - Precision: BF16
116
+ 8. Evaluate on hold-out set
117
+ 9. Save adapter to HF Hub: `jacobeen06/Genesis-2.0-DPO-adapter`
118
+
119
+ ### Expected outcome
120
+ - Tool call accuracy: +5-15% improvement over Genesis-1.0
121
+ - Reduced hallucinated tool calls
122
+ - Better tool-choice discrimination
123
+
124
+ ---
125
+
126
+ ## Phase 2 — GRPO with Verifiable Rewards (RTX PRO 6000, ~$3-5)
127
+
128
+ ### Procedure
129
+ 1. Load Phase 1 checkpoint (base + DPO LoRA)
130
+ 2. Configure GRPOTrainer with vLLM:
131
+ - G=4-8 generations per prompt
132
+ - Reward: combined rule-based (same as Phase 0)
133
+ - GRPO config: clip_high=0.28, clip_low=0.2 (DAPO-style asymmetric)
134
+ - KL penalty: β=0.04 start, decay to 0.01
135
+ - vLLM gpu_memory_utilization: 0.90
136
+ - Context: 4096-8192
137
+ 3. Monitor for failure modes:
138
+ - Entropy collapse → enable clip-higher
139
+ - Advantage collapse → dynamic sampling
140
+ - KL drift → PID-controlled β
141
+ 4. Evaluate on hold-out set
142
+ 5. Save adapter: `jacobeen06/Genesis-2.0-GRPO-adapter`
143
+
144
+ ### Expected outcome
145
+ - OOD tool reasoning: +10-20% over DPO-only
146
+ - Multi-step plan quality improvement
147
+ - Better recovery from tool errors
148
+
149
+ ---
150
+
151
+ ## Phase 3 — Merge, Quantize, Deploy (Local M5 Pro, $0)
152
+
153
+ ### Procedure
154
+ 1. Merge all-linear LoRA into base model
155
+ 2. Convert to MLX format (4-bit with MTP heads preserved)
156
+ 3. Evaluate on benchmark (compare pre/post RL)
157
+ 4. Upload as `jacobeen06/Genesis-2.0-35b` to HF Hub
158
+ 5. Update oMLX/cua-driver config for Genesis-2.0
159
+ 6. Run inference test with `mlx_lm.generate --model jacobeen06/Genesis-2.0-35b --mtp`
160
+
161
+ ---
162
+
163
+ ## Infrastructure Reference
164
+
165
+ ### RunPod: RTX PRO 6000 Blackwell 96GB
166
+ - **Community Cloud:** ~$1.69/hr
167
+ - **Secure Cloud:** ~$1.99/hr
168
+ - **Recommended template:** `axolotl-cloud:main-latest` (has torch, CUDA, etc.)
169
+ - **Disk:** 50 GB minimum (model ~30 GB + adapter ~0.25 GB + data ~2 GB)
170
+ - **Region:** US or EU (whichever has availability)
171
+
172
+ ### Pod Setup Checklist
173
+ - [ ] Create pod with RTX PRO 6000 96GB
174
+ - [ ] Wait for pod to reach "Running" state
175
+ - [ ] Open Web Terminal
176
+ - [ ] Verify GPU: `nvidia-smi`
177
+ - [ ] Install extra deps: `pip install trl unsloth bitsandbytes`
178
+ - [ ] Download base model: `huggingface-cli download Qwen/Qwen3.6-35B-A3B`
179
+ - [ ] Download adapter: `huggingface-cli download jacobeen06/Genesis-1.0-SFT-adapter`
180
+ - [ ] Run training script
181
+ - [ ] Upload result adapter to HF
182
+
183
+ ### Key Risks & Mitigations
184
+ | Risk | Mitigation |
185
+ |------|-----------|
186
+ | Flash-attn compilation OOM | Use `attn_implementation: sdpa` instead |
187
+ | vLLM OOM during GRPO | Reduce G=4, use Unsloth Standby, stay at 4K context |
188
+ | SSH not available on pod | Use RunPod Web Terminal (single-command approach) |
189
+ | Training diverges | Monitor loss curves in W&B, kill and adjust LR |
190
+ | Data transfer slow | Use `hf upload` from Mac → HF Hub → `hf download` on pod |