Abstract: Optimization layers within neural network architectures have become increasingly popular for their ability to solve a wide range of machine learning tasks and to model domain-specific knowledge. However, designing optimization layers requires careful consideration as the underlying optimization problems might be infeasible during training. Motivated by applications in learning, control and robotics, this work focuses on convex quadratic programming (QP) layers. The specific structure of this type of optimization layer can be efficiently exploited for faster computations while still allowing rich modeling capabilities. We leverage primal-dual augmented Lagrangian techniques for computing derivatives of both feasible and infeasible QP solutions. More precisely, we propose a unified approach that tackles the differentiability of the closest feasible QP solutions in a classical $l_2$ sense. We then harness this approach to enrich the expressive capabilities of existing QP layers. More precisely, we show how differentiating through infeasible QPs during training enables to drive towards feasibility at test time a new range of QP layers. These layers notably demonstrate superior predictive performance in some conventional learning tasks. Additionally, we present alternative formulations that enhance numerical robustness, speed, and accuracy for training such layers. Along with these contributions, we provide an open-source C++ software package called QPLayer for differentiating feasible and infeasible convex QPs and which can be interfaced with modern learning frameworks.
Introduction
In modern deep learning, the integration of domain-specific knowledge—such as physical laws, logical constraints, or geometric priors—is often achieved through optimization layers. Unlike standard neural network layers that apply a fixed mathematical transformation (like a ReLU or Tanh activation), an optimization layer's output is the solution to an internal mathematical problem.
While powerful, these layers introduce significant computational and mathematical challenges, particularly regarding differentiability and feasibility. This work introduces QPLayer, a high-performance framework designed to handle convex Quadratic Programming (QP) layers with unprecedented speed and robustness.
The Feasibility Challenge
Convex Quadratic Programming layers have historically suffered from a major weakness: feasibility. Existing state-of-the-art tools, such as OptNet, require the QP to remain "primal feasible" throughout the entire training process. This means that for every input and every set of learned weights, a valid solution must exist that satisfies all constraints.
In practice, this is a fragile assumption. If a network's parameters evolve to create contradictory constraints, the solver fails, the gradient becomes undefined, and training halts. Researchers often resort to architectural "hacks" to guarantee feasibility, which limits the model's expressive power and complicates design. QPLayer addresses this by treating infeasibility not as a failure, but as a differentiable state.
The QPLayer Approach
QPLayer leverages a primal-dual augmented Lagrangian method to solve a "hierarchic" version of the QP. If a problem is infeasible, the layer automatically identifies and returns the solution to the "closest" feasible problem in a least-squares ($l_2$) sense.
Extended Conservative Jacobians (ECJ)
To compute gradients through points that are non-differentiable or infeasible, the authors utilize Extended Conservative Jacobians. This mathematical framework allows for a generalized version of the Implicit Function Theorem (IFT). By using a specific mathematical map and avoiding large matrix products in the backward pass, QPLayer maintains sparsity and numerical stability, leading to significant performance gains.
Key Results and Benchmarks
The authors evaluated QPLayer against standard benchmarks, including Sudoku solving, MNIST classification, and robotic control tasks (Cart-Pole swing-up).
- Computational Speed: QPLayer demonstrated a 3x to 10x speedup in total training time compared to OptNet. In randomized QP benchmarks, it was consistently 4x faster than OptNet and orders of magnitude faster than
CvxpyLayer. - Logical Accuracy: In the Sudoku task, which requires learning logical constraints, QPLayer achieved significantly higher accuracy (33 errors vs. 162 for OptNet). This was possible because QPLayer can differentiate through Linear Programs (LPs), which are better suited for logical tasks but often cause numerical instability in other solvers.
- Robustness: QPLayer proved stable even with large learning rates. While other solvers produced
NaNerrors when problems became ill-conditioned, QPLayer’s augmented Lagrangian approach continued to provide useful gradients, "pushing" the model back toward the feasible region.
Conclusion
QPLayer represents a significant step forward for differentiable optimization. By providing a robust, high-speed C++ implementation that handles infeasibility gracefully, it allows researchers to embed complex constraints into neural networks without the fear of training-time failures. Future work aims to extend this framework to Second-Order Cone Programs (SOCPs), further expanding its utility in complex robotics and engineering applications.
Summary updated