-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhf_grpotuned_pipeline.py
More file actions
70 lines (62 loc) · 1.79 KB
/
Copy pathhf_grpotuned_pipeline.py
File metadata and controls
70 lines (62 loc) · 1.79 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
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import annotations
import argparse
from pathlib import Path
from oneshot_grpo.inference.pipeline import (
DEFAULT_MODEL_ID,
build_text_generator,
generate_math_solution,
save_prompt_and_response,
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Run inference with the GRPO-tuned math model.",
)
parser.add_argument(
"prompt",
nargs="*",
help="Math prompt to solve. If omitted, the prompt is read from stdin.",
)
parser.add_argument(
"--model",
default=DEFAULT_MODEL_ID,
help="Model identifier to load from Hugging Face Hub.",
)
parser.add_argument(
"--max-new-tokens",
type=int,
default=6000,
help="Maximum number of tokens to generate.",
)
parser.add_argument(
"--temperature",
type=float,
default=1.0,
help="Sampling temperature.",
)
parser.add_argument(
"--output-jsonl",
default="math_results.jsonl",
help="Path to the JSONL file where prompts and answers will be appended.",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
prompt = " ".join(args.prompt) if args.prompt else input("Enter a math problem: ")
generator = build_text_generator(model_id=args.model)
solution = generate_math_solution(
prompt,
generator=generator,
max_new_tokens=args.max_new_tokens,
temperature=args.temperature,
)
print("Generated Output:")
print(solution)
save_prompt_and_response(
prompt,
solution,
path=Path(args.output_jsonl),
extra={"model": args.model},
)
print(f"Result saved to {args.output_jsonl}")
if __name__ == "__main__":
main()