Download tests/test_overview.py from BurnyCoder/recursive-judge-grpo-study: direct link, hf CLI and curl.
- Browser
- Download file 5.58 kB
-
https://huggingface.co/datasets/BurnyCoder/recursive-judge-grpo-study/resolve/main/tests/test_overview.py
- Command line
-
hf download hf://datasets/BurnyCoder/recursive-judge-grpo-study/tests/test_overview.py
-
curl -L -o test_overview.py https://huggingface.co/datasets/BurnyCoder/recursive-judge-grpo-study/resolve/main/tests/test_overview.py
5.58 kB
| """Check the generated top-of-README summaries on artificial per-problem outcomes.""" | |
| import json | |
| import pytest | |
| from study.overview import (ARMS, glance_markdown, glance_rows, group_advantages, replace_region, solver_scores, | |
| verdict) | |
| def test_replace_region_rewrites_each_marked_block_and_keeps_hand_written_text(): | |
| text = "Head\n<!-- A:START -->\nold a\n<!-- A:END -->\nMiddle\n<!-- B:START -->old b<!-- B:END -->\nTail\n" | |
| text = replace_region(text, "A", "new a") | |
| text = replace_region(text, "B", "new b") | |
| assert text == "Head\n<!-- A:START -->\nnew a\n<!-- A:END -->\nMiddle\n<!-- B:START -->\nnew b\n<!-- B:END -->\nTail\n" | |
| def test_replace_region_tolerates_an_optional_missing_region_but_not_a_required_one(): | |
| assert replace_region("Fixture\n", "HIGHLIGHTS", "x", required=False) == "Fixture\n" | |
| with pytest.raises(ValueError): | |
| replace_region("Fixture\n", "RESULTS", "x") | |
| def write_replay(folder, outcomes, name="replay.jsonl"): | |
| folder.mkdir(parents=True, exist_ok=True) | |
| (folder/"development.json").write_text("{}", encoding="utf-8") | |
| (folder/name).write_text("".join(json.dumps(dict(key=f"p{i}", correct=c))+"\n" for i, c in enumerate(outcomes)), | |
| encoding="utf-8") | |
| def test_rows_label_roles_and_compare_every_arm_with_three_judges_on_the_same_problems(tmp_path): | |
| source, root = tmp_path/"calibrated", tmp_path | |
| n = 32 | |
| write_replay(source/"base", [1]*16+[0]*16) | |
| write_replay(source/"d3-17", [0]*n) | |
| write_replay(source/"oracle-17", [1]*n) | |
| write_replay(source/"d2-17", [0]*(n-1)+[1]) | |
| write_replay(root/"new-judges/winner-d3", [1]*n, "solutions.jsonl") | |
| write_replay(root/"new-judges/winner-d2", [1]*n, "solutions.jsonl") | |
| rows = glance_rows(solver_scores(source, root)) | |
| by_key = {(r["family"], r["key"]): r for r in rows} | |
| oracle = by_key["original", "oracle-17"] | |
| assert (oracle["role"], oracle["correct"], oracle["n"]) == ("Control", n, n) | |
| assert oracle["change"]["delta"] == 1 and oracle["change"]["interval"] == [1, 1] | |
| assert verdict(oracle["change"]) == "higher" | |
| assert verdict(by_key["original", "d2-17"]["change"]) == "not distinguishable" | |
| assert by_key["original", "d3-17"]["change"] is None and by_key["original", "d3-17"]["role"] == "Method" | |
| # A registered arm without a development receipt is shown as pending, never as a score. | |
| assert by_key["original", "flat-17"]["correct"] is None | |
| assert by_key["frozen", "new-judges/winner-d2"]["change"]["delta"] == 0 | |
| table = glance_markdown(rows) | |
| assert "Pending" in table and "32/32 (100.0%)" in table and "+100.00" in table | |
| assert "Higher than three judges" in table and "Not distinguishable from three judges" in table | |
| assert "exact checker reward (`oracle-17`" in table | |
| def test_rows_skip_arms_whose_problems_differ_from_the_starting_solver(tmp_path): | |
| source = tmp_path/"calibrated" | |
| write_replay(source/"base", [1, 0]) | |
| write_replay(source/"d3-17", [1, 0, 1]) | |
| rows = glance_rows(solver_scores(source, tmp_path)) | |
| assert next(r for r in rows if r["key"] == "d3-17")["correct"] is None | |
| def test_verdict_requires_the_whole_interval_on_one_side_of_zero(): | |
| assert verdict(dict(interval=[-.15625, 0.0])) == "not distinguishable" | |
| assert verdict(dict(interval=[-.9, -.4])) == "lower" | |
| assert verdict(dict(interval=[.1, .5])) == "higher" | |
| def test_group_advantages_follow_trl_group_scaling_with_bessel_correction(): | |
| # TRL 1.19 GRPOTrainer: (r - mean) / (nanstd + 1e-4), nanstd applies count/(count-1). | |
| values = group_advantages([1, 1, 0, 0]) | |
| assert values[0] == pytest.approx(.5/(3**-.5+1e-4)) | |
| assert values[2] == pytest.approx(-values[0]) | |
| assert group_advantages([1, 1, 1, 1]) == [0, 0, 0, 0] | |
| def test_every_registered_family_has_exactly_one_method_arm(): | |
| for family in {a.family for a in ARMS}: | |
| assert sum(a.role == "Method" for a in ARMS if a.family == family) == 1 | |
| def test_summary_media_are_drawn_from_outcomes_and_removed_without_evidence(tmp_path): | |
| from PIL import Image | |
| from study.visual_summary import OUTPUTS, draw_all | |
| source = tmp_path/"calibrated" | |
| for key, outcomes in (("base", [1, 0]*16), ("d3-17", [0]*30+[1, 1]), ("d2-17", [1]*25+[0]*7), | |
| ("oracle-17", [1]*32), ("shuffle-17", [0]*27+[1]*5)): | |
| write_replay(source/key, outcomes) | |
| table = glance_rows(solver_scores(source, tmp_path)) | |
| quarter = dict(last_update=256, correct=15, n=256, rewarded_correct=2, rewarded_wrong=169) | |
| # One logged group in the format depth_review.group_evidence produces: (answer, exact label, J2 reward, J3 reward). | |
| example = dict(update=20, expression="(2+3)*4", | |
| samples=[("5,20", 1, 1, 0), ("5,20", 1, 1, 1), ("6,20", 0, 0, 0), ("6,20", 0, 0, 1)], | |
| reports=[["1,0,20,1,0,20", "0,2,20,0,1,5"]]) | |
| review = dict(seed=17, groups=256, fixes=1, harms=2, changed_groups=3, credit_example=example, | |
| two=dict(quarters=[dict(quarter, correct=186)]), three=dict(quarters=[quarter])) | |
| out = tmp_path/"assets" | |
| out.mkdir() | |
| draw_all(table, dict(depth_review=[review], primary={}), out) | |
| for name in OUTPUTS: | |
| assert (out/name).stat().st_size > 1000, name | |
| # Pillow merges repeated frames, so one frame remains per walkthrough stage. | |
| assert Image.open(out/"walkthrough.gif").n_frames == 7 | |
| draw_all(glance_rows(solver_scores(tmp_path/"empty", tmp_path)), {}, out) | |
| assert sorted(p.name for p in out.iterdir()) == ["architecture.png"] | |