Training Guide¶
This guide covers the v0.6.0 trainer loop and how to combine SCM semantics with coverage-aware optimisation.
Trainer Overview¶
zeroproofml.training.trainer.SCMTrainerimplements the reference loop with mixed precision, gradient accumulation, and coverage-based early stopping.zeroproofml.training.targets.lift_targetsis the legacy/simple sentinel path for finite values plusNaN/Infbottom labels. It remains supported for compatibility and small demos, but it is not the preferred audit path because sentinels cannot distinguish censored, domain-invalid, missing, and fault labels.- For auditable datasets with explicit label semantics, prefer
zeroproofml.training.targets.lift_semantic_targets(values, status_labels)with status labelsfinite,bottom,censored_below,censored_above,domain_invalid,missing, orfault. It returnsSemanticTargetscarrying(Y_n, Y_d), finite/bottom masks, censored orientation labels, and bottom-kind codes that distinguish semantic bottoms from faults. SCMTraineraccepts typed batches as(inputs, values, status_labels)and passes asemantic_targetskeyword argument to loss functions that opt into it. Losses should use that object to mask labels such asmissing, which are neither finite training targets nor bottom targets.- Thresholds are perturbed per batch (
perturbed_threshold) to reduce train/infer gaps.
TrainingConfig¶
zeroproofml.training.trainer.TrainingConfig controls the trainer loop:
- Epochs/updates:
max_epochs,gradient_accumulation_steps - AMP:
mixed_precision(alias:use_amp) andamp_dtype - Thresholds:
tau_train_min,tau_train_max, and stricttau_infer - Coverage early-stop:
coverage_threshold,coverage_patience - Logging:
log_hook(metrics)(see15_debug_logging.md) - Validation:
val_loaderruns once per epoch; aggregated metrics are stored intrainer.val_historyand emitted tolog_hookwithval_-prefixed keys. - Gradient policy override:
gradient_policyapplies a globalGradientPolicyoverride during training steps (see03_gradient_policies.md). - Bottom capability check: if lifted targets contain bottom labels (
inf/NaN) and a projective head reportsbottom_capability(tau_infer) == "unreachable_by_construction", the trainer raises before optimizing. Useallow_bottom_unreachable=Trueonly when those labels are intentional noise or outside the current task. - Loss curricula (optional):
loss_curriculumcan produce per-epochloss_weightsthat are passed into loss functions that acceptloss_weights(andepoch/global_step).
Typical Flow¶
- Prepare data with explicit semantic status labels when available; the
trainer lifts
(inputs, values, status_labels)batches to(Y_n, Y_d). - Select gradient policy (usually
CLAMPfor SCM-only graphs orPROJECTfor projective heads). - Assemble losses: implicit + margin + sign consistency + rejection (via
SCMTrainingLoss). - Train loop:
- forward pass (SCM or projective mode),
- compute losses and coverage,
- backprop using the active gradient policy,
- update optimiser (supports AMP via
torch.ampon PyTorch 2.x). - Monitor coverage; early stop when coverage stays below
coverage_thresholdforcoverage_patienceepochs.
Tips¶
- Treat NaN outputs as ⊥ when computing coverage during training.
- Keep
τ_train_minandτ_train_maxclose unless you specifically need stronger perturbations. - Log
last_thresholdsfrom the trainer to understand how often the model sees near-singular regimes.