ML-01a: the training run is the registered routine; its routine records are reported, not required
Not every model has each of the five routine records (a prevalence-incidence mixture has no class balance or
classifier calibration), so requiring all of them blocked promotion of models whose run is in order. The check now
passes when the version comes from its training run and its detail says which records the run holds
("registros de rutina: k de 5 (...)"). A version declared over the API still can't be promoted: it has no saved
model (ML-01b).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
This commit is contained in:
@@ -236,7 +236,10 @@ class ModelRegistry:
|
||||
# A reference cohort outside the platform (TEA's EEG baselines), identified by the hash of its listing.
|
||||
reference = mv.tags.get(COHORT_BUILD_TAG) if mv.tags.get(COHORT_SOURCE_TAG) == REFERENCE_SOURCE else None
|
||||
metrics = run.data.metrics
|
||||
missing = [kind.value for kind in ROUTINE_KINDS if kind.value not in self.routines(mv.run_id)]
|
||||
# ML-01a: the training run is itself the registered routine; its records (`TrainingRun.log_routine`) are
|
||||
# reported, not required, since not every model has each of `ROUTINE_KINDS` (a prevalence-incidence mixture
|
||||
# has no class balance or classifier calibration).
|
||||
recorded = [kind.value for kind in ROUTINE_KINDS if kind.value in self.routines(mv.run_id)]
|
||||
sha = mv.tags.get(MODEL_SHA_TAG, "")
|
||||
if armado is not None:
|
||||
cohort_detail = f"huella {armado['huella'][:12]}"
|
||||
@@ -258,8 +261,9 @@ class ModelRegistry:
|
||||
PromotionCheck("MLD-01", "reporte de pruebas técnicas", bool(mv.tags.get("technical_validation_report_uri")), mv.tags.get("technical_validation_report_uri", "")),
|
||||
PromotionCheck("MLD-01b", "validación clínica documentada", bool(mv.tags.get("clinical_validation_report_uri")), mv.tags.get("clinical_validation_report_uri", "")),
|
||||
PromotionCheck("MLD-03", "reporte de interpretabilidad (pesos, OR/HR)", bool(mv.tags.get("interpretability_report_uri")), mv.tags.get("interpretability_report_uri", "")),
|
||||
PromotionCheck("ML-01a", "rutinas registradas por la corrida de entrenamiento", not missing,
|
||||
f"faltan: {', '.join(missing)}" if missing else f"{len(ROUTINE_KINDS)} de {len(ROUTINE_KINDS)}"),
|
||||
PromotionCheck("ML-01a", "rutina registrada por la corrida de entrenamiento", bool(run.info.run_id),
|
||||
f"corrida {run.info.run_id[:12]}; registros de rutina: {len(recorded)} de {len(ROUTINE_KINDS)}"
|
||||
+ (f" ({', '.join(recorded)})" if recorded else "")),
|
||||
PromotionCheck("ML-01b", "modelo guardado por la corrida de entrenamiento", bool(sha), sha[:12]),
|
||||
]
|
||||
|
||||
|
||||
+20
-13
@@ -21,7 +21,7 @@ def test_dev_version_cannot_be_promoted_and_says_why(governance_db, mlflow_track
|
||||
with pytest.raises(PromotionBlocked) as blocked:
|
||||
registry.promote("cacu", "tamizaje", version)
|
||||
failed = {check.code for check in blocked.value.checks if not check.passed}
|
||||
assert failed == {"ML-02", "ML-03", "MLD-01", "MLD-01b", "MLD-03", "ML-01a", "ML-01b"}
|
||||
assert failed == {"ML-02", "ML-03", "MLD-01", "MLD-01b", "MLD-03", "ML-01b"}
|
||||
|
||||
|
||||
def test_promotion_retires_the_previous_version_of_the_scenario(production_ready):
|
||||
@@ -57,21 +57,28 @@ def test_lineage_lists_every_stored_file_and_each_routine_record(production_read
|
||||
assert lineage["routines"]["BALANCE_CLASES"] == {"method": "prueba", "n": 8}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("routines, model, failing", [
|
||||
([ArtifactKind.MUESTREO], True, "ML-01a"),
|
||||
(None, False, "ML-01b"),
|
||||
])
|
||||
def test_promotion_needs_what_the_training_run_itself_recorded(governance_db, cacu_db, mlflow_tracking, routines, model,
|
||||
failing):
|
||||
"""A run that skipped routine records, or saved no model, is not promoted, whatever else is in order. Fails if
|
||||
the ML-01a check stops requiring every kind in `ROUTINE_KINDS` or the ML-01b check stops requiring `modelo_sha`."""
|
||||
run = trained_run("cacu", "incompleta", armado("huella-x"), {"auc": 0.8}, routines=routines, model=model)
|
||||
def test_promotion_needs_the_model_the_training_run_itself_saved(governance_db, cacu_db, mlflow_tracking):
|
||||
"""A run that saved no model is not promoted, whatever else is in order. Fails if the ML-01b check stops requiring
|
||||
`modelo_sha`."""
|
||||
run = trained_run("cacu", "incompleta", armado("huella-x"), {"auc": 0.8}, routines=None, model=False)
|
||||
version = registry.register_run(run, technical_validation_report_uri="t", clinical_validation_report_uri="c",
|
||||
interpretability_report_uri="i")
|
||||
failed = [check for check in registry.checks("cacu", "incompleta", version) if not check.passed]
|
||||
assert [check.code for check in failed] == [failing]
|
||||
if failing == "ML-01a":
|
||||
assert "DATOS_FALTANTES" in failed[0].detail
|
||||
assert [check.code for check in failed] == ["ML-01b"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("routines, recorded", [([], "0 de 5"), ([ArtifactKind.MUESTREO], "1 de 5 (MUESTREO)")])
|
||||
def test_the_training_run_is_the_registered_routine_and_its_records_are_reported(governance_db, cacu_db,
|
||||
mlflow_tracking, routines, recorded):
|
||||
"""ML-01a: the version's training run is the registered routine, so a model without some routine records (a
|
||||
prevalence-incidence mixture has no class balance) can still be promoted; the check reports which records the
|
||||
run holds. Fails if ML-01a goes back to requiring every kind in `ROUTINE_KINDS`, or stops reporting them."""
|
||||
run = trained_run("cacu", "parcial", armado("huella-x"), {"auc": 0.8}, routines=routines, model=True)
|
||||
version = registry.register_run(run, technical_validation_report_uri="t", clinical_validation_report_uri="c",
|
||||
interpretability_report_uri="i")
|
||||
checks = {check.code: check for check in registry.checks("cacu", "parcial", version)}
|
||||
assert checks["ML-01a"].passed and recorded in checks["ML-01a"].detail
|
||||
assert all(check.passed for check in checks.values())
|
||||
|
||||
|
||||
def test_an_artifact_downloads_as_a_file_and_a_folder_as_a_zip(production_ready):
|
||||
|
||||
Reference in New Issue
Block a user