Skip to content

Bound APIs

Use the wrapper evaluation interfaces for ordinary robustness reporting. Lower-level integrations can call IBP, CROWN, SABR, TAPS, or set propagation. SABR/TAPS training bounds and approximate ReLU surrogates do not automatically supply full input-region certificates.

For affine/Boolean output specifications over declared boxes, see property bounds.

Forward LiRPA evaluation uses same-slope ReLUs and the full clipped input box:

Compute full-region classification-margin bounds using forward LiRPA.

Evaluation uses same-slope ReLU relaxations over the complete supplied box. The function returns lower and optional upper margin bounds without retaining an autograd graph and restores the caller's relaxation settings.

Source code in CTRAIN/bound/forward.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def bound_forward(model, ptb, data, target, n_classes=10,
                  bound_upper=False, reuse_input=False):
    """Compute full-region classification-margin bounds using forward LiRPA.

    Evaluation uses same-slope ReLU relaxations over the complete supplied box.
    The function returns lower and optional upper margin bounds without retaining
    an autograd graph and restores the caller's relaxation settings.
    """
    relaxations = {node: node.relu_options for node in model.modules()
                   if isinstance(node, BoundRelu)}
    try:
        for node in relaxations:
            node.relu_options = 'same-slope'
        with torch.no_grad():
            return model.compute_bounds(
                x=None if reuse_input else (BoundedTensor(data, ptb),),
                C=construct_c(data, target, n_classes), method='Forward',
                bound_upper=bound_upper)
    finally:
        for node, option in relaxations.items():
            node.relu_options = option