cvxpy/cvxpylayers

Differentiable convex optimization layers

What it solves

CVXPYlayers allows developers to integrate convex optimization problems directly into deep learning models as differentiable layers. This enables the training of neural networks that include a convex optimization step, allowing the model to learn the parameters of the optimization problem itself through backpropagation.

How it works

The library uses CVXPY to specify parametrized convex optimization problems. In the forward pass, it solves the optimization problem to produce a solution. In the backward pass, it computes the derivative of that solution with respect to the input parameters, making the layer compatible with automatic differentiation frameworks.

Who it’s for

It is designed for researchers and engineers working with PyTorch, JAX, or MLX who need to embed optimization constraints and objectives into their machine learning pipelines.

Highlights

  • Multi-framework support: Works seamlessly with PyTorch, JAX, and MLX.
  • GPU acceleration: Supports GPU acceleration via the Moreau and CuClarabel backends.
  • Broad optimization support: Handles standard convex programs as well as log-log convex programs (LLCPs).
  • Dual variable access: Can return constraint dual variables (Lagrange multipliers) in addition to the primal solution.

Related

  • Project
  • Project
  • Project
  • Project