Anytime-Safe Test-Time Adaptation via Level-Constrained Inexact Steps

A deployed classifier that adapts itself to shifted test data, such as images that have become foggy, noisy, or blurred, runs an optimizer on live data. That optimizer can be cut off at any moment, because the next image arrives before it finishes. Current test-time adaptation methods take plain gradient steps on an unsupervised loss. Whatever half-finished model exists when the next image arrives is the one that makes the prediction, and nothing stops that model from having drifted into a collapsed state that predicts only a few classes. Constrained optimization has a tool for this situation, called feasible-path methods: algorithms in which every intermediate iterate satisfies the constraints, not only the final one. They are known to tolerate inexactly solved inner subproblems. These methods have only been studied on static, offline problems.

We propose to recast each round of test-time adaptation as a small problem with nonconvex function constraints. The constraints are "do not move the predictions too far from the source model" and "do not collapse the predicted class distribution." We then solve each round with a level-constrained proximal method whose inner subproblem is solved only roughly, and every accepted iterate is checked with a forward pass. Every model that ever serves a prediction then satisfies the constraints on the data seen so far. The optimizer can also be stopped whenever the stream demands it, so there is no need to tune a step count to the arrival rate. In two sentences: make every intermediate adapted model safe to deploy, then let the data stream decide how long to optimize. If this works, the conflict between "solve subproblems accurately" and "keep up with the stream" disappears, because accuracy improves when time allows and safety never depends on it.

Core Claim

Two research threads sit in tension. Inexact-optimization theory, exemplified by Inexact first-order primal-dual algorithms, preserves optimal convergence rates by driving the inner tolerance toward zero. In streaming adaptation, Evaluation of Test-Time Adaptation Under Computational Time Constraints shows that spending more time per update makes methods miss incoming samples. Diffusion-based DDA rises from 64.4% to 82.0% error on ImageNet-C under a realistic stream, and SAR degrades by 7.2%.

Our claim is that the stream-latency problem becomes an anytime problem once feasibility, rather than optimality, is the invariant guaranteed at every iterate. Because each accepted iterate is feasible, the solver can be interrupted at any point and the current model is deployable. That model is no worse, in the constrained sense, than the source model.

We expect three results relative to the best compute-matched method. Under severe and continual shift, the proposal should show a lower worst-window error. It should show a near-zero rate of deployed models violating the anti-collapse constraints. Its mean error should match or improve on the baseline across a range of stream speeds, with no per-speed tuning.

Research Program

The adapted parameters $\theta$ are the batch-normalization scale and shift parameters, following Tent: Fully Test-Time Adaptation by Entropy Minimization. Tent adapts only these parameters by minimizing prediction entropy on test batches. The choice keeps the parameter count small and makes our results directly comparable to Tent. The objective $L_t(\theta)$ is the entropy on the current batch $B_t$.

We add two constraints, both measured on the current batch plus a small reservoir $R_t$ of recent test inputs. The first is a source-fidelity constraint. The second is an anti-collapse constraint:

$$c_1(\theta)=\frac{1}{|R_t|}\sum_{x\in R_t}\mathrm{KL}\big(p_{\theta_0}(x)\,\|\,p_\theta(x)\big)-\delta\le 0,\qquad c_2(\theta)=h_0-H\Big(\frac{1}{|B_t|}\sum_{x\in B_t}p_\theta(x)\Big)\le 0.$$

In these definitions, $p_\theta(x)$ is the predicted class distribution and $\theta_0$ is the source model. $\delta$ bounds how far predictions may move from the source model. $H$ is entropy, and $h_0$ is a floor on the entropy of the batch-averaged prediction. A collapsed model, one that predicts a handful of classes, violates $c_2$.

These constraints are deliberately functional rather than parameter-space constraints. Exploring Safety Supervision for Continual Test-time Domain Adaptation bounds drift with a soft penalty on $\|\theta_t-\theta_0\|^2$. That paper motivates our design: it reports that a rigid anchor can hinder adaptation under severe shift. It also leaves intermediate iterates free to drift. Controllable Continual Test-Time Adaptation shows that passively suppressing drift does not prevent classes from merging. It steers features directionally with soft dot-product losses instead. We keep their goal of class separability, but turn it into a hard constraint that every iterate must satisfy.

The solver comes from Level constrained first order methods for function constrained optimization. That method maintains strict feasibility along its whole trajectory by solving, at each step, a convex subproblem: linearize the objective and the constraints, add proximal terms, and loosen the constraint level gradually. It retains $\mathcal{O}(1/\epsilon)$ complexity to reach approximate stationary points even when those subproblems are solved inexactly.

With only two constraints, the subproblem's dual is two-dimensional. A handful of dual iterations solves it approximately, at negligible cost compared with a backward pass. That paper's guarantees assume known smoothness constants and an a priori bound on the Lagrange multipliers, and both assumptions fail for a network facing drifting data. We replace them with a cheap acceptance test. After each candidate step, a forward pass recomputes $c_1$ and $c_2$. A violating step is shrunk toward the last accepted iterate until it passes.

The acceptance test is borrowed in spirit from zero-order feasibility checks such as those in Anderson Accelerated Feasible Sequential Linear Programming. It means feasibility holds by verification rather than by constants we cannot know. When a new batch arrives, we re-evaluate the constraints at the current model. The constraints change with the data, so the model may now be infeasible for the new batch. In that case the first steps are spent on restoration toward $\theta_0$, which is always feasible by construction. This also sidesteps the multiplier-bound problem raised for level methods under nonstationary constraints.

The scheduling rule is simple: keep taking accepted steps until the next batch arrives, then serve with the last accepted iterate. On the analysis side, we will prove three things for this deadline-truncated method. First, every served model is feasible on its reservoir and batch at check time. Second, the expected per-batch decrease in the objective is bounded below in terms of the number of accepted steps, adapting LCPG's inexact analysis to a per-batch restart. Third, we will state plainly what the guarantee does not cover: unseen future data. To address this, we will measure how often constraints certified on the reservoir are violated on the next batch, and report a margin version that tightens $\delta$ to $\delta-\gamma$.

Baselines

The naive reference points are the unadapted source model and simple test-time normalization (AdaBN). Under the realistic protocol, Evaluation of Test-Time Adaptation Under Computational Time Constraints finds normalization to be the only method that never collapses. Our method should be clearly better on mean error than both, and should never be worse than the source model on any corruption window.

The strongest existing competitor under time constraints is EATA. It filters unreliable samples and regularizes important weights, and in the same paper it reaches the lowest overall error, 55.6% on ImageNet-C, under the realistic online protocol. We will run EATA and our method in that paper's protocol on the same hardware and backbone. Skipped samples will be served by stale weights according to each method's measured relative adaptation speed $\lceil T_{\text{adapt}}/T_{\text{stream}}\rceil$. Both methods get the same hyperparameter-search budget, tuned on a held-out corruption subset. Beating EATA means lower mean error at matched stream speed. Better worst-window error at equal mean error would also count.

For continual adaptation on CIFAR, the strongest reported numbers are 14.7% mean error on CIFAR-10-C for Controllable Continual Test-Time Adaptation and 15.2% for Exploring Safety Supervision for Continual Test-time Domain Adaptation, compared with 16.5% for CoTTA and 43.5% for the source model. On continual ImageNet-C the same two papers report 59.4% and 62.1%. These numbers are offline, without a time budget. We will reproduce both methods under the realistic protocol rather than compare against their published figures. On ImageNet-C we also include Tent, at 44.0% average error offline in Tent: Fully Test-Time Adaptation by Entropy Minimization, since it is our unconstrained parent.

The key ablations isolate two things: the constrained step itself and the acceptance check. The first replaces level-constrained steps with Tent steps followed by the same forward-pass reject-and-shrink test. The second removes the acceptance check and trusts the linearized subproblem alone.

Why not just…?

Why not just add a tuned soft penalty, such as KL-to-source plus a marginal-entropy bonus, to Tent? This is a real threat on mean error, because a well-tuned penalty may match us on average. A penalty bounds nothing per iterate, however. Its weight trades violation against progress uniformly across shifts, so a weight tuned on mild corruptions should permit collapse on severe ones. A weight tuned for severe corruptions should over-restrict mild ones. Results in Controllable Continual Test-Time Adaptation on passive drift suppression point the same way. We will run the penalized objective with a penalty-weight sweep at equal tuning budget. We will report mean error together with the served-model violation rate and worst-window error. If the penalty matches us on all three, the hard-constraint claim fails.

Why not just take Tent steps and reject or backtrack any step that violates the constraints? This is the closest alternative, and it is exactly our first ablation. Our hypothesis is that under severe shift the constraints are active and the entropy gradient points out of the feasible set. Backtracking then shrinks steps toward zero and adaptation stalls. A level-constrained step instead moves along the constraint boundary. If the rejection-only variant matches the full method, the honest conclusion is that cheap verification, not the constrained subproblem, carries the benefit. The paper would then be reframed around that finding.

Why not just project onto a ball around the source parameters? Projection onto a ball is essentially free, so this alternative has no computational objection. The question is whether distance in parameter space controls behavior. Small changes to normalization scale can flip many predictions, and large harmless changes can be blocked. We will include ball-projected Tent with its radius tuned. We will then plot how well parameter distance and our KL constraint each predict collapse events.

Why not just use AdaBN, since it is fast and robust under the stream? The file shows a large accuracy gap when optimization is possible: 49.9% for normalization against 44.0% for Tent on ImageNet-C. Because our method is anytime, at the fastest stream speeds it should degrade to roughly AdaBN plus a few safe steps rather than below it. That prediction is tested directly in the stream-speed sweep below.

Proposed Experiments

The main experiment is continual ImageNet-C: fifteen corruptions at severity 5 presented in sequence, with ImageNet-R and ImageNet-3DCC as secondary shifts. All runs use the realistic online protocol of Evaluation of Test-Time Adaptation Under Computational Time Constraints. We vary the stream interval $T_{\text{stream}}$ over a range spanning "one step per batch" to "many steps per batch." We will report the following metrics:

  1. Mean error.
  2. Worst-window error, measured over sliding windows of a few thousand samples.
  3. The fraction of served models that violate $c_1$ or $c_2$, measured on the batch they serve.
  4. The violation rate on the next batch, which tests the generalization of the certificate.
  5. Measured relative adaptation speed.

CIFAR-10-C and CIFAR-100-C continual runs, in the standard CoTTA ordering, test the method at smaller scale against the two safety-oriented continual methods.

The decisive checks are three. First, in an interruption test, we stop the solver at a uniformly random inner step on each batch. Our method's error should change smoothly with stopping time. Tent run for multiple steps, and the penalized variant, should show violation spikes. Second, across stream speeds, one configuration of our method should sit at or below EATA's error curve with no per-speed retuning. Third, on long continual runs where Tent collapses, our method's violation rate should stay near zero and its error should never exceed the source model's in any window.

Our extra cost is two constraint gradients per step, which raises the relative adaptation speed. The protocol charges us for it. If that cost erases the gains at realistic stream speeds, we will consider the method to have failed on the question it was designed to answer.