Upload eval/eval_bert_partD.py
Browse files- eval/eval_bert_partD.py +54 -0
eval/eval_bert_partD.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# ── Results ──
|
| 3 |
+
fr = policies['frontier']
|
| 4 |
+
fr_cost = fr['cost'] / fr['n']
|
| 5 |
+
fr_succ = fr['success'] / fr['n']
|
| 6 |
+
|
| 7 |
+
print(f"\n\n{'='*70}")
|
| 8 |
+
print("BERT vs XGBoost ROUTER COMPARISON ON SWE-BENCH")
|
| 9 |
+
print(f"{'='*70}")
|
| 10 |
+
print(f"\n{'Policy':<20} {'Success':>10} {'AvgCost':>10} {'CostRed':>10}")
|
| 11 |
+
print("-"*52)
|
| 12 |
+
for name in ['oracle','bert_feedback','v11_feedback','bert','v11_xgboost','frontier','always_cheap']:
|
| 13 |
+
if name not in policies: continue
|
| 14 |
+
r = policies[name]
|
| 15 |
+
sr = r['success']/r['n'] if r['n'] > 0 else 0
|
| 16 |
+
ac = r['cost']/r['n'] if r['n'] > 0 else 0
|
| 17 |
+
cr = (1-ac/fr_cost)*100 if fr_cost > 0 else 0
|
| 18 |
+
print(f"{name:<20} {sr:>10.3f} {ac:>10.4f} {cr:>9.1f}%")
|
| 19 |
+
|
| 20 |
+
print(f"\nQuality gap vs frontier:")
|
| 21 |
+
for name in ['bert','bert_feedback','v11_xgboost','v11_feedback']:
|
| 22 |
+
r = policies[name]
|
| 23 |
+
sr = r['success']/r['n'] if r['n'] > 0 else 0
|
| 24 |
+
gap = (sr - fr_succ) * 100
|
| 25 |
+
print(f" {name}: {gap:+.1f}pp vs frontier")
|
| 26 |
+
|
| 27 |
+
# BERT tier distribution
|
| 28 |
+
print(f"\nBERT tier distribution:")
|
| 29 |
+
bert_tiers = defaultdict(int)
|
| 30 |
+
for iid, model_results in list(traces.items())[:500]:
|
| 31 |
+
problem = next(iter(model_results.values()))['problem']
|
| 32 |
+
t, c = route_bert(problem)
|
| 33 |
+
bert_tiers[t] += 1
|
| 34 |
+
for t in sorted(bert_tiers):
|
| 35 |
+
print(f" Tier {t}: {bert_tiers[t]}")
|
| 36 |
+
|
| 37 |
+
# Save results
|
| 38 |
+
results = {}
|
| 39 |
+
for name, r in policies.items():
|
| 40 |
+
sr = r['success']/r['n'] if r['n'] > 0 else 0
|
| 41 |
+
ac = r['cost']/r['n'] if r['n'] > 0 else 0
|
| 42 |
+
cr = (1-ac/fr_cost)*100 if fr_cost > 0 else 0
|
| 43 |
+
results[name] = {"success": round(sr, 4), "avg_cost": round(ac, 4), "costRed": round(cr, 1)}
|
| 44 |
+
|
| 45 |
+
from huggingface_hub import HfApi
|
| 46 |
+
import tempfile
|
| 47 |
+
api = HfApi()
|
| 48 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
| 49 |
+
json.dump(results, f, indent=2)
|
| 50 |
+
api.upload_file(path_or_fileobj=f.name, path_in_repo="eval/bert_vs_xgboost_results.json",
|
| 51 |
+
repo_id="narcolepticchicken/agent-cost-optimizer", repo_type="model")
|
| 52 |
+
os.unlink(f.name)
|
| 53 |
+
print(f"\nResults uploaded to eval/bert_vs_xgboost_results.json")
|
| 54 |
+
print("DONE!")
|