Closed HeinrichAD closed 2 years ago
Hi @HeinrichAD,
Thanks for your interest in our project!
The formula used to compute certificate require the function to be 1-lipschitz to be valid.
The general formula should be :
M=(top1 - top2)/(sqrt(2)*L)
Where L is the Lipschitz constant of the network. ( see this paper and this paper )
The function torchlip.utils.evaluate_lip_const
, is not advised for this use. It is important to recall that computing the Lipschitz constant of a network is a NP-hard problem. The function you mentioned use the naive method and is used for unit testing purposes. Using it in this context would probably give broken certificates.
Feel free to take a look at this paper learn more about methods to evaluate the Lipschitz constant of a network.
@cofri should we update the doc of this function ?
Thanks. I will look into the papers. I will close the issue and reopen it later if necessary. My intention was the compare Lipschitz and "vanilla" trained models.
As side note: If it's only for testing everything is fine, but torchlip.utils.evaluate_lip_const
has no GPU support.
Inside, torch.distributions.Uniform
creates a new Tensor based on its low
parameter. Currently, it's just a float value. Hence, it will result always in an CPU tensor.
A possible solution would be to pass low
as tensor which is on the same device like the inputs (x
) or model
.
Hello @HeinrichAD, To compare Lipschitz and "vanilla" models in terms of robustness, a standard way is to run L2 adversarial attacks. It is then possible to see which model is more robust to the attack. Note that this method does not give any guarantee; it's an empirical result.
On the other hand concerning robustness guarantees, the certificates can be computed using the formula given by @thib-s. This formulation is valid for both Lipschitz and "vanilla" models and involves the Lipschitz constant of the network. For a Lipschitz model, this is straightforward as we know the Lipschitz constant of all layers (default to 1 in deel-torchlip). However for a "vanilla" model, the Lipschitz constant computation is not trivial. But if you can compute it accurately, you can use the same formula to get certificates for the "vanilla" model.
Moreover, thank you for your tip on GPU support. It is indeed implemented for testing but we keep in mind your solution to extend to GPU support.
Are certificates also available for non lipschitz trained models?
Example: If you look at your example 4 "HKR multiclass and fooling" and use the
vanilla_export()
already before the training (and train with CrossEntropyLoss), the certificate values looks much better. But the certificate guarantee $\epsilon \geq \mathcal{M}$ seems to be broken.Examples values from example 4:
(modified version)
Vanilla
Lipschitz
Edit: Could
torchlip.utils.evaluate_lip_const
be should to compare lipschitz and vanilla trained models?