Nonlinear Optimization with GPU-Accelerated Neural Network Constraints

Robert B. Parker, Oscar Dowson, Nicole LoGiudice, Manuel J Garcia, Russell Bent

TL;DR

Embedding large neural networks directly into nonlinear optimization problems usually grinds interior point solvers to a halt due to massive constraint systems. By reformulating the problem into a "reduced-space" representation and offloading derivative calculations to a GPU via PyTorch, the authors solve optimization problems with up to 592 million neural network parameters in just seconds—slashing solve times from hours down to a few seconds.

What Problem Does This Paper Address?

Engineers and researchers frequently need to optimize over trained neural networks (NNs)—whether verifying robustness against adversarial perturbations or using NNs as fast physics surrogates (such as power grid transient stability models).

When these networks are embedded into standard nonlinear programming (NLP) solvers using a full-space formulation, every hidden neuron and layer is introduced as an explicit decision variable and constraint. While this keeps individual constraints simple, the Karush–Kuhn–Tucker (KKT) linear system inside solvers like IPOPT balloons with the size of the network. For networks with millions of parameters, factorizing this enormous matrix becomes computationally prohibitive, causing solvers to time out or exceed practical memory limits.

Methods

The authors adopt a reduced-space "gray box" formulation:

  • Variable Reduction: Instead of exposing every intermediate layer's pre-activations and activations to the solver, only the network's input and output variables are exposed. A single equality constraint $y = \text{NN}(x)$ encapsulates the entire network.
  • GPU-Accelerated Oracles: Because the solver sees only the inputs and outputs, it requires derivative "oracles" (Jacobians and the Hessian of the Lagrangian). These are evaluated via PyTorch with CUDA acceleration rather than algebraic modeling tools like JuMP.
  • Lagrangian Hessian Trick: A naive evaluation of the Hessian of a multi-output neural network requires contracting a 3rd-order tensor ($\mathcal{O}(m n^2)$, where $m$ is output and $n$ is input dimension). Instead, the authors represent the Lagrangian term $\lambda^T \text{NN}(x)$ as a linear layer in PyTorch, reducing it to a scalar-valued function whose $n \times n$ Hessian matrix can be computed directly and efficiently using automatic differentiation.

Datasets

The authors evaluated their approach on two distinct benchmarks:

  1. MNIST Handwritten Digits: Standard 784-input image classification dataset ($28 \times 28$ pixels) across 10 classes, used to test adversarial image perturbation constraints.
  2. Synthetic 37-Bus Power Grid: A synthetic power system dataset representing the Hawaii 37-bus transmission grid, trained on 110 high-fidelity dynamic simulations from PowerWorld to build a neural surrogate that predicts minimum transient post-fault frequencies under generator outage contingencies.

Key Insights and Ideas

  • KKT Factorization is the Bottleneck: In full-space models, over 99% of run time is spent inside the solver factorizing the KKT matrix. The reduced-space approach keeps the optimization problem size fixed to the solver, regardless of how deep or wide the embedded neural network is.
  • Fewer Iterations in Reduced Space: Beyond reducing per-iteration matrix sizes, interior point methods consistently took substantially fewer iterations to converge in the reduced space (e.g., 28–43 iterations vs. hundreds or thousands in full-space).
  • Workload Shifting to GPUs: By eliminating the sparse factorization bottleneck, the primary computational cost shifts to evaluating the Hessian of the Lagrangian. This shifted workload matches GPU strengths: tensorized, parallel automatic differentiation.

Key Results

  • Overcoming Scalability Walls: Full-space models timed out (>5 hours) on networks with $\ge 18\text{M}$ parameters (MNIST) and $\ge 68\text{M}$ parameters (power flow). In contrast, the GPU-accelerated reduced-space formulation effortlessly scaled up to 274 million parameters on MNIST and 592 million parameters on power flow.
  • Order-of-Magnitude Speedups:
  • For a 5M-parameter MNIST network, full-space CPU required 11,536 seconds (~3.2 hours) across 2,110 iterations. The GPU-accelerated reduced-space formulation solved it in 5 seconds across 67 iterations.
  • For the largest SCOPF model (592M parameters), CPU-only reduced-space required 144 seconds, while GPU acceleration solved it in 3 seconds—a 48× speedup.
  • On the 274M-parameter MNIST network, GPU acceleration provided a 9× speedup over CPU reduced-space (3 seconds vs. 45 seconds).

Limitations and Future Work

  • Smooth Activations Only: Because interior point methods require twice continuously differentiable ($C^2$) functions, non-smooth activations like ReLU cannot be used; networks must use smooth alternatives (e.g., Tanh, Sigmoid, SoftMax).
  • Local vs. Global Optimization: Hiding intermediate variables makes the approach unsuitable for traditional global solvers, which need explicit algebraic structures to build convex relaxations. Integrating bound-tightening schemes (e.g., CROWN) remains an open challenge.
  • Dimension Scaling: For problems where input/output dimensions are exceptionally large, CPU-to-GPU data transfers might introduce communication bottlenecks.
  • Hybrid Solvers: In this study, IPOPT still ran on the CPU while PyTorch handled evaluations on the GPU. Coupling this formulation with fully GPU-native interior point solvers (such as MadNLP) is an identified avenue for future improvements.

Summary updated

BibTeX
@inproceedings{parker2025nonlinear,
  author = {Robert B. Parker and Oscar Dowson and Nicole LoGiudice and Manuel J Garcia and Russell Bent},
  title = {{Nonlinear Optimization with GPU-Accelerated Neural Network Constraints}},
  booktitle = {ScaleOPT @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=7Nf40tUjxL},
}
Figure