GramLoop: Training-Free Gram-Gated Replay for Robust Dense Prediction

Yang Chen, Canyu Shen, Xinzhe Rao, Yuanyi Yan, Yunlu Chen, Meng Tang, Teng Long, Vincent Tao HuarXiv 2026

TL;DR

GramLoop is a training-free, inference-time framework that enhances the robustness of frozen DINOv3 models under distribution shifts without altering model weights, adapters, or prediction heads. By replaying a short window of transformer blocks and selectively gating updates based on final-layer relational consistency (Gram drift), it successfully refines dense features while preserving crucial spatial structures.

What Problem Does This Paper Address?

Modern vision foundation models like DINOv3 excel on clean benchmarks but remain surprisingly fragile when encountering real-world distribution shifts, such as weather corruptions, digital perturbations, or natural domain variations.

While test-time adaptation (TTA) methods attempt to fix this by updating model parameters at inference time, doing so for massive models (like the 7B-parameter DINOv3) is computationally prohibitive and risks catastrophic forgetting. An alternative is "looped computation"—reapplying the same transformer blocks to iteratively refine features. However, naive block replay updates every token uniformly, which can easily destroy the delicate pairwise patch relationships that dense prediction tasks (like object detection and semantic segmentation) rely on to maintain spatial structure.

Methods

The authors introduce GramLoop, a training-free framework that introduces controlled inference-time recurrence into a frozen backbone.

Figure 1: GramLoop measures the final-layer Gram drift of each replay proposal and attenuates structurally disruptive endpoint updates before the unchanged task head.

The mechanism works as follows:

  1. Decomposition: The frozen DINOv3 encoder is divided into a prefix, a short loop window (a few transformer blocks), and a suffix.
  2. Relational Anchoring: A standard forward pass establishes an image-specific "anchor" trajectory. The final layer's feature map is used to compute a baseline cosine-Gram matrix, capturing the geometric relationships between all image patches.
  3. Window Replay & Suffix Evaluation: Features at the loop window endpoint are replayed through the window again to generate a feature proposal. This proposal is propagated through the suffix to the final layer.
  4. Gram-Gating: GramLoop measures the patchwise "Gram drift" between the proposal's final-layer relations and the anchor's relations. If a patch proposal severely distorts the global spatial geometry, its update is exponentially attenuated via a patchwise gate.
  5. Endpoint Update: The gated update is applied back at the loop window endpoint rather than the final layer, allowing mature final-layer evidence to guide earlier feature refinement.

Datasets

GramLoop was evaluated across two primary dense prediction tasks using the following benchmarks:

  • Semantic Segmentation: Evaluated on ADE20K (clean), ADE20K-C (15 common corruptions), and ADE20K-P (17 real-world-inspired perturbations).
  • Object Detection: Evaluated on COCO val2017 (clean), COCO-C (corruptions), COCO-P (perturbations), and COCO-O (6 natural out-of-distribution domains like sketch or weather).

Key Insights and Ideas

  • Leveraging Pretraining Objectives for TTA: DINOv3 specifically uses a "Gram-anchoring" objective during pretraining to keep patch relations stable. GramLoop cleverly repurposes this exact structural signal at inference time as a zero-shot sanity check for feature updates.
  • Separation of Church and State (Measurement vs. Modification): Ablations revealed that measuring drift at the final layer but applying the correction at an earlier loop endpoint yields the best performance. This decouples reliability estimation from trajectory modification.
  • Token Selection Matters: Spatially uneven gating outperforms uniform feature dampening. By suppressing updates only on tokens that cause high downstream relational drift, the model retains beneficial updates while protecting global layout integrity.
Figure 2: Replay proposes patch updates with spatially un- even Gram drift; GramLoop assigns low gates to high-drift patches, yielding accepted updates with lower residual rela- tion error. For a fixed COCO-P exemplar at impulse severity 10, the 2 × 2 panels show the corrupted input, proposal drift, gate, and post-gating drift in reading order. Proposal and post-gating drift share a color scale, while the gate uses [0, 1].

Key Results

GramLoop consistently outperformed the baseline DINOv3 model across all five distribution-shift benchmarks without any training:

  • COCO-O (Natural Shifts): Improved mean Average Precision (mAP) by +0.252 and Effective Robustness by +0.250.
  • Robustness Suites: Achieved modest but highly consistent gains across the board (+0.053 mPC on ADE20K-C, +0.037 on ADE20K-P, +0.085 on COCO-C, and +0.060 on COCO-P).
  • Clean Performance: Unlike many TTA methods that degrade clean performance to gain robustness, GramLoop preserved and slightly improved clean performance (+0.165 mIoU on clean ADE20K).
  • Severity Scaling: The benefits of GramLoop scale with the difficulty of the input; the largest performance gains were observed at the highest corruption severities (levels 4 and 5).
Qualitative improvements in segmentation and detection under distribution shifts.

Limitations and Future Work

The primary trade-off of GramLoop is computational overhead. Because it runs multiple replay steps and extra suffix passes, the inference time increases (empirically around 2.35× GPU time for the configuration tested). Peak memory, however, remains completely unchanged.

The authors note that future work will focus on mitigating this latency by adaptively deciding when and how many tokens need replaying, alongside developing lower-cost reliability probes to replace the full suffix pass.

Summary updated

Abstract

We aim to improve frozen DINOv3 dense-prediction models under distribution shift by adding inference computation inside the visual backbone, without changing model weights, task adapters, or prediction heads. The challenge is that repeated transformer-block computation must refine dense features without disrupting the pairwise patch relations that DINOv3 uses to preserve spatial structure. We introduce GramLoop, a training-free framework that replays a short transformer window and controls each replay through final-layer cosine-Gram consistency. Each proposal is propagated through the frozen suffix, measured against the standard DINOv3 trajectory, and accepted through a patchwise gate at the replay-window endpoint. Across object detection and semantic segmentation under corruptions, perturbations, and natural shifts, GramLoop improves all five shifted benchmarks over the paired DINOv3 baseline. On COCO-O, it improves mAP by +0.252 and Effective Robustness by +0.250, while preserving clean ADE20K performance. Code will be released at https://github.com/cheyan9/GramLoop.
BibTeX
@misc{chen2026gramloop,
  author = {Yang Chen and Canyu Shen and Xinzhe Rao and Yuanyi Yan and Yunlu Chen and Meng Tang and Teng Long and Vincent Tao Hu},
  title = {{GramLoop: Training-Free Gram-Gated Replay for Robust Dense Prediction}},
  year = {2026},
  eprint = {2608.29113},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.29113},
}
Figure