Verified-Intelligence / auto_LiRPA

auto_LiRPA: An Automatic Linear Relaxation based Perturbation Analysis Library for Neural Networks and General Computational Graphs
https://arxiv.org/pdf/2002.12920
Other
269 stars 67 forks source link

Heaviside IBP Fails #62

Closed cherrywoods closed 6 months ago

cherrywoods commented 6 months ago

Describe the bug Computing bounds of the Heaviside function using IBP fails.

To Reproduce

>>> import torch
>>> from torch import nn
>>> from auto_LiRPA import BoundedModule, BoundedTensor, PerturbationLpNorm
>>> class TestModule(nn.Module):
...     def forward(self, x):
...         return torch.heaviside(x, torch.ones(1))
... 
>>> module = BoundedModule(TestModule(), torch.empty(1, 5))
>>> ptb = PerturbationLpNorm(x_L=-torch.ones(10, 5), x_U=torch.ones(10, 5))
>>> x = BoundedTensor(torch.zeros(10, 5), ptb)
>>> module.compute_bounds(x=(x,), method="ibp")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/david/.miniconda3/envs/auto_LiRPA/lib/python3.10/site-packages/auto_LiRPA-0.4.0-py3.10.egg/auto_LiRPA/bound_general.py", line 1206, in compute_bounds
    return self._compute_bounds_main(C=C,
  File "/home/david/.miniconda3/envs/auto_LiRPA/lib/python3.10/site-packages/auto_LiRPA-0.4.0-py3.10.egg/auto_LiRPA/bound_general.py", line 1271, in _compute_bounds_main
    self.ibp_lower, self.ibp_upper = self.IBP_general(node=final, C=C)
  File "/home/david/.miniconda3/envs/auto_LiRPA/lib/python3.10/site-packages/auto_LiRPA-0.4.0-py3.10.egg/auto_LiRPA/interval_bound.py", line 50, in IBP_general
    node.interval = node.interval_propagate(*inp)
  File "/home/david/.miniconda3/envs/auto_LiRPA/lib/python3.10/site-packages/auto_LiRPA-0.4.0-py3.10.egg/auto_LiRPA/operators/activation_base.py", line 144, in interval_propagate
    return self.forward(h_L), self.forward(h_U)
  File "/home/david/.miniconda3/envs/auto_LiRPA/lib/python3.10/site-packages/auto_LiRPA-0.4.0-py3.10.egg/auto_LiRPA/operators/activations.py", line 73, in forward
    return torch.heaviside(x[0], x[1])
IndexError: tuple index out of range

System configuration:

shizhouxing commented 6 months ago

@cherrywoods Fixed: https://github.com/Verified-Intelligence/auto_LiRPA/commit/2553832b5a5bbfe643b694458867ebd1dbdece65

cherrywoods commented 6 months ago

Thanks for fixing this so promptly!