Set-based trainer API
The wrapper normally calls this trainer.
Train a classifier through centres and correlated output enclosures.
After clean warm-up, a linear radius ramp introduces the set-based loss. Propagation chunks accumulate sample-weighted gradients before one optimiser update per logical loader batch. Clean chunk statistics are reused for BatchNorm propagation. Validation selects full-box forward-LiRPA accuracy after ramp-up; without validation, the final model is returned.
Returns:
| Type | Description |
|---|---|
Module
|
Trained model, with selected inference weights when validation is enabled. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
PyTorch model to train or evaluate. |
required |
train_loader
|
DataLoader
|
Training loader providing input and target batches and any required normalisation metadata. |
required |
optimizer
|
Optimizer
|
Optimiser holding the model parameters and current update state. |
required |
num_epochs
|
int
|
Total training budget, including warm-up and ramp-up. |
required |
eps
|
float or Tensor
|
Target perturbation radius in raw input units, before loader normalisation. |
required |
val_loader
|
DataLoader
|
Optional validation loader used for model selection. Without it, training returns the final weights. |
None
|
eval_eps
|
float or Tensor
|
Legacy name for validation_eps. Supplying conflicting values is rejected. |
None
|
warm_up_epochs
|
int
|
Initial epochs using only the natural task loss. |
1
|
ramp_up_epochs
|
int
|
Epochs over which the perturbation radius increases to its training target. |
20
|
lr_scheduler
|
LRScheduler
|
Learning-rate scheduler associated with the supplied optimiser. |
None
|
tau
|
float
|
Weight of the output-enclosure penalty, with 1 - tau weighting centre cross-entropy. |
0.1
|
input_set
|
str
|
Training input representation: 'box' or an attack-generated 'zonotope'. |
'box'
|
num_generators
|
int
|
Number of attack directions used to construct an input zonotope. |
8
|
error_propagation
|
str
|
Whether nonlinear interval errors remain an 'interval' or become explicit 'generators'. |
'interval'
|
propagation_batch_size
|
int
|
Maximum number of inputs propagated together to limit bound-computation memory. |
1
|
pgd_eps_factor
|
float
|
Positive factor scaling the PGD search range, independently of the nominal bound region. |
1.0
|
population_bn
|
bool
|
Whether to recalibrate BatchNorm on training data after each epoch, before model selection and saving. |
False
|
gradient_clip
|
float
|
Maximum parameter-gradient norm. None disables clipping where supported. |
10.0
|
start_epoch
|
int
|
Zero-based starting epoch in the full training schedule. |
0
|
end_epoch
|
int
|
Exclusive ending epoch. None runs to the end of the configured schedule. |
None
|
results_path
|
str or Path
|
Directory for the results or checkpoints written by this function. |
None
|
checkpoint_save_interval
|
int
|
Save an epoch checkpoint at this interval and at the end of the training call. |
10
|
device
|
str or device
|
Device on which to run the model and tensor computations. |
'cpu'
|
selection_state
|
dict
|
Mutable dictionary retaining the best validation score, inference weights and epoch across training calls. |
None
|
validation_eps
|
float or Tensor
|
Fixed raw-input radius used for validation; None uses the training target. |
None
|
lr_decay_schedule_unit
|
str
|
Whether to advance the learning-rate scheduler per 'epoch' or per 'batch'. |
'epoch'
|
history
|
list
|
Optional list to which the trainer appends per-epoch losses, radii and learning rates. |
None
|
Source code in CTRAIN/train/certified/set_based.py
55 56 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 101 102 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |