hugruby commited on
Commit
4e0ad6f
·
verified ·
1 Parent(s): d8b386f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +149 -0
README.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: mistralai/Mathstral-7B-v0.1
4
+ library_name: peft
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - lora
8
+ - peft
9
+ - grpo
10
+ - dr-grpo
11
+ - mathematical-reasoning
12
+ - math
13
+ datasets:
14
+ - hugruby/mismatched-wrong-drafts
15
+ language:
16
+ - en
17
+ ---
18
+
19
+ # Mathstral-7B · Mismatched × Correct drafts
20
+
21
+ Ablation — a *correct* draft **mismatched** to a different problem (the 2×2's fourth cell).
22
+
23
+ LoRA adapter for **`mistralai/Mathstral-7B-v0.1`**, trained with **Dr. GRPO** as the **Mismatched × Correct drafts** condition in *"Weak-to-Strong Elicitation via Mismatched Wrong Drafts"* (Wei Deng, [arXiv:2605.17314](https://arxiv.org/abs/2605.17314)).
24
+
25
+ - **Base model:** `mistralai/Mathstral-7B-v0.1` (Apache-2.0)
26
+ - **Draft model:** `Qwen/Qwen2.5-Math-1.5B` (writes the training-time draft)
27
+ - **Adapter:** LoRA r=16, α=32 (167 MB), released at **global step 2000**
28
+ - **Training data:** config `mismatched_correct` of [`hugruby/mismatched-wrong-drafts`](https://huggingface.co/datasets/hugruby/mismatched-wrong-drafts) — 8,888 Level 3–5 MATH problems (**MATH-500 held out**)
29
+ - **License:** Apache-2.0
30
+
31
+ ## How to use
32
+
33
+ This is a **LoRA adapter** — load it on top of the base model.
34
+
35
+ ```python
36
+ import torch
37
+ from transformers import AutoModelForCausalLM, AutoTokenizer
38
+ from peft import PeftModel
39
+
40
+ BASE = "mistralai/Mathstral-7B-v0.1"
41
+ ADAPTER = "hugruby/mathstral-7b-mismatched-correct-drafts"
42
+
43
+ tok = AutoTokenizer.from_pretrained(ADAPTER)
44
+ model = PeftModel.from_pretrained(
45
+ AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16, device_map="auto"),
46
+ ADAPTER,
47
+ ).eval()
48
+
49
+ problem = "If $x+y=6$ and $xy=5$, find $x^2+y^2$."
50
+ gen = dict(max_new_tokens=4096, do_sample=False)
51
+
52
+ # CANONICAL — the plain draft-free prompt the model was trained and evaluated on (no [INST]):
53
+ PROMPT = (
54
+ "Problem: " + problem + "\n\n"
55
+ "Thinking: N/A\n\n"
56
+ "The thinking section may contain errors. Solve the math problem step by step. "
57
+ "Write your own correct solution. Put your final answer within \\boxed{}.\n\n"
58
+ "Correct Solution:"
59
+ )
60
+ ids = tok(PROMPT, return_tensors="pt").to(model.device)
61
+ print(tok.decode(model.generate(**ids, **gen)[0][ids.input_ids.shape[1]:], skip_special_tokens=True))
62
+ ```
63
+
64
+ ### Optional: the `[INST]` chat format (out-of-distribution)
65
+
66
+ The shipped `chat_template.jinja` is Mathstral's original `[INST]` chat template. This adapter was **not** trained in that format, so `apply_chat_template(...)` is **out-of-distribution** and generally underperforms the plain prompt above — it is included only so you can A/B both:
67
+
68
+ ```python
69
+ ids = tok.apply_chat_template(
70
+ [{"role": "user",
71
+ "content": problem + "\n\nPlease reason step by step, and put your final answer within \\boxed{}."}],
72
+ add_generation_prompt=True, return_tensors="pt").to(model.device)
73
+ print(tok.decode(model.generate(ids, **gen)[0][ids.shape[1]:], skip_special_tokens=True))
74
+ ```
75
+
76
+ ## How it was trained
77
+
78
+ Trained with **Dr. GRPO** (`loss_type=dr_grpo`, `scale_rewards=False`) using TRL `GRPOTrainer` on top of Unsloth `FastLanguageModel`, on the `mismatched_correct` data config. The reward is binary `mathematically_quasi_correct`. The correction-bonus, copy-penalty, and corrupt-penalty terms are all **0**, and the reward is pure binary.
79
+
80
+ Training command:
81
+
82
+ ```bash
83
+ python scripts/train.py \
84
+ --model mistralai/Mathstral-7B-v0.1 \
85
+ --dataset-path data/mismatched_correct \
86
+ --output-dir outputs/mismatched_correct \
87
+ --max-steps 2222 \
88
+ --gradient-accumulation-steps 4 \
89
+ --max-completion-length 4096 \
90
+ --max-seq-length 8192 \
91
+ --learning-rate 5e-6 --lr-scheduler-type constant \
92
+ --beta 0 \
93
+ --correction-bonus 0.0 --copy-penalty 0.0 --corrupt-penalty 0.0 \
94
+ --adam-beta2 0.99 \
95
+ --save-steps 50 --gpu-mem-util 0.5
96
+ ```
97
+
98
+ | Hyperparameter | Value |
99
+ |---|---|
100
+ | Base model | `mistralai/Mathstral-7B-v0.1` |
101
+ | Method | Dr. GRPO (`loss_type=dr_grpo`, `scale_rewards=False`) |
102
+ | LoRA rank / alpha | **r = 16, α = 32** → scaling **γ = α/r = 2** |
103
+ | LoRA targets / dropout | `q,k,v,o,gate,up,down` (7 projections) / 0.0 |
104
+ | KL coefficient β | 0 |
105
+ | Reward bonuses | correction 0, copy-penalty 0, corrupt-penalty 0 |
106
+ | Generations per prompt | 16 |
107
+ | Per-device batch | 1 |
108
+ | Gradient accumulation | 4 → 4 problems × 16 = 64 completions/step |
109
+ | Learning rate | 5e-6, **constant** schedule |
110
+ | Adam β₂ | 0.99 |
111
+ | Max completion length | 4096 |
112
+ | Max sequence length \* | 8192 |
113
+ | Max prompt tokens \* | — (disabled, no truncation; longest prompt 3,317 tok < 8,192 − 4,096, so the 4,096 max completion length is respected) |
114
+ | Max steps | 2222 |
115
+ | **Released checkpoint** | **global step 2000** (epoch 0.900) |
116
+ | Random seed | 42 |
117
+
118
+ \* **Length budgets across all four variants:**
119
+
120
+ | Variant | max-seq-length | max-completion | max-prompt-tokens |
121
+ |---|---|---|---|
122
+ | mismatched-wrong | 7168 | 4096 | 3072 |
123
+ | matched-wrong | 7168 | 4096 | 3072 |
124
+ | no-draft | 7168 | 4096 | disabled (equivalent to 3,072, as all prompts are short) |
125
+ | **mismatched-correct** | 8192 | 4096 | disabled |
126
+
127
+ For a strict apple-to-apple comparison, `mismatched-correct` should have used `--max-seq-length 7168` and `--max-prompt-tokens 3072` like the other three variants; the larger 8,192 with the cap left off was an omission. The effect should be negligible though — only **6 of 8,888** prompts exceed 3,072 tokens (longest 3,317), so for the other 8,882 the run is identical to a 7,168 / 3,072 setup. For those 6 the prompt is left untruncated, but the 4,096 max-completion length is still respected and the sequence runs only slightly past 7,168 (at most 3,317 + 4,096 = 7,413, well under 8,192). But to train a precise apple-to-apple version yourself, change `--max-seq-length 8192` to `7168` and add `--max-prompt-tokens 3072`.
128
+
129
+ ## Files
130
+
131
+ - `adapter_model.safetensors`, `adapter_config.json` — the LoRA adapter (load with PEFT on the base model)
132
+ - `tokenizer.json`, `tokenizer.model`, `tokenizer_config.json`, `special_tokens_map.json` — tokenizer
133
+ - `chat_template.jinja` — Mathstral's `[INST]` template (see the out-of-distribution note above)
134
+
135
+ ## Citation
136
+
137
+ ```bibtex
138
+ @article{deng2026mismatched,
139
+ title = {Weak-to-Strong Elicitation via Mismatched Wrong Drafts},
140
+ author = {Deng, Wei},
141
+ journal = {arXiv preprint arXiv:2605.17314},
142
+ year = {2026},
143
+ url = {https://arxiv.org/abs/2605.17314}
144
+ }
145
+ ```
146
+
147
+ ## License
148
+
149
+ Apache-2.0. The base model (`Mathstral-7B-v0.1`) and the draft model (`Qwen2.5-Math-1.5B`) are both Apache-2.0.