Open
Description
When I applied cvxpylayer in my project, I found a problem in cvxpylayer. This leads to KeyError, when we deepcopy a existing module that contains cvxpylayer. For example, you can try the code below.
import cvxpy as cp
from cvxpylayers.torch import CvxpyLayer
import torch
import copy
n = 6
m = 3
x = cp.Variable(n)
x_prime = cp.Parameter(n)
constraints = [cp.pnorm(x, 2) <= m]
objective = cp.Minimize(0.5 * cp.pnorm(x - x_prime, 2))
problem = cp.Problem(objective, constraints)
assert problem.is_dpp()
projection = CvxpyLayer(problem, parameters=[x_prime], variables=[x])
s=torch.nn.Sequential(projection)
s=s.cuda()
sc=copy.deepcopy(s)
x=torch.randn(100,n, requires_grad=True)
sc(x)
Metadata
Metadata
Assignees
Labels
No labels