File size: 2,235 Bytes
f227f52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Render the admitted reward and pass@8 history for preserved RL runs."""

import argparse
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("metrics", type=Path)
    parser.add_argument("output_dir", type=Path)
    parser.add_argument("--title", required=True)
    args = parser.parse_args()

    metrics = pd.read_csv(args.metrics)
    surface = metrics[["global_step", "reward/avg_raw_reward", "reward/avg_pass_at_8"]].rename(
        columns={
            "global_step": "step",
            "reward/avg_raw_reward": "reward",
            "reward/avg_pass_at_8": "pass_at_8",
        }
    )
    args.output_dir.mkdir(parents=True, exist_ok=True)
    surface.to_csv(args.output_dir / "reward-pass8.csv", index=False)

    plt.rcParams.update({"font.size": 11, "axes.titleweight": "semibold"})
    figure, axis = plt.subplots(figsize=(8.2, 4.8), constrained_layout=True)
    axis.plot(surface["step"], surface["reward"], color="#1261a0", marker="o", linewidth=2.2, label="Admitted reward")
    axis.plot(
        surface["step"],
        surface["pass_at_8"],
        color="#a34a28",
        marker="s",
        linestyle="--",
        linewidth=2.0,
        label="Pass@8",
    )
    for row in surface.itertuples(index=False):
        axis.annotate(f"{row.reward:.3f}", (row.step, row.reward), xytext=(0, -18), textcoords="offset points", ha="center")
    axis.set_title(args.title, loc="left")
    axis.set_xlabel("Optimizer step")
    axis.set_ylabel("Score")
    axis.set_xticks(surface["step"].astype(int))
    axis.set_ylim(0, 1.08)
    axis.grid(axis="y", color="#d9dee5", linewidth=0.8)
    axis.spines[["top", "right"]].set_visible(False)
    axis.legend(loc="lower left", frameon=False, ncols=2)
    axis.text(
        1.0,
        -0.18,
        "Pass@8 is 1.0 at all three admitted steps.",
        transform=axis.transAxes,
        ha="right",
        color="#4a5568",
        fontsize=9,
    )

    figure.savefig(args.output_dir / "reward-pass8.png", dpi=180)
    figure.savefig(args.output_dir / "reward-pass8.svg")
    plt.close(figure)


if __name__ == "__main__":
    main()