File size: 1,184 Bytes
aa1df78 | 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 | """Read SWE-smith's grading report of each attempt and write att-<k>/resolved.json for train/build_sft.py.
python train/collect_grades.py /data/train/mini/results/gen
"""
import glob
import json
import os
import sys
def main():
gen = sys.argv[1]
total = {}
for a in sorted(glob.glob(gen + "/att-*")):
reports = glob.glob(a + "/grade/logs/run_evaluation/*/report.json")
if not reports:
print(os.path.basename(a), "no grading report")
continue
r = json.load(open(reports[0]))
resolved = sorted(r.get("ids_resolved") or [])
preds = json.load(open(a + "/preds.json"))
with_patch = sum(1 for v in preds.values() if (v.get("model_patch") or "").strip())
json.dump({"resolved": resolved, "graded": r.get("total"), "attempted": len(preds), "with_patch": with_patch},
open(a + "/resolved.json", "w"))
total[os.path.basename(a)] = {"attempted": len(preds), "with_patch": with_patch, "graded": r.get("total"), "resolved": len(resolved)}
print(json.dumps(total))
json.dump(total, open(gen + "/grades.json", "w"), indent=1)
if __name__ == "__main__":
main()
|