Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An problem when using relu and linear layer #70

Open
fxh903 opened this issue May 7, 2024 · 1 comment
Open

An problem when using relu and linear layer #70

fxh903 opened this issue May 7, 2024 · 1 comment

Comments

@fxh903
Copy link

fxh903 commented May 7, 2024

when i use a simple net for testing

class simpleNet(nn.Module):
  def __init__(self) -> None:
    super(simpleNet,self).__init__()
    self.linear_input = nn.Linear(64,100)
    self.relu = nn.ReLU()
  
  def forward(self,x):
    x = self.linear_input(x)
    x = self.relu(x)
    return x

if __name__ == '__main__':

    model = simpleNet()
    my_input = torch.ones((1,1,200,64))
    
    crown_model = BoundedModule(model, torch.empty_like(my_input))
    crown_model.eval()
    ptb = PerturbationLpNorm(norm = 2,eps=1)
    bounded_x = BoundedTensor(my_input, ptb)
    pred = crown_model(bounded_x)


    lb, ub = crown_model.compute_bounds(x=(bounded_x,), method='backward')
    print(lb,ub)

then i found

Traceback (most recent call last):
  File "/home/fengxianheng/ConvexCertify/test.py", line 117, in <module>
    lb, ub = crown_model.compute_bounds(x=(bounded_x,), method='backward')
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/bound_general.py", line 1318, in compute_bounds
    return self._compute_bounds_main(C=C,
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/bound_general.py", line 1416, in _compute_bounds_main
    self.check_prior_bounds(final)
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/bound_general.py", line 899, in check_prior_bounds
    self.compute_intermediate_bounds(
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/bound_general.py", line 983, in compute_intermediate_bounds
    node.lower, node.upper = self.backward_general(
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/backward_bound.py", line 338, in backward_general
    A, lower_b, upper_b = l.bound_backward(
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/operators/linear.py", line 891, in bound_backward
    results = super().bound_backward(last_lA, last_uA, *x, **kwargs)
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/operators/linear.py", line 355, in bound_backward
    lA_x, uA_x, lbias, ubias = multiply_with_weight(weight, set_l=True, set_u=True)
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/operators/linear.py", line 346, in multiply_with_weight
    lA_x, lbias = _bound_oneside(last_lA, weight_override=weight)
  File "/opt/anaconda3/envs/certified_watermark/lib/python3.9/site-packages/auto_LiRPA/operators/linear.py", line 252, in _bound_oneside
    -1, *last_A.input_shape[1:])
TypeError: 'NoneType' object is not subscriptable

i dont know what's the reason. Can someone explain this?

@aknirala
Copy link

aknirala commented Sep 5, 2024

If I change my_input as:
my_input = torch.ones((1,200,64))
it works. Any reason why my_input was 4 dimensional?
Ideally, for your model, it should be 2 dimensional. i.e, like: my_input = torch.ones((1,64))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants