convex_combinations
Expressive losses combining adversarial searches and interval bounds.
get_cc_ibp_loss(*args, **kwargs)
Compute cross-entropy on mixed IBP and adversarial classification margins.
Alpha weights the IBP margin. Arguments and optional returns follow get_expressive_ibp_loss.
Source code in CTRAIN/train/certified/losses/convex_combinations.py
172 173 174 175 176 177 178 | |
get_exp_ibp_loss(*args, **kwargs)
Combine batch-mean IBP and adversarial losses through a geometric mixture.
Alpha weights the logarithm of the IBP loss. Arguments and optional returns follow get_expressive_ibp_loss.
Source code in CTRAIN/train/certified/losses/convex_combinations.py
181 182 183 184 185 186 187 | |
get_expressive_ibp_loss(hardened_model, original_model, ptb, data, target, n_classes, criterion, alpha, return_bounds=False, return_stats=False, restarts=1, step_size=0.2, n_steps=200, pgd_ptb=None, early_stopping=False, decay_checkpoints=(), decay_factor=0.1, device='cuda', relu_upper_retention=1.0, pgd_eps_factor=1.0, data_min=None, data_max=None, eps=None, loss_type=None, *, loss_combination, teacher_features=None, distillation_weight=None)
Construct shared adversarial and IBP components for expressive losses.
MTL-IBP combines their losses through a weighted sum, CC-IBP applies the criterion to their mixed classification margins, and Exp-IBP combines the batch-mean losses geometrically. The parameter alpha weights the IBP component. PGD runs in evaluation mode; loss evaluation uses the caller's mode. Returned IBP bounds concern the nominal input region and are sound only when relu_upper_retention is one. The published objectives use cross-entropy as the criterion.
See De Palma et al. (2024), Expressive Losses for Verified Robustness via Convex Combinations: https://arxiv.org/abs/2305.13991.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hardened_model
|
BoundedModule
|
The bounded model to be trained. |
required |
original_model
|
Module
|
The original model. |
required |
ptb
|
PerturbationLpNorm
|
The perturbation applied to the input data. |
required |
data
|
Tensor
|
Input data. |
required |
target
|
Tensor
|
Target labels. |
required |
n_classes
|
int
|
Number of classes. |
required |
criterion
|
callable
|
Loss function. |
required |
alpha
|
float
|
Weighting factor between robust loss and adversarial loss. |
required |
return_bounds
|
bool
|
If True, returns bounds. |
False
|
return_stats
|
bool
|
If True, returns robustness and adversarial error statistics. |
False
|
restarts
|
int
|
Number of restarts for PGD attack. |
1
|
step_size
|
float
|
Step size for PGD attack. |
0.2
|
n_steps
|
int
|
Number of steps for PGD attack. |
200
|
pgd_ptb
|
PerturbationLpNorm
|
PGD perturbation object. |
None
|
early_stopping
|
bool
|
If True, stops early during PGD attack. |
False
|
decay_checkpoints
|
tuple
|
Checkpoints for decay during PGD attack. |
()
|
decay_factor
|
float
|
Decay factor for PGD attack. |
0.1
|
device
|
str
|
Device to run the computations on. |
'cuda'
|
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
|
data_min
|
Tensor
|
Lower input-domain limit in model coordinates. |
None
|
data_max
|
Tensor
|
Upper input-domain limit in model coordinates. |
None
|
eps
|
Tensor
|
Perturbation radius in model input coordinates. |
None
|
loss_type
|
str
|
Expressive-loss variant selected by the compatibility interface. |
None
|
loss_combination
|
callable
|
Callable combining bound-based and adversarial losses or margins. |
required |
teacher_features
|
Module
|
Frozen teacher feature extractor evaluated on clean inputs. |
None
|
distillation_weight
|
float
|
Feature-distillation weight. None uses 5 divided by the feature width. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing the loss, and optionally certified and adversarial error statistics. |
Source code in CTRAIN/train/certified/losses/convex_combinations.py
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
get_mtl_ibp_loss(hardened_model, original_model, ptb, data, target, n_classes, criterion, alpha, return_bounds=False, return_stats=False, restarts=1, step_size=0.2, n_steps=200, pgd_ptb=None, early_stopping=False, decay_checkpoints=(), decay_factor=0.1, device='cuda', relu_upper_retention=1.0, pgd_eps_factor=1.0, data_min=None, data_max=None, eps=None, loss_type='mtl_ibp')
Compute the weighted sum of IBP and adversarial classification losses.
Alpha weights the IBP component. Arguments and optional returns follow get_expressive_ibp_loss. The legacy loss_type argument also selects CC-IBP or Exp-IBP for callers using the earlier shared interface.
Source code in CTRAIN/train/certified/losses/convex_combinations.py
157 158 159 160 161 162 163 164 165 166 167 168 169 | |
validate_expressive_options(alpha, loss_type=None)
Validate the expressive-loss variant and its IBP mixture weight in [0, 1].
Source code in CTRAIN/train/certified/losses/convex_combinations.py
13 14 15 16 17 18 | |