TAPS
Functional training procedure for TAPS, including schedules, validation and checkpoints.
taps_train_model(original_model, hardened_model, train_loader, val_loader=None, start_epoch=0, end_epoch=None, num_epochs=None, eps=0.3, eps_std=0.3, eps_schedule=(0, 20, 50), eps_schedule_unit='epoch', eps_scheduler_args=dict(), optimizer=None, lr_scheduler=None, lr_decay_schedule_unit='epoch', n_classes=10, gradient_clip=None, l1_regularisation_weight=1e-05, shi_regularisation_weight=0.5, shi_reg_decay=True, gradient_expansion_alpha=5.0, taps_pgd_steps=20, taps_pgd_step_size=None, taps_pgd_restarts=1, taps_pgd_decay_factor=0.2, taps_pgd_decay_checkpoints=(5, 7), taps_gradient_link_thresh=0.5, taps_gradient_link_tolerance=1e-05, checkpoint_save_interval=10, results_path='./results', device='cuda', population_bn=False, validation_eps=None, relu_upper_retention=1.0, pgd_eps_factor=1.0, selection_state=None, *, history=None)
Train a classifier through IBP feature bounds and latent adversarial margins.
TAPS splits the network into a feature extractor and classifier, then combines latent-search and interval losses after warm-up and ramp-up. Validation selects latent-margin proxy accuracy at validation_eps after ramp-up; this score is not certified accuracy. Without validation, the trainer returns the final model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_model
|
Module
|
The original model to be trained. |
required |
hardened_model
|
BoundedModule
|
The bounded model to be trained. |
required |
train_loader
|
DataLoader
|
DataLoader for the training data. |
required |
val_loader
|
DataLoader
|
Optional validation data. Selects the best model by full-epsilon latent-margin accuracy after ramp-up; otherwise returns the final model. |
None
|
start_epoch
|
int
|
Starting epoch for training. |
0
|
end_epoch
|
int
|
Epoch to prematurely end training at. |
None
|
num_epochs
|
int
|
Number of epochs to train the model. |
None
|
eps
|
float
|
Epsilon value for perturbation. |
0.3
|
eps_std
|
float
|
Legacy normalised-radius argument, retained for positional compatibility; the scheduler uses eps and loader metadata. |
0.3
|
eps_schedule
|
tuple
|
Warm-up, ramp-up and remaining training durations in the selected scheduling unit. |
(0, 20, 50)
|
eps_schedule_unit
|
str
|
Unit for epsilon schedule ('epoch' or 'batch'). |
'epoch'
|
eps_scheduler_args
|
dict
|
Additional arguments for the epsilon scheduler. |
dict()
|
optimizer
|
Optimizer
|
Optimizer for training. |
None
|
lr_scheduler
|
LRScheduler
|
Learning-rate scheduler associated with the supplied optimiser. |
None
|
lr_decay_schedule_unit
|
str
|
Unit for learning rate decay schedule ('epoch' or 'batch'). |
'epoch'
|
n_classes
|
int
|
Number of classes in the dataset. |
10
|
gradient_clip
|
float
|
Value for gradient clipping. |
None
|
l1_regularisation_weight
|
float
|
Weight for L1 regularisation. |
1e-05
|
shi_regularisation_weight
|
float
|
Weight for SHI regularisation. |
0.5
|
shi_reg_decay
|
bool
|
Whether to decay SHI regularisation. |
True
|
gradient_expansion_alpha
|
float
|
Alpha value for gradient expansion. |
5.0
|
taps_pgd_steps
|
int
|
Number of PGD steps for TAPS. |
20
|
taps_pgd_step_size
|
float
|
Step size for PGD in TAPS. |
None
|
taps_pgd_restarts
|
int
|
Number of PGD restarts for TAPS. |
1
|
taps_pgd_decay_factor
|
float
|
Decay factor for PGD in TAPS. |
0.2
|
taps_pgd_decay_checkpoints
|
tuple
|
Checkpoints for PGD decay in TAPS. |
(5, 7)
|
taps_gradient_link_thresh
|
float
|
Threshold for gradient linking in TAPS. |
0.5
|
taps_gradient_link_tolerance
|
float
|
Tolerance for gradient linking in TAPS. |
1e-05
|
checkpoint_save_interval
|
int
|
Interval for saving checkpoints. |
10
|
results_path
|
str
|
Path to save training results. |
'./results'
|
device
|
str
|
Device to use for training ('cuda' or 'cpu'). |
'cuda'
|
population_bn
|
bool
|
Recalibrate BatchNorm on the training loader after each epoch. |
False
|
validation_eps
|
float
|
Evaluation radius for checkpoint selection; defaults to training epsilon. |
None
|
relu_upper_retention
|
float
|
Retained unstable ReLU upper bound fraction for training; default 1. |
1.0
|
pgd_eps_factor
|
float
|
PGD search range factor; does not change nominal IBP bounds. |
1.0
|
selection_state
|
dict
|
Mutable dictionary retaining the best validation score, inference weights and epoch across training calls. |
None
|
history
|
list
|
Optional list to which the trainer appends per-epoch losses, radii and learning rates. |
None
|
Returns:
| Type | Description |
|---|---|
BoundedModule
|
The trained hardened model. |
Source code in CTRAIN/train/certified/taps.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |