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

get_sparse_C function encountered index error #44

Open
nrober1122 opened this issue Mar 15, 2023 · 0 comments
Open

get_sparse_C function encountered index error #44

nrober1122 opened this issue Mar 15, 2023 · 0 comments

Comments

@nrober1122
Copy link

nrober1122 commented Mar 15, 2023

Describe the bug
compute_bounds encounters an error when calling the get_sparse_C function through check_prior_bounds for certain nn.Module configurations.

To Reproduce

  1. Minimum example is provided in this colab
  2. The pytorch state_dict file is attached, which can be unzipped then uploaded into the colab file structure.
    single_pendulum_small_controller.torch.zip
  3. Error message:
IndexError                                Traceback (most recent call last)
<ipython-input-5-f8356946ec50> in <module>
     19   my_input = BoundedTensor(nominal_input, ptb)
     20 
---> 21   lb, ub = model.compute_bounds(x=(my_input,), method="backward")
     22   t_end = time.time()
     23 

6 frames
/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in compute_bounds(self, x, aux, C, method, IBP, forward, bound_lower, bound_upper, reuse_ibp, reuse_alpha, return_A, needed_A_dict, final_node_name, average_A, intermediate_layer_bounds, reference_bounds, intermediate_constr, alpha_idx, aux_reference_bounds, need_A_only, cutter, decision_thresh, update_mask)
   1337         self.final_node_name = final.name
   1338 
-> 1339         self.check_prior_bounds(final)
   1340 
   1341         if method == 'backward':

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in check_prior_bounds(self, node)
    881             return
    882         for n in node.inputs:
--> 883             self.check_prior_bounds(n)
    884         for i in getattr(node, 'requires_input_bounds', []):
    885             self.compute_intermediate_bounds(

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in check_prior_bounds(self, node)
    881             return
    882         for n in node.inputs:
--> 883             self.check_prior_bounds(n)
    884         for i in getattr(node, 'requires_input_bounds', []):
    885             self.compute_intermediate_bounds(

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in check_prior_bounds(self, node)
    881             return
    882         for n in node.inputs:
--> 883             self.check_prior_bounds(n)
    884         for i in getattr(node, 'requires_input_bounds', []):
    885             self.compute_intermediate_bounds(

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in check_prior_bounds(self, node)
    883             self.check_prior_bounds(n)
    884         for i in getattr(node, 'requires_input_bounds', []):
--> 885             self.compute_intermediate_bounds(
    886                 node.inputs[i], prior_checked=True)
    887         node.prior_checked = True

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/bound_general.py in compute_intermediate_bounds(self, node, prior_checked)
    968                         ref_intermediate_lb, ref_intermediate_ub = aux_bounds
    969 
--> 970                 sparse_C = self.get_sparse_C(
    971                     node, sparse_intermediate_bounds,
    972                     ref_intermediate_lb, ref_intermediate_ub)

/usr/local/lib/python3.9/dist-packages/auto_LiRPA-0.3.1-py3.9.egg/auto_LiRPA/backward_bound.py in get_sparse_C(self, node, sparse_intermediate_bounds, ref_intermediate_lb, ref_intermediate_ub)
    374                 del ref_intermediate_lb, ref_intermediate_ub
    375         if not reduced_dim:
--> 376             num_channel = node.output_shape[-3]
    377             # Identity patch size: (ouc_c, 1, 1, 1, out_c, 1, 1).
    378             patches = (

IndexError: tuple index out of range
  1. To replicate this bug, please open the colab (optionally, save as a copy so you can edit as the above link just provides viewing permission). Unzip & upload the provided .torch model file. Run the first cell to clone & install auto-lirpa. Restart the runtime and auto-lirpa will be fully installed (no need to re-run the first cell again). Run the subsequent cells to define the model class, load the state_dict, and run the test case.

System configuration:

  • OS: Ubuntu 20.04 (provided by colab)
  • Python version: Python 3.9.16
  • Pytorch Version: 1.13.1
  • Hardware: google colab
  • Have you tried to reproduce the problem in a cleanly created conda/virtualenv environment using official installation instructions and the latest code on the main branch?: implemented in a new colab file

Additional context
This is an attempt to work around issue #43 (also shares context with #42), so we are using the same model structure with multiple controller/dynamics blocks appended together. Notice this error doesn't occur for the first iteration (one controller/dynamics pair), but does for subsequent iterations. It seems to be an issue with the way BoundAdd is handled in get_sparse_C

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

1 participant