Upload root_scripts/coverage_test.py with huggingface_hub
Browse files
root_scripts/coverage_test.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json, sys, importlib.util
|
| 3 |
+
|
| 4 |
+
# Direct file import to avoid verl.__init__
|
| 5 |
+
spec = importlib.util.spec_from_file_location(
|
| 6 |
+
"physics_reward",
|
| 7 |
+
"/workspace/rl4phyx/RL4Phyx/ZeroSearch/One-Shot-RLVR/verl/utils/reward_score/physics_reward.py"
|
| 8 |
+
)
|
| 9 |
+
mod = importlib.util.module_from_spec(spec)
|
| 10 |
+
spec.loader.exec_module(mod)
|
| 11 |
+
|
| 12 |
+
rule_based_score = mod.rule_based_score
|
| 13 |
+
sympy_fallback_score = mod.sympy_fallback_score
|
| 14 |
+
|
| 15 |
+
f = "/workspace/rl4phyx/RL4Phyx/SFT/sft_eval_footprint/inference_results_base.jsonl"
|
| 16 |
+
with open(f) as fh:
|
| 17 |
+
lines = [json.loads(l) for l in fh if l.strip()]
|
| 18 |
+
|
| 19 |
+
results = {"rule_ok": 0, "sympy_ok": 0, "sympy_fail": 0, "rule_wrong": 0}
|
| 20 |
+
categories = {}
|
| 21 |
+
fail_examples = []
|
| 22 |
+
|
| 23 |
+
for r in lines:
|
| 24 |
+
gt = str(r.get("ground_truth_value", "")).strip()
|
| 25 |
+
cat = r.get("category", "unknown")
|
| 26 |
+
|
| 27 |
+
score = rule_based_score(gt, gt)
|
| 28 |
+
|
| 29 |
+
if score == 1.0:
|
| 30 |
+
status = "rule_ok"
|
| 31 |
+
results["rule_ok"] += 1
|
| 32 |
+
elif score is None:
|
| 33 |
+
try:
|
| 34 |
+
s = sympy_fallback_score(gt, gt)
|
| 35 |
+
if s == 1.0:
|
| 36 |
+
status = "sympy_ok"
|
| 37 |
+
results["sympy_ok"] += 1
|
| 38 |
+
else:
|
| 39 |
+
status = "sympy_fail"
|
| 40 |
+
results["sympy_fail"] += 1
|
| 41 |
+
if len(fail_examples) < 20:
|
| 42 |
+
fail_examples.append({"gt": gt[:80], "cat": cat})
|
| 43 |
+
except Exception as e:
|
| 44 |
+
status = "sympy_fail"
|
| 45 |
+
results["sympy_fail"] += 1
|
| 46 |
+
if len(fail_examples) < 20:
|
| 47 |
+
fail_examples.append({"gt": gt[:80], "cat": cat})
|
| 48 |
+
else:
|
| 49 |
+
status = "rule_wrong"
|
| 50 |
+
results["rule_wrong"] += 1
|
| 51 |
+
if len(fail_examples) < 20:
|
| 52 |
+
fail_examples.append({"gt": gt[:80], "cat": cat})
|
| 53 |
+
|
| 54 |
+
if cat not in categories:
|
| 55 |
+
categories[cat] = {"rule_ok": 0, "sympy_ok": 0, "fail": 0}
|
| 56 |
+
if "ok" in status:
|
| 57 |
+
categories[cat][status] += 1
|
| 58 |
+
else:
|
| 59 |
+
categories[cat]["fail"] += 1
|
| 60 |
+
|
| 61 |
+
total = len(lines)
|
| 62 |
+
covered = results["rule_ok"] + results["sympy_ok"]
|
| 63 |
+
|
| 64 |
+
print(f"=== Hybrid Reward Coverage ({total} questions) ===")
|
| 65 |
+
print(f" Rule-based: {results['rule_ok']:4d} ({results['rule_ok']/total*100:.1f}%)")
|
| 66 |
+
print(f" SymPy: {results['sympy_ok']:4d} ({results['sympy_ok']/total*100:.1f}%)")
|
| 67 |
+
print(f" TOTAL OK: {covered:4d} ({covered/total*100:.1f}%)")
|
| 68 |
+
print(f" Failed: {results['sympy_fail']+results['rule_wrong']:4d} ({(results['sympy_fail']+results['rule_wrong'])/total*100:.1f}%)")
|
| 69 |
+
|
| 70 |
+
print(f"\n=== By Category ===")
|
| 71 |
+
for cat, v in sorted(categories.items()):
|
| 72 |
+
t = v["rule_ok"] + v["sympy_ok"] + v["fail"]
|
| 73 |
+
ok = v["rule_ok"] + v["sympy_ok"]
|
| 74 |
+
print(f" {cat:25s}: {ok}/{t} = {ok/t*100:.0f}% [rule={v['rule_ok']}, sympy={v['sympy_ok']}, fail={v['fail']}]")
|
| 75 |
+
|
| 76 |
+
print(f"\n=== Fail Examples ===")
|
| 77 |
+
for ex in fail_examples:
|
| 78 |
+
print(f" [{ex['cat']:20s}] {ex['gt']}")
|