util
Shared validation, model selection, BatchNorm synchronisation and epoch-metric utilities.
EpochMetrics
Accumulate sample-weighted training metrics across full and partial batches.
Source code in CTRAIN/train/certified/util.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
mean(key)
Return the sample-weighted mean of a previously accumulated metric.
Source code in CTRAIN/train/certified/util.py
52 53 54 | |
update(count, **values)
Accumulate batch-mean metrics weighted by the number of examples.
Source code in CTRAIN/train/certified/util.py
46 47 48 49 50 | |
checkpoint_due(epoch, end_epoch, interval)
Return whether a completed epoch is a periodic or final trajectory checkpoint.
Source code in CTRAIN/train/certified/util.py
35 36 37 | |
evaluate_taps_proxy(original_model, hardened_model, data_loader, eps, n_classes, device, propagation='IBP', sabr_args=None, **attack_args)
Evaluate latent-margin proxy accuracy at a fixed perturbation radius.
The feature and classifier split uses IBP or SABR propagation and latent PGD. Caller modes and gradient flags are preserved, so BatchNorm statistics are not updated. This score is used for model selection, not sound certification.
Source code in CTRAIN/train/certified/util.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
evaluate_validation_loss(models, loader, loss_func, device)
Compute sample-weighted validation loss with fixed evaluation-mode BatchNorm statistics.
Source code in CTRAIN/train/certified/util.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
prepare_model_selection(state, loader, eps=None)
Prepare persistent validation-selection state and reject an empty validation loader.
Source code in CTRAIN/train/certified/util.py
141 142 143 144 145 146 147 148 149 | |
resolve_validation_eps(validation_eps, eval_eps)
Resolve validation_eps and its legacy eval_eps alias, rejecting conflicting radii.
Source code in CTRAIN/train/certified/util.py
28 29 30 31 32 | |
restore_model_selection(state, model)
Load selected inference weights if present and return whether restoration occurred.
Source code in CTRAIN/train/certified/util.py
163 164 165 166 167 168 | |
synchronise_bn(original_model, hardened_model, train_loader, device, population=False, loss_fusion_model=None)
Synchronise BatchNorm buffers across the original, bounded and fused models.
Optional population recalibration refreshes running statistics on training data before copying them. Recalibration preserves caller modes and BatchNorm momentum, including on failure.
Source code in CTRAIN/train/certified/util.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
update_model_selection(state, model, score, epoch, *, allow_negative_infinity=False)
Retain the first best-scoring inference weights without rewinding the training trajectory.
Source code in CTRAIN/train/certified/util.py
152 153 154 155 156 157 158 159 160 | |
validate_training_run(train_loader, num_epochs, start_epoch, end_epoch, checkpoint_save_interval, lr_decay_schedule_unit='epoch', *, history=None)
Validate the loader, epoch range, scheduler unit and checkpoint interval; return the exclusive ending epoch.
Source code in CTRAIN/train/certified/util.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
validation_ptb(data, loader, eps)
Construct a clipped validation box from a raw-input radius and the loader's metadata.
Source code in CTRAIN/train/certified/util.py
188 189 190 191 192 193 194 195 196 | |