Download score.py from zhiyuanhucs/agent-benchmark-eval-code: direct link, hf CLI and curl.
- Browser
- Download file 3.52 kB
-
https://huggingface.co/datasets/zhiyuanhucs/agent-benchmark-eval-code/resolve/main/score.py
- Command line
-
hf download hf://datasets/zhiyuanhucs/agent-benchmark-eval-code/score.py
-
curl -L -o score.py https://huggingface.co/datasets/zhiyuanhucs/agent-benchmark-eval-code/resolve/main/score.py
3.52 kB
| #!/usr/bin/env python3 | |
| """Summarize one native result per planned task, with fixed denominators.""" | |
| import argparse | |
| import importlib.util | |
| import json | |
| from pathlib import Path | |
| import sys | |
| from harness.bootstrap import ROOT | |
| def load_module(name, path): | |
| spec = importlib.util.spec_from_file_location(name, path) | |
| module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| return module | |
| def score(output): | |
| plan = json.loads((output / 'PLAN.json').read_text()) | |
| expected = set(plan['selected_tasks']) | |
| results = {} | |
| for path in sorted((output / 'trials').rglob('result.json')): | |
| item = json.loads(path.read_text()) | |
| task = item.get('task_name') | |
| if not task: | |
| continue | |
| if task not in expected or task in results: | |
| raise ValueError(f'Unexpected or duplicate task result: {task}') | |
| results[task] = (item, path.parent) | |
| graded = success = valid_graded = valid_success = 0 | |
| exception_types = {} | |
| for item, _ in results.values(): | |
| reward = ((item.get('verifier_result') or {}).get('rewards') or {}).get('reward') | |
| exception = item.get('exception_info') | |
| graded += reward in (0, 1) | |
| success += reward == 1 | |
| valid_graded += reward in (0, 1) and not exception | |
| valid_success += reward == 1 and not exception | |
| if exception: | |
| name = exception.get('exception_type', 'UnknownError') | |
| exception_types[name] = exception_types.get(name, 0) + 1 | |
| count = len(expected) | |
| report = {'benchmark': plan['benchmark'], 'model': plan['model'], 'expected': count, | |
| 'native_results': len(results), 'graded': graded, 'success': success, | |
| 'valid_graded': valid_graded, 'valid_success': valid_success, 'exceptions': exception_types, | |
| 'missing_tasks': sorted(expected - results.keys()), 'partial_subset': plan['partial'], | |
| 'complete_execution': len(results) == count and all(r[0].get('finished_at') for r in results.values()), | |
| 'success_rate': success / count if count else 0, | |
| 'success_rate_without_execution_exception': valid_success / count if count else 0, | |
| 'valid_execution_success_rate': valid_success / valid_graded if valid_graded else None} | |
| if plan['benchmark'] == 'swe_review': | |
| official = ROOT / 'vendor' / 'swe_review' / 'SWE-Review-Bench' | |
| sys.path.insert(0, str(official)) | |
| da = load_module('official_compute_da', official / 'compute_da.py') | |
| truth = json.loads((ROOT / 'data' / 'swe_review' / (plan['split'] + '.json')).read_text()) | |
| truth = [r for r in truth if r['instance_id'] in expected] | |
| from utils import load_review_results | |
| reviews = {r['instance_id']: r for r in load_review_results(str(output / 'trials'))} | |
| # Missing output remains a model/execution failure in the full denominator. | |
| all_reviews = [reviews.get(i, {'instance_id': i, 'report': None}) for i in sorted(expected)] | |
| report['official_DA'] = da.compute_da(all_reviews, truth) | |
| report['RRR'] = None | |
| report['RRR_note'] = 'Run revision.py with the split original patch generator before reporting RRR.' | |
| (output / 'metrics.json').write_text(json.dumps(report, indent=2)) | |
| return report | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--output', type=Path, required=True) | |
| args = parser.parse_args() | |
| print(json.dumps(score(args.output.resolve()), indent=2)) | |