Safe Gradient Flow for Bilevel Optimization

Sina Sharifi, Nazanin Abolfazli, Erfan Yazdandoost Hamedani, Mahyar Fazlyab · DOI

Abstract

Bilevel optimization (BLO) is a hierarchical framework where an upper-level problem is constrained by the solution to a lower-level optimization. Traditional BLO solvers often rely on computationally expensive nested loops or implicit differentiation. This paper introduces a control-theoretic framework, Safe Gradient Flow (SGF), to solve BLO problems in a single loop. By treating the lower-level optimality condition as a "safety constraint" and applying a safety filter derived from Control Barrier Functions, the proposed method creates a dynamical system that converges to the optimal solution without expensive nested iterations. An inversion-free variant is also presented to scale the approach to high-dimensional machine learning tasks.

Introduction

Bilevel optimization is increasingly relevant in machine learning, appearing in hyperparameter optimization, meta-learning, and data cleaning. However, BLO is notoriously difficult because the upper and lower levels are interdependently coupled. Standard approaches typically require solving the lower-level problem to completion for every update of the upper-level variable (nested loops) or computing the implicit gradient, which involves expensive Hessian inversions. These methods are often too slow for large-scale applications. The core challenge lies in updating both variables simultaneously while ensuring the lower-level solution remains optimal—a property we define as "safety."

Methods: Safe Gradient Flow

The authors propose viewing the lower-level optimality condition as a dynamic boundary. The Safe Gradient Flow (SGF) approach consists of two primary components: a base gradient flow that minimizes the upper-level objective, and a safety filter.

The Safe Gradient Flow (SGF) framework. The lower-level optimality condition is treated as a safety constraint, and a safety filter modifies the upper-level gradient to maintain feasibility on the KKT manifold.

The safety filter is formulated as a convex Quadratic Program (QP) that minimally modifies the upper-level gradient to ensure the system remains on or is attracted to the "KKT manifold" where the lower-level problem is solved. To ensure stability, the filter enforces an exponential convergence condition ($\frac{d}{dt} \nabla_y g + \alpha \nabla_y g = 0$), meaning even if the system starts away from the lower-level optimum, it is rapidly corrected.

For high-dimensional problems where Hessians are prohibitive, the authors introduce the Inversion-free Relaxed Safety Filter (RXSF). This variant relaxes the lower-level constraint into a small suboptimality neighborhood ($\|\nabla_y g\|^2 \le \epsilon^2$), eliminating the need for matrix inversions and making the algorithm scalable to deep learning architectures.

Experimental Results

The method was evaluated on synthetic non-convex problems and a real-world data hyper-cleaning task using the MNIST dataset. In the hyper-cleaning experiment, a classifier is trained on corrupted labels (lower level) while sample weights are optimized on a clean validation set (upper level).

Test accuracy on the MNIST data hyper-cleaning task, comparing the proposed Inversion-free method against the state-of-the-art AIDBio across different label corruption rates (p).

As shown in the results, the Inversion-free SGF method consistently outperformed AIDBio (Approximate Implicit Differentiation), a state-of-the-art baseline. It achieved higher test accuracy and lower validation loss using the same number of gradient evaluations, demonstrating superior efficiency and robustness to label noise (parameter $p$). Theoretical analysis using Lyapunov functions further supports these findings, proving that the dynamical system converges to a neighborhood of the global optimal solution.

Conclusion and Future Work

Safe Gradient Flow offers a promising single-loop alternative to traditional bilevel optimization methods. By leveraging control-theoretic safety filters, it achieves competitive performance with significantly reduced computational overhead. Current limitations include the assumption of unconstrained decision variables and the requirement for strong convexity in the lower-level objective. Future research will focus on extending the framework to constrained optimization and exploring more complex, non-convex lower-level landscapes.

Summary updated

BibTeX
@inproceedings{sharifi2025safe,
  author = {Sina Sharifi and Nazanin Abolfazli and Erfan Yazdandoost Hamedani and Mahyar Fazlyab},
  title = {{Safe Gradient Flow for Bilevel Optimization}},
  booktitle = {ACC},
  year = {2025},
  doi = {10.23919/acc63710.2025.11107448},
}
Figure