block checkpoint evaluation on ancestral exposure
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from scripts.evaluate_yolo_checkpoint_matrix import (
|
||||
dataset_overlap_evidence,
|
||||
training_sample_independence_evidence,
|
||||
main,
|
||||
model_lineage_independence_evidence,
|
||||
write_blocked_manifest,
|
||||
)
|
||||
|
||||
@@ -67,7 +69,7 @@ def _write_summary(path: Path, rows: list[tuple[str, str]]) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_training_sample_independence_detects_overlap_for_each_corpus(
|
||||
def test_model_lineage_independence_detects_exposure_in_every_split(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
evaluation = tmp_path / "evaluation"
|
||||
@@ -80,24 +82,25 @@ def test_training_sample_independence_detects_overlap_for_each_corpus(
|
||||
)
|
||||
active = tmp_path / "active.json"
|
||||
challenger = tmp_path / "challenger.json"
|
||||
_write_summary(active, [("postel_bos", "train"), ("mol", "train")])
|
||||
_write_summary(active, [("postel_bos", "train"), ("turnhout", "val")])
|
||||
_write_summary(
|
||||
challenger, [("postel_bos", "train"), ("dessel", "train")]
|
||||
)
|
||||
|
||||
evidence = training_sample_independence_evidence(
|
||||
evidence = model_lineage_independence_evidence(
|
||||
dataset_yaml, [active, challenger]
|
||||
)
|
||||
|
||||
assert evidence["status"] == "overlap"
|
||||
assert evidence["overlapping_evaluation_samples"] == ["postel_bos"]
|
||||
assert evidence["independent_for_all_supplied_training_corpora"] is False
|
||||
assert evidence["overlapping_evaluation_samples"] == ["postel_bos", "turnhout"]
|
||||
assert evidence["independent_for_all_supplied_lineage_corpora"] is False
|
||||
assert [
|
||||
row["overlapping_evaluation_samples"] for row in evidence["training_corpora"]
|
||||
] == [["postel_bos"], ["postel_bos"]]
|
||||
row["overlapping_evaluation_samples"] for row in evidence["lineage_corpora"]
|
||||
] == [["postel_bos", "turnhout"], ["postel_bos"]]
|
||||
assert evidence["lineage_corpora"][0]["exposure_roles"]["turnhout"] == ["val"]
|
||||
|
||||
|
||||
def test_training_sample_independence_accepts_disjoint_samples(tmp_path: Path) -> None:
|
||||
def test_model_lineage_independence_accepts_disjoint_samples(tmp_path: Path) -> None:
|
||||
evaluation = tmp_path / "evaluation"
|
||||
evaluation.mkdir()
|
||||
dataset_yaml = evaluation / "dataset.yaml"
|
||||
@@ -108,14 +111,14 @@ def test_training_sample_independence_accepts_disjoint_samples(tmp_path: Path) -
|
||||
training = tmp_path / "training.json"
|
||||
_write_summary(training, [("mol", "train")])
|
||||
|
||||
evidence = training_sample_independence_evidence(dataset_yaml, [training])
|
||||
evidence = model_lineage_independence_evidence(dataset_yaml, [training])
|
||||
|
||||
assert evidence["status"] == "independent"
|
||||
assert evidence["overlapping_evaluation_samples"] == []
|
||||
assert evidence["independent_for_all_supplied_training_corpora"] is True
|
||||
assert evidence["independent_for_all_supplied_lineage_corpora"] is True
|
||||
|
||||
|
||||
def test_training_sample_independence_is_unavailable_without_training_corpus(
|
||||
def test_model_lineage_independence_is_unavailable_without_ancestral_corpus(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
evaluation = tmp_path / "evaluation"
|
||||
@@ -126,11 +129,11 @@ def test_training_sample_independence_is_unavailable_without_training_corpus(
|
||||
evaluation / "yolo_tile_dataset_summary.json", [("turnhout", "val")]
|
||||
)
|
||||
|
||||
evidence = training_sample_independence_evidence(dataset_yaml, [])
|
||||
evidence = model_lineage_independence_evidence(dataset_yaml, [])
|
||||
|
||||
assert evidence["status"] == "unavailable"
|
||||
assert evidence["overlapping_evaluation_samples"] == []
|
||||
assert evidence["independent_for_all_supplied_training_corpora"] is False
|
||||
assert evidence["independent_for_all_supplied_lineage_corpora"] is False
|
||||
|
||||
|
||||
def test_blocked_manifest_records_that_models_and_gpu_were_not_used(
|
||||
@@ -145,11 +148,51 @@ def test_blocked_manifest_records_that_models_and_gpu_were_not_used(
|
||||
dataset_yaml,
|
||||
{
|
||||
"status": "overlap",
|
||||
"independent_for_all_supplied_training_corpora": False,
|
||||
"independent_for_all_supplied_lineage_corpora": False,
|
||||
},
|
||||
)
|
||||
|
||||
payload = json.loads(output.read_text(encoding="utf-8"))
|
||||
assert payload["status"] == "blocked_training_sample_overlap"
|
||||
assert payload["status"] == "blocked_model_lineage_sample_exposure"
|
||||
assert payload["model_loading_attempted"] is False
|
||||
assert payload["gpu_inference_attempted"] is False
|
||||
|
||||
|
||||
def test_cli_blocks_lineage_validation_exposure_before_model_resolution(
|
||||
tmp_path: Path, monkeypatch
|
||||
) -> None:
|
||||
evaluation = tmp_path / "evaluation"
|
||||
images = evaluation / "images" / "val"
|
||||
images.mkdir(parents=True)
|
||||
(images / "turnhout_r0_c0.png").write_bytes(b"not opened before gate")
|
||||
dataset_yaml = evaluation / "dataset.yaml"
|
||||
dataset_yaml.write_text("path: .\nval: images/val\n", encoding="utf-8")
|
||||
_write_summary(
|
||||
evaluation / "yolo_tile_dataset_summary.json", [("turnhout", "val")]
|
||||
)
|
||||
ancestor = tmp_path / "ancestor.json"
|
||||
_write_summary(ancestor, [("turnhout", "val"), ("mol", "train")])
|
||||
output = tmp_path / "blocked.json"
|
||||
monkeypatch.setattr(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"evaluate_yolo_checkpoint_matrix.py",
|
||||
"--dataset-yaml",
|
||||
str(dataset_yaml),
|
||||
"--model",
|
||||
str(tmp_path / "model-is-never-resolved.pt"),
|
||||
"--output",
|
||||
str(output),
|
||||
"--background-prefix",
|
||||
"background",
|
||||
"--lineage-summary",
|
||||
str(ancestor),
|
||||
"--require-lineage-sample-independence",
|
||||
],
|
||||
)
|
||||
|
||||
assert main() == 3
|
||||
payload = json.loads(output.read_text(encoding="utf-8"))
|
||||
assert payload["status"] == "blocked_model_lineage_sample_exposure"
|
||||
assert payload["model_loading_attempted"] is False
|
||||
|
||||
Reference in New Issue
Block a user