cvxpylayers icon indicating copy to clipboard operation
cvxpylayers copied to clipboard

some bug patches + torch no_grad forward pass

Open healeyq3 opened this issue 7 months ago • 4 comments

Continuing the work that @PTNobel and I started in the diffcp repository to address https://github.com/cvxpy/cvxpy/issues/2485.

Specifically, used the new diffcp solve_only_batch call chain in the torch CvxpyLayer when gradients are not desired for reverse autodiff. This functionality can be accessed by

  1. Setting all parameter tensors which will be passed into the CvxpyLayer to not require a gradient.
  2. Making the layer(param1, param2, ...) call inside with torch.no_grad()

For examples, see the last two tests in torch/test_cvxpylayer.py.

Additionally, I patched two errors in the test file. Note that the tests

  1. test_basic_gp
  2. test_lml
  3. test_simple_batch_socp failed prior to the CvxpyLayer additions that I made. The gp failure appears to be due to difference in solutions obtained by cvxpylayers and pure cvxpy. The second two failed tests are due to small(ish) Jacobian mismatches.

The next steps (I think) to complete issue https://github.com/cvxpy/cvxpy/issues/2485 are

  1. Release the new version of diffcp with the solve_only functionality (I used my local copy to make these cvxpylayer changes.)
  2. See if this update provides any meaningful computational enhancements.
  3. Implement this no_grad functionality for JAX and TensorFlow layers.

However, please let me know if there are more suggestions and/or edits I need to make to this PR. Thanks!

healeyq3 avatar Jul 25 '24 22:07 healeyq3