eps_scheduler
Schedule perturbation radii and loss-mixture weights during certified training.
BaseScheduler
Store the perturbation and loss-mixture schedule shared by certified trainers.
The scheduler tracks raw-input epsilon together with kappa and beta. Epsilon can be returned in model coordinates using the supplied normalisation statistics. LinearScheduler and SmoothedScheduler implement the updates.
Source code in CTRAIN/train/certified/eps_scheduler.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 | |
__init__(num_epochs, eps, mean, std, start_eps=0, start_kappa=1, end_kappa=0, start_beta=0, end_beta=0, eps_schedule_unit='batch', eps_schedule=(0, 20), batches_per_epoch=None, start_epoch=-1)
Configure perturbation and mixture schedules with input-normalisation metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_epochs
|
int
|
The number of epochs for training. |
required |
eps
|
float
|
The epsilon value for the scheduler. |
required |
mean
|
float
|
The mean value for normalisation. |
required |
std
|
float
|
The standard deviation value for normalisation. |
required |
start_eps
|
float
|
The starting epsilon value. |
0
|
start_kappa
|
float
|
The starting kappa value. |
1
|
end_kappa
|
float
|
The ending kappa value. |
0
|
start_beta
|
float
|
The starting beta value. |
0
|
end_beta
|
float
|
The ending beta value. |
0
|
eps_schedule_unit
|
str
|
The unit for epsilon scheduling ('batch' or 'epoch'). |
'batch'
|
eps_schedule
|
tuple
|
Warm-up, ramp-up and remaining training durations in the selected scheduling unit. |
(0, 20)
|
batches_per_epoch
|
int
|
Positive number of training batches per epoch, required for both scheduling units. |
None
|
start_epoch
|
int
|
Starting epoch used to initialise the batch counter; -1 denotes a new schedule. |
-1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Invalid schedule durations, epoch budget, batch count, normalisation statistics or mixture endpoints. |
Source code in CTRAIN/train/certified/eps_scheduler.py
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 | |
batch_step(metric=None)
Define the batch-step interface; derived schedulers implement the numerical update.
Source code in CTRAIN/train/certified/eps_scheduler.py
126 127 128 | |
get_cur_beta()
Return the current CROWN-IBP bound-mixture weight.
Source code in CTRAIN/train/certified/eps_scheduler.py
118 119 120 | |
get_cur_eps(normalise=True)
Return the current perturbation radius, optionally divided by the input standard deviation.
Source code in CTRAIN/train/certified/eps_scheduler.py
104 105 106 107 108 109 110 111 112 | |
get_cur_kappa()
Return the current natural-loss mixture weight.
Source code in CTRAIN/train/certified/eps_scheduler.py
114 115 116 | |
get_max_eps(normalise=True)
Return the target perturbation radius, optionally divided by the input standard deviation.
Source code in CTRAIN/train/certified/eps_scheduler.py
122 123 124 | |
LinearScheduler
Bases: BaseScheduler
Increase epsilon linearly while interpolating the loss-mixture weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_epochs
|
int
|
Total number of epochs for training. |
required |
eps
|
float
|
The target epsilon value. |
required |
mean
|
float
|
The mean value for normalisation. |
required |
std
|
float
|
The standard deviation value for normalisation. |
required |
start_eps
|
float
|
The starting epsilon value. |
0
|
start_kappa
|
float
|
The starting kappa value. |
1
|
end_kappa
|
float
|
The ending kappa value. |
0
|
start_beta
|
float
|
The starting beta value. |
1
|
end_beta
|
float
|
The ending beta value. |
0
|
eps_schedule_unit
|
str
|
The unit for epsilon scheduling ('batch' or 'epoch'). |
'batch'
|
eps_schedule
|
tuple
|
Warm-up, ramp-up and remaining training durations in the selected scheduling unit. |
(0, 20)
|
batches_per_epoch
|
int
|
Positive number of training batches per epoch, required for both scheduling units. |
None
|
start_epoch
|
int
|
Starting epoch used to initialise the batch counter; -1 denotes a new schedule. |
-1
|
Methods:
| Name | Description |
|---|---|
batch_step |
Adjusts the current epsilon, kappa, and beta values based on the current batch number. |
Source code in CTRAIN/train/certified/eps_scheduler.py
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 | |
batch_step(metric=None)
Advance epsilon and mixture weights by one training batch.
Source code in CTRAIN/train/certified/eps_scheduler.py
178 179 180 181 182 183 184 185 | |
SmoothedScheduler
Bases: BaseScheduler
Increase epsilon through a polynomial segment followed by a matched linear ramp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_epochs
|
int
|
Number of epochs for training. |
required |
eps
|
float
|
Final epsilon value. |
required |
mean
|
float
|
Mean value for normalisation. |
required |
std
|
float
|
Standard deviation value for normalisation. |
required |
start_eps
|
float
|
Initial epsilon value. |
0
|
start_kappa
|
float
|
Initial kappa value. |
1
|
end_kappa
|
float
|
Final kappa value. |
0
|
start_beta
|
float
|
Initial beta value. |
1
|
end_beta
|
float
|
Final beta value. |
0
|
eps_schedule_unit
|
str
|
Unit for epsilon scheduling ('batch' or 'epoch'). |
'batch'
|
batches_per_epoch
|
int
|
Positive number of training batches per epoch, required for both scheduling units. |
None
|
start_epoch
|
int
|
Starting epoch used to initialise the batch counter; -1 denotes a new schedule. |
-1
|
eps_schedule
|
tuple
|
Warm-up, ramp-up and remaining training durations in the selected scheduling unit. |
(0, 20)
|
midpoint
|
float
|
Ramp fraction where epsilon changes from polynomial growth to a matched linear segment. |
0.25
|
exponent
|
float
|
Power of the initial polynomial epsilon-growth segment. |
4.0
|
Methods:
| Name | Description |
|---|---|
batch_step |
Updates the current epsilon, kappa, and beta values based on the current batch number. |
Source code in CTRAIN/train/certified/eps_scheduler.py
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 | |
batch_step(metric=None)
Advance epsilon and mixture weights by one training batch.
Source code in CTRAIN/train/certified/eps_scheduler.py
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 | |
linear_schedule_fraction(epoch, batch, batches, warm_up_epochs, ramp_up_epochs, *, at_batch_end=False)
Return progress through a linear ramp at the requested batch boundary.
Warm-up returns zero and completed ramp-up returns one. at_batch_end selects whether the current batch contributes to the ramp fraction.
Source code in CTRAIN/train/certified/eps_scheduler.py
8 9 10 11 12 13 14 15 16 17 18 19 | |