Datasets:
Formats:
parquet
Languages:
English
Size:
10K - 100K
Tags:
agriculture
plant-disease
crop-disease
vision-language-model
retrieval-augmented-generation
memory
License:
Download code/verify_release.py from tirtho149/MACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.79 kB
-
https://huggingface.co/datasets/tirtho149/MACE-Bench/resolve/main/code/verify_release.py
- Command line
-
hf download hf://datasets/tirtho149/MACE-Bench/code/verify_release.py
-
curl -L -o verify_release.py https://huggingface.co/datasets/tirtho149/MACE-Bench/resolve/main/code/verify_release.py
3.79 kB
| """Check that this release reproduces the MACE study without model calls. | |
| cd code && mkdir -p .cache && tar -xzf ../cache/llm.tar.gz -C .cache | |
| AGMEM_DATA=$PWD/../benchmark python verify_release.py | |
| 1. Rebuilds every evaluation job (all packages, including the 2026-11-05 amendment P8 and P9) from benchmark/ and | |
| study/, and compares each job, with its exact memory list, to study/evaluation_jobs.jsonl.gz. | |
| 2. Recomputes the request hash of every caption and every text diagnosis and checks that the cached reply exists, which | |
| means the prompt is reproduced byte for byte and a rerun replays the recorded answer at no cost. | |
| 3. Checks that each cached diagnosis reply gives the prediction stored in runs/<package>/predictions.jsonl. | |
| Agentic (P6) and image-reference (P7) calls are not hashed here; their records are in cache/agentic.tar.gz and the traces. | |
| """ | |
| import gzip | |
| import json | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| from agmem import config as C, data, kb as KB, llm, packet, prompts | |
| from mace10 import amend, conditions, jobs | |
| def diag_key(j, caps, kbd, classes): | |
| """Request hash of a text diagnosis, built exactly as mace10/run.py builds the request.""" | |
| if j["condition"] == "sage": | |
| text, _ = packet.build(j["crop"], kbd, caps[j["image_id"]], None) | |
| else: | |
| memory = [{"id": "m_" + m["image_id"], "label_shown": m["label"], "label_true": m["label"], "caption": caps[m["image_id"]]} for m in j["memory"]] | |
| text, _, refs = conditions.build(j["variant"], j["crop"], kbd, caps[j["image_id"]], memory, j["image_id"], classes, j.get("retrieved_ids")) | |
| assert not refs | |
| content = [llm.image_block(data.path(j["image_id"])), {"type": "text", "text": prompts.diagnosis_user(j["crop"], classes, text)}] | |
| return llm.sha({"m": C.MODEL, "s": prompts.DIAG_SYS, "c": content}) | |
| REL = Path(__file__).resolve().parent.parent | |
| saved = {j["job_id"]: j for j in (json.loads(l) for l in gzip.open(REL / "study/evaluation_jobs.jsonl.gz", "rt"))} | |
| built = {j["job_id"]: j for j in jobs.build() + amend.build()} | |
| diff = [k for k in saved if json.dumps(built.get(k), sort_keys=True) != json.dumps(saved[k], sort_keys=True)] | |
| print(f"1. jobs rebuilt {len(built)}, saved {len(saved)}, differing {len(diff)}") | |
| caps = json.loads((REL / "captions.json").read_text()) | |
| miss_cap = [i for i in caps if not jobs.cached(jobs.caption_key(i, data.images().loc[i, "crop"]))] | |
| print(f"2. captions {len(caps)}, cache misses {len(miss_cap)}") | |
| pred = {} | |
| for p in (REL / "runs").glob("P*/predictions.jsonl"): | |
| for l in p.open(): | |
| r = json.loads(l); pred[r["job_id"]] = r | |
| kbs = {} | |
| hit, miss, agree = Counter(), Counter(), Counter() | |
| for j in saved.values(): | |
| if j["condition"] in ("agentic", "imageref", "imageref_dev"): | |
| continue | |
| c = j["crop"] | |
| if c not in kbs: | |
| kbs[c] = (KB.build(c, data.classes(c)), data.classes(c)) | |
| k = diag_key(j, caps, *kbs[c]) | |
| tag = (j["pkg"], j["condition"]) | |
| if k and jobs.cached(k): | |
| hit[tag] += 1 | |
| rep = json.loads((C.CACHE / "llm" / f"{k}.json").read_text()) | |
| p = prompts.clean_prediction(llm.parse_json(rep["text"]), kbs[c][1]) | |
| if j["job_id"] in pred and p.get("prediction") == pred[j["job_id"]]["prediction"]: | |
| agree[tag] += 1 | |
| else: | |
| miss[tag] += 1 | |
| for t in sorted(set(hit) | set(miss)): | |
| print(f" {t[0]:<4} {t[1]:<13} cache hits {hit[t]:>5} misses {miss[t]:>3} reply = saved prediction {agree[t]:>5}") | |
| ok = not diff and not miss_cap and not sum(miss.values()) and sum(agree.values()) == sum(hit.values()) | |
| print("3. all text diagnoses replayed:", sum(hit.values()), "| replies matching saved predictions:", sum(agree.values())) | |
| print("RELEASE REPRODUCES" if ok else "MISMATCH FOUND") | |
| sys.exit(0 if ok else 1) | |