Test-Time Model Adaptation for Quantized Neural Networks

Zeshuai Deng, Guohao Chen, Shuaicheng Niu, Hui Luo, Shuhai Zhang, Yifan Yang, Renjie Chen, Wei Luo, Mingkui Tan

Introduction

Deploying deep learning models on edge devices—such as smartphones, drones, and IoT sensors—requires significant optimization to meet strict memory and power constraints. Quantized Neural Networks (QNNs), which reduce weight and activation precision from 32-bit floating point to low-bit integers (e.g., 4-bit or 8-bit), have emerged as a primary solution. However, quantization introduces a critical vulnerability: increased fragility under domain shifts. When a quantized model encounters real-world environmental changes—such as fog, rain, or sensor noise—its performance degrades significantly more than that of a full-precision model.

This paper introduces Zeroth-Order Adaptation (ZOA), a framework designed to make QNNs robust to these shifts during deployment. By utilizing zeroth-order optimization, ZOA enables models to adapt using only two forward passes per sample, bypassing the computational and mathematical hurdles of backpropagation in discrete, low-bit environments.

The Challenge of Adapting Quantized Models

Existing Test-Time Adaptation (TTA) methods typically rely on gradient-based optimization via backpropagation. For QNNs, this approach faces three major obstacles:

  1. Vanishing and Non-Differentiable Gradients: The discrete nature of quantized weights makes standard differentiation nearly impossible. The "staircase" function of quantization leads to zero gradients almost everywhere, preventing effective weight updates.
  2. Resource Constraints: Backpropagation requires storing intermediate activations to compute gradients. This memory overhead often exceeds the total capacity of the edge devices that QNNs are designed for.
  3. Latency Requirements: Real-time applications cannot afford the multiple forward and backward passes required by traditional TTA methods.

Furthermore, the authors provide theoretical and empirical proof of a "Quantization Gap," showing that the loss difference between quantized and full-precision models grows exponentially as bit-precision decreases. This explains why a 4-bit model fails significantly harder than a 32-bit model when faced with environmental corruption.

The ZOA Framework

To address these challenges, the ZOA framework introduces a "forward-only" adaptation strategy composed of three core innovations:

1. Zeroth-Order Gradient Estimation

Instead of calculating true gradients, ZOA employs Simultaneous Perturbation Stochastic Approximation (SPSA). The framework applies a small, random perturbation to the model parameters and performs two forward passes: one standard and one perturbed. By analyzing the difference in loss between these two passes, ZOA estimates a gradient direction. This allows the model to optimize its parameters without ever needing a backward pass or differentiable loss functions.

2. Continual Knowledge Reprogramming

Real-world environments are rarely static. To handle sequential domain shifts, ZOA maintains a "knowledge base" of domain-specific vectors. When the system detects a new domain (using feature statistics from the model’s early layers), it learns a new vector and a set of aggregation coefficients. This allows the model to blend historical knowledge with current adaptation, preventing "catastrophic forgetting" of previously encountered environments.

3. Domain Knowledge Management (DKM)

To ensure the system remains lightweight, the Domain Knowledge Management scheme monitors the growth of the knowledge base. By identifying and removing redundant or highly similar domain vectors, DKM keeps the memory footprint stable even during long-term deployment.

Experimental Evaluation

The researchers evaluated ZOA across several rigorous benchmarks, including ImageNet-C (15 types of corruptions), ImageNet-R (artistic renditions), and ImageNet-Sketch. The framework was tested on diverse architectures, including Vision Transformers (ViT-B), ResNet-50, and the newer Vision Mamba (ViM-S), across bit-widths ranging from W8A8 down to W2A4.

Key Results

  • Accuracy Improvements: On a 6-bit quantized ViT-B model, ZOA achieved a 5.0% accuracy improvement over the previous state-of-the-art (FOA) on ImageNet-C. Even on highly compressed W3A3 models, ZOA boosted accuracy from 27.8% to 34.2%.
  • Memory Efficiency: ZOA is exceptionally lean. For a 4-bit ViT-B model, ZOA required only 103 MB of memory. In contrast, backpropagation-based methods like TENT or CoTTA require thousands of megabytes, making them unusable on most edge hardware.
  • Versatility: Unlike previous forward-only methods that were restricted to specific Transformer layers, ZOA’s parameter-level perturbation is architecture-agnostic, performing effectively on CNNs and Mamba-based models.

Conclusion and Future Work

ZOA represents a significant step forward in making edge AI both efficient and resilient. By replacing memory-intensive backpropagation with a streamlined zeroth-order approach, the framework allows low-bit models to adapt to the unpredictable real world in real-time.

While ZOA currently requires a small set of initial data to establish baseline statistics, future research may focus on making the method entirely data-independent from the start. Additionally, extending ZOA to more complex tasks like real-time object detection and segmentation could further broaden the impact of robust, quantized AI in the field.

Summary updated

BibTeX
@inproceedings{deng2025test,
  author = {Zeshuai Deng and Guohao Chen and Shuaicheng Niu and Hui Luo and Shuhai Zhang and Yifan Yang and Renjie Chen and Wei Luo and Mingkui Tan},
  title = {{Test-Time Model Adaptation for Quantized Neural Networks}},
  booktitle = {ACM Multimedia},
  year = {2025},
  doi = {10.1145/3746027.3754730},
}
Figure