sabr
Select adversarial input subregions and compute SABR training bounds.
bound_sabr(hardened_model, original_model, data, target, eps, subselection_ratio, device='cuda', n_classes=10, x_L=None, x_U=None, data_min=None, data_max=None, n_steps=8, step_size=0.5, restarts=1, early_stopping=True, intermediate_bound_model=None, decay_factor=0.1, decay_checkpoints=(4, 7), return_adv_output=False, pgd_ptb=None, relu_upper_retention=1.0, pgd_eps_factor=1.0)
Compute training bounds over an adversarially selected input subregion.
SABR uses PGD to select a difficult point, then propagates a smaller, contained region around that point using IBP. These bounds describe the selected subregion and do not certify the full nominal perturbation region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hardened_model
|
BoundedModule
|
The auto_LiRPA model. |
required |
original_model
|
Module
|
The original neural network model. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
eps
|
float
|
Perturbation radius in model input coordinates. |
required |
subselection_ratio
|
float
|
The ratio for subselection of the epsilon for the IBP bounding during SABR. |
required |
device
|
str
|
The device to run the computation on. |
'cuda'
|
n_classes
|
int
|
The number of classes for classification. |
10
|
x_L
|
Tensor
|
The lower bound of the input data. |
None
|
x_U
|
Tensor
|
The upper bound of the input data. |
None
|
data_min
|
Tensor
|
The minimum value of the input data. |
None
|
data_max
|
Tensor
|
The maximum value of the input data. |
None
|
n_steps
|
int
|
The number of steps for the attack. |
8
|
step_size
|
float
|
The step size for the attack. |
0.5
|
restarts
|
int
|
The number of restarts for the attack. |
1
|
early_stopping
|
bool
|
Whether to use early stopping. |
True
|
intermediate_bound_model
|
Module
|
The intermediate bound model. If provided, the SABR bounds of the intermediate model are returned. This is needed during STAPS bound calculation. |
None
|
decay_factor
|
float
|
The decay factor for the attack. |
0.1
|
decay_checkpoints
|
tuple
|
The decay checkpoints for the attack. |
(4, 7)
|
return_adv_output
|
bool
|
Whether to return the adversarial output. |
False
|
pgd_ptb
|
PerturbationLpNorm
|
Alternate bounds for the PGD
centre search. The resulting SABR box is still clamped to the
nominal region described by |
None
|
relu_upper_retention
|
float
|
Unstable ReLU upper bound fraction for this training bound; default 1. Values below 1 are not sound certificates. |
1.0
|
pgd_eps_factor
|
float
|
Positive PGD search-range factor; nominal IBP bounds are unchanged. Explicit pgd_ptb, when provided, takes precedence. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor, Tensor]
|
The lower and upper bounds of the model's output, and the adversarial output if return_adv_output is True. |
Source code in CTRAIN/bound/sabr.py
13 14 15 16 17 18 19 20 21 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 | |
get_propagation_region(model, data, target, subselection_ratio, step_size, n_steps, restarts, x_L=None, x_U=None, data_min=None, data_max=None, eps=None, early_stopping=True, decay_factor=0.1, decay_checkpoints=(4, 7), pgd_x_L=None, pgd_x_U=None, *, loss_fn=None, is_success=None)
Select a contained SABR subregion around a PGD-generated point.
The half-width in each coordinate is subselection_ratio times the nominal interval half-width. Clipping the centre keeps this subregion inside the nominal box, including at input boundaries. Separate PGD endpoints may widen the search without enlarging the region used for propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The neural network model. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
subselection_ratio
|
float
|
The ratio for subselection. |
required |
step_size
|
float
|
The step size for the attack. |
required |
n_steps
|
int
|
The number of steps for the attack. |
required |
restarts
|
int
|
The number of restarts for the attack. |
required |
x_L
|
Tensor
|
The lower bound of the input data. |
None
|
x_U
|
Tensor
|
The upper bound of the input data. |
None
|
data_min
|
Tensor
|
The minimum value of the input data. |
None
|
data_max
|
Tensor
|
The maximum value of the input data. |
None
|
eps
|
float
|
Perturbation radius in model input coordinates. |
None
|
early_stopping
|
bool
|
Whether to use early stopping. |
True
|
decay_factor
|
float
|
The decay factor for the attack. |
0.1
|
decay_checkpoints
|
tuple
|
The decay checkpoints for the attack. |
(4, 7)
|
pgd_x_L
|
Tensor
|
Alternate lower bound for the PGD search. |
None
|
pgd_x_U
|
Tensor
|
Alternate upper bound for the PGD search. |
None
|
loss_fn
|
callable
|
Optional per-example attack objective to maximise, called as loss_fn(output, target). |
None
|
is_success
|
callable
|
Optional per-example Boolean counterexample test, called as is_success(output, target). |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, float, Tensor]
|
The propagation inputs, tau value, and adversarial examples. |
Source code in CTRAIN/bound/sabr.py
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 | |