-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_grpo.py
More file actions
57 lines (46 loc) · 1.55 KB
/
Copy pathtrain_grpo.py
File metadata and controls
57 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Tiny TRL GRPO example for the public expired task.
Run with: python train_grpo.py --model Qwen/Qwen2.5-0.5B-Instruct --max-steps 10
"""
from __future__ import annotations
import argparse
from datasets import Dataset
from trl import GRPOConfig, GRPOTrainer
from mathcode_mini.env import MathCodeMiniEnv
def reward_func(environments, **kwargs):
return [float(environment.reward) for environment in environments]
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--model", required=True)
parser.add_argument("--output-dir", default="outputs/mathcode-mini")
parser.add_argument("--max-steps", type=int, default=10)
args = parser.parse_args()
prompts = [
[
{
"role": "user",
"content": (
"Repair the bisection repository using the MathCode tools. "
"Run public tests, inspect your diff, then call finish."
),
}
]
* 32
]
dataset = Dataset.from_dict({"prompt": prompts, "task_id": ["bisect_repair_v1"] * len(prompts)})
trainer = GRPOTrainer(
model=args.model,
reward_funcs=reward_func,
train_dataset=dataset,
environment_factory=MathCodeMiniEnv,
args=GRPOConfig(
output_dir=args.output_dir,
max_steps=args.max_steps,
num_generations=4,
max_completion_length=2048,
logging_steps=1,
report_to=[],
),
)
trainer.train()
if __name__ == "__main__":
main()