Beyond NaN: Resiliency of Optimization Layers in The Face of Infeasibility

Wai Tuck Wong, Sarah Kinsey, Ramesha Karunasena, Thanh Nguyen, Arunesh Sinha

TL;DR

Neural networks that integrate optimization solvers as internal layers are vulnerable to a new class of adversarial attacks that force numerical instability, resulting in "NaN" (Not a Number) outputs and total system failure. This paper introduces a robust defense by adding a differentiable layer that uses Singular Value Decomposition (SVD) to bound the condition number of input matrices, ensuring numerical stability and often improving overall training performance.

What Problem Does This Paper Address?

There is a growing trend in AI to embed optimization solvers directly into neural network architectures (e.g., OptNet). This allows models to perform complex reasoning or planning—like solving a Sudoku puzzle or planning a vehicle's speed—within a single forward pass.

However, these solvers are sensitive to the mathematical properties of their inputs. If the neural network outputs a matrix that is "singular" (meaning it cannot be inverted) or "ill-conditioned" (numerically unstable), the solver can fail. An adversary can exploit this by crafting inputs that force the solver into these failure states. Unlike traditional adversarial attacks that aim to trick a model into misclassifying an image, these "NaN attacks" aim for a complete denial of service. In critical applications like autonomous driving, a sudden NaN output could lead to catastrophic outcomes because the system loses its ability to make a decision.

Failure in autonomous driving speed planning when the optimization layer fails.

Methods

The authors tackle the problem from both offensive and defensive perspectives:

The Attacks

They propose three methods to find inputs $u$ that cause the solver's constraint matrix $A$ to become singular:

  1. AllZeroRowCol: Uses gradient descent to force an entire row or column of the matrix to zero.
  2. ZeroSingularValue: Targets the smallest singular value of the matrix to force it to zero.
  3. ConditionGrad: Directly maximizes the matrix's condition number (the ratio of its largest to smallest singular values) using its gradient.

The Defense

The core contribution is a novel, differentiable defense layer. Before the parameters reach the solver, this layer performs a Singular Value Decomposition (SVD) on the matrix $A$. It then "clamps" the singular values so that the condition number $\kappa_2(A)$ never exceeds a user-defined bound $B$. By ensuring the matrix is always well-conditioned, the solver is guaranteed to produce a stable, numerical result.

Figure 1: Optimization layers in neural networks. The neural network takes input u. Some parameters (Q, p, A, b, G, h) of the optimization then depend on the output θ = fw(u).

Datasets

The researchers evaluated their work across three distinct domains:

  • Synthetic Data: An abstract assignment problem designed to test varying constraint matrix sizes.
  • Jigsaw Sudoku: A complex variant of Sudoku where constraints are based on irregular geometric shapes. The model must infer these constraints directly from images of the puzzle (using MNIST digits).
  • Autonomous Driving (BelgiumTS): A real-world scenario where the network plans a speed profile based on traffic sign images and the vehicle's current state (speed, distance to destination, etc.).
The Jigsaw Sudoku network architecture, which must infer constraints from visual input.

Key Insights and Ideas

  • Simplicity Wins: Surprisingly, the simplest attack (AllZeroRowCol) was the most effective. Theoretically "principled" methods like ZeroSingularValue often failed in practice due to the very numerical precision errors they were trying to exploit.
  • Defense as a Regularizer: The SVD-based defense didn't just stop attacks; it actually improved training. By bounding the condition number, it stabilized the gradients flowing back through the solver, leading to faster convergence and lower final loss.
  • Silent Failures: The authors discovered that popular optimization libraries (like qpth) often fail silently. Instead of throwing an error when faced with an infeasible problem, they might return wildly incorrect results, which is arguably more dangerous than a NaN.
  • Context Matters: A simple "default safe action" (like braking) isn't a universal fix for NaN outputs in driving, as the safest action depends entirely on the current context (e.g., speed of the car behind you).

Key Results

  • Attack Success: In undefended models, the AllZeroRowCol attack achieved a 100% success rate in producing NaNs across almost all test cases.
  • Defense Efficacy: With the SVD defense in place (using various bounds $B$), the attack success rate dropped to 0.00%.
  • Performance Gains: In the autonomous driving task, the original model was highly unstable, with a massive test loss variance ($7928.76 \pm 38565$). The defended model ($B=2$) was significantly more stable and accurate, achieving a test loss of just $6.64 \pm 3.52$.
  • Reliability: In the driving experiments, only 12.8% of training runs for the original model were successful (others failed due to numerical issues). The defended model succeeded in every run.

Limitations and Future Work

  • Computational Overhead: While SVD is efficient, it is still more computationally expensive than standard layers. However, the authors note it is still faster than the optimization solver itself.
  • Solver Auditing: The paper highlights significant bugs in standard libraries (like PyTorch's lu_solve). A major future direction is a more thorough audit of the low-level mathematical libraries that AI researchers take for granted.
  • Complex Attacks: Future work could explore more sophisticated, photorealistic adversarial attacks that maintain semantic meaning while still triggering numerical failures.

Summary updated

Abstract

Prior work has successfully incorporated optimization layers as the last layer in neural networks for various problems, thereby allowing joint learning and planning in one neural network forward pass. In this work, we identify a weakness in such a set-up where inputs to the optimization layer lead to undefined output of the neural network. Such undefined decision outputs can lead to possible catastrophic outcomes in critical real time applications. We show that an adversary can cause such failures by forcing rank deficiency on the matrix fed to the optimization layer which results in the optimization failing to produce a solution. We provide a defense for the failure cases by controlling the condition number of the input matrix. We study the problem in the settings of synthetic data, Jigsaw Sudoku, and in speed planning for autonomous driving, building on top of prior frameworks in end-to-end learning and optimization. We show that our proposed defense effectively prevents the framework from failing with undefined output. Finally, we surface a number of edge cases which lead to serious bugs in popular equation and optimization solvers which can be abused as well.
BibTeX
@inproceedings{wong2023beyond,
  author = {Wai Tuck Wong and Sarah Kinsey and Ramesha Karunasena and Thanh Nguyen and Arunesh Sinha},
  title = {{Beyond NaN: Resiliency of Optimization Layers in The Face of Infeasibility}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i12.26778},
}
Figure