Differentiation Through Black-Box Quadratic Programming Solvers

Connor W. Magoon, Fengyu Yang, Noam Aigerman, Shahar Z. Kovalsky

In the world of deep learning, we are increasingly moving beyond simple "layers" of neurons toward "optimization layers"—modules that solve a mathematical optimization problem as part of a forward pass. Quadratic Programming (QP) is the workhorse of this field, appearing in everything from robotics and control to optimal transport.

However, a major bottleneck has persisted: if you want to backpropagate through a QP, you usually have to use a specific, often custom-built solver that supports differentiation. This forces researchers to choose between a solver that is "differentiable" and one that is actually fast, robust, or capable of handling large-scale sparse data.

A new paper introduces dQP, a framework that breaks this trade-off by allowing you to differentiate through virtually any "black-box" QP solver.

TL;DR

dQP is a modular, solver-agnostic framework that enables plug-and-play differentiation for almost any Quadratic Programming solver (including industry standards like Gurobi and MOSEK). By decoupling the optimization process from the gradient calculation using the "active set" of constraints, dQP achieves state-of-the-art scalability and numerical robustness, especially for large-scale sparse problems.

What Problem Does This Paper Address?

To train a neural network containing an optimization layer, you need the gradient of the solution with respect to the input parameters. Traditionally, this required "opening the hood" of the solver. Existing tools like OptNet or CVXPYLayers are either tightly coupled to specific algorithms or rely on general-purpose formulations that struggle to scale.

This creates a "solver lock-in." If your problem is massive and sparse, you might want to use a commercial-grade solver like Gurobi, but if Gurobi isn't "differentiable," you're stuck using a slower, custom interior-point method. The gap is especially painful in large-scale applications where specialized solvers are the only way to get a solution in a reasonable timeframe.

Methods: The Power of the Active Set

The core "aha moment" of dQP lies in the Active Set.

In a QP, you are minimizing a quadratic function subject to linear inequality constraints. At the optimal solution, some of those inequalities will be "active" (meaning the solution sits exactly on the boundary, effectively turning the inequality into an equality), while others will be "inactive" (the solution is nowhere near the boundary).

Active Set Simplification

The authors leverage a key theoretical insight:

  1. Solve first: Use any high-performance black-box solver to find the primal solution ($z^*$).
  2. Identify the Active Set: Figure out which constraints are active at that solution.
  3. Differentiate later: Once the active set is known, the complex QP locally behaves like a much simpler equality-constrained problem (as illustrated above, where the complex polygon simplifies to a single line constraint locally). The derivatives can then be computed by solving a reduced-size linear system (the KKT system).

Crucially, dQP can even differentiate solvers that only provide a primal solution by "completing" the dual variables at a negligible computational cost. Because the gradient calculation uses a smaller, "reduced" matrix, it is often much more numerically stable than traditional methods.

Datasets

The authors put dQP through a gauntlet of over 2,000 problems:

  • Maros-Meszaros (MM) Dataset: A standard industry benchmark consisting of 129 difficult, large-scale sparse QP problems.
  • Synthetic Projections: Large-scale problems involving projection onto the probability simplex and "chains" with bounded links, testing scalability up to $10^5$ variables.
  • Random QPs: Hundreds of randomly generated dense and sparse problems.
  • Bi-Level Geometry Optimization: A real-world application involving the "straight-edge drawing" of complex 3D meshes (like an ant mesh with 15k vertices).

Key Insights and Ideas

  • Decoupling is Power: By separating the "how" of solving from the "how" of differentiating, users can swap in the best solver for their specific hardware or problem structure without changing their training code.
  • Numerical Stability: The "reduced" KKT system used by dQP is often significantly better conditioned than the "full" system used by competitors. This means fewer "NaN" gradients and more reliable training.
  • Modular Implementation: dQP is built on top of the qpsolvers library, providing immediate access to over 15 commercial and open-source backends.

Key Results

  • Success Rate: On the challenging Maros-Meszaros dataset, dQP solved 100% of the problems. In contrast, OptNet and SCQPTH failed on more than half of them.
  • Speed and Scalability: In large-scale tests ($n > 2000$), dQP outperformed competing methods by 2 to 3 orders of magnitude in both speed and accuracy.
Performance and Scalability
  • Sparse Advantage: dQP shines in large-scale sparse regimes. For a mesh optimization task with 10,000+ vertices, dQP was the only method capable of providing gradients in a reasonable time.

Limitations and Future Work

While dQP is a major step forward, the authors note a few areas for growth:

  • GPU Acceleration: Currently, dQP is optimized for CPUs because that is where the most robust sparse solvers live. Future work could involve better integration with emerging GPU-accelerated sparse solvers.
  • Infeasibility: The current framework assumes the problem is feasible and strictly convex. It does not yet have specialized handling for mathematically "impossible" (infeasible) problems, a feature present in some other niche solvers.
  • Broadening the Scope: The authors view this as a template for making other types of optimization (like Semidefinite Programming) "black-box differentiable."

Paper Link: Differentiation Through Black-Box Quadratic Programming Solvers Code: https://github.com/cwmagoon/dQP

Summary updated

BibTeX
@inproceedings{magoon2025differentiation,
  author = {Connor W. Magoon and Fengyu Yang and Noam Aigerman and Shahar Z. Kovalsky},
  title = {{Differentiation Through Black-Box Quadratic Programming Solvers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=DvwKWKG1Ul},
}
Figure