Hierarchical Adaptive networks with Task vectors for Test-Time Adaptation

TL;DR

Hi-Vec uses hierarchical layers with dynamic selection and task vectors to improve test-time adaptation, boosting robustness against complex distribution shifts.

cs.LG 🔴 Advanced 2025-08-12 24 views
Sameer Ambekar Marta Hasny Laura Daza Daniel M. Lang Julia A. Schnabel
deep learning domain adaptation test-time adaptation hierarchical structure model merging

Key Findings

Methodology

Hi-Vec employs a hierarchical organization of linear layers (Matryoshka structure) within the encoder, integrating dynamic layer selection based on gradient norms, target information sharing via task vectors, and mutual information-based layer agreement for outlier detection. This framework allows flexible adaptation to diverse shifts. It is compatible with existing methods like Tent, SAR, and Stamp, and validated on datasets such as CIFAR-10-C and ImageNet-C, demonstrating significant performance gains.

Key Results

  • On CIFAR-10-C with noise, Hi-Vec combined with Stamp achieved 83.6% accuracy, a 5.7% increase over baseline; on ImageNet-C, accuracy improved by 3.2%, AUC by 4.1%. In outlier and spurious correlation scenarios, it enhanced robustness, especially in Waterbirds and ColoredMNIST, with notable gains in worst-group accuracy.
  • Ablation studies confirmed that dynamic layer selection and task vector fusion are critical for performance, while the layer agreement mechanism effectively filters noise, reducing erroneous updates.
  • Across multiple datasets and conditions, Hi-Vec consistently outperformed baselines, especially with limited batch sizes and high outlier ratios, showing strong stability and adaptability.

Significance

This work advances test-time adaptation by moving beyond single-layer mappings, leveraging hierarchical structures for multi-scale, robust, and flexible model tuning. Its compatibility with existing methods and superior performance in noisy, complex environments make it a promising solution for deploying deep models in real-world, dynamic settings, addressing key challenges in model robustness and generalization.

Technical Contribution

The paper introduces a hierarchical linear layer design, combined with a dynamic selection mechanism based on gradient norms, and a target information sharing strategy via task vectors. Additionally, a layer agreement measure based on mutual information ensures outlier detection and prevents harmful fine-tuning. These innovations collectively enhance the model’s capacity to adapt efficiently and robustly to diverse distribution shifts, providing theoretical guarantees rooted in linear mode connectivity and information theory.

Novelty

This is the first work to integrate multi-layer hierarchical linear structures with dynamic selection and cross-layer information sharing for test-time adaptation. Unlike prior single-layer approaches, it enables multi-scale, context-aware adaptation, significantly improving robustness against complex shifts and outliers, representing a substantial leap forward in adaptive deep learning.

Limitations

  • The method relies on pre-designed hierarchical structures, which may not generalize seamlessly across different architectures or tasks. Its performance under extreme shifts or very small batch sizes needs further validation.
  • Additional computational overhead from dynamic selection and weight merging could limit real-time deployment, especially on resource-constrained devices.
  • Sensitivity to hyperparameters like similarity thresholds and the need for careful tuning may affect robustness and stability in diverse scenarios.

Future Work

Future directions include automating the design of hierarchical structures via meta-learning, extending the framework to multi-modal and sequential data, and optimizing computational efficiency. Exploring adaptive thresholding and unsupervised structure learning could further improve robustness and applicability in real-world, resource-limited environments.

AI Executive Summary

Deep learning models often face performance degradation when encountering data that differ from their training distribution, a challenge known as distribution shift. Traditional solutions like domain adaptation or domain generalization require access to target data during training or assume static environments, limiting their practicality. Test-time adaptation (TTA) emerged as a promising approach, enabling models to adapt dynamically during inference without source data. However, existing TTA methods typically rely on a single linear layer, constraining their ability to handle complex, diverse shifts.

This paper introduces Hi-Vec, a hierarchical adaptive framework that leverages multiple linear layers organized in a coarse-to-fine structure. By dynamically selecting the most suitable layer based on gradient norms, Hi-Vec ensures targeted adaptation. It further employs task vectors to share target-specific information across layers, enhancing expressivity. To prevent erroneous updates caused by noisy or outlier data, the framework incorporates a layer agreement mechanism based on mutual information, which detects out-of-distribution samples and skips unnecessary fine-tuning.

Extensive experiments on datasets such as CIFAR-10-C, CIFAR-100-C, and ImageNet-C demonstrate that Hi-Vec significantly improves robustness and accuracy. When integrated with state-of-the-art methods like Tent, SAR, and Stamp, it boosts average accuracy by over 3%, especially under limited batch sizes and high noise conditions. The approach effectively addresses the limitations of prior single-layer methods, providing a scalable, flexible solution for real-world applications where data distribution constantly evolves.

Overall, Hi-Vec represents a substantial advancement in test-time adaptation, combining hierarchical representation, dynamic selection, and robust outlier detection. Its compatibility with existing methods and superior performance across diverse scenarios position it as a key step toward deploying more resilient and adaptable deep learning systems in dynamic environments. Future work will focus on automating hierarchical design, extending to multi-modal data, and optimizing computational efficiency for edge deployment.

Deep Analysis

Background

Deep learning在实际应用中面临分布偏移问题,早期工作如Domain Adaptation和Domain Generalization通过数据对齐或特征不变性提升模型泛化能力。近年来,测试时适应(Test-Time Adaptation, TTA)成为研究热点,允许模型在推理过程中动态调整参数以应对新环境。代表性方法如Tent、SAR、Stamp主要通过微调BN参数或输出层实现,但受限于单一线性映射的表达能力,难以应对复杂偏移。层次化表示学习(如Matryoshka结构)逐渐兴起,提升了模型的表达多样性,但在实际适应中仍存在效率和鲁棒性不足的问题。

Core Problem

现有测试时适应方法多依赖单一线性层,难以应对多样化和复杂的分布偏移,尤其在偏移类型多样、噪声高或批次有限时表现不佳。模型微调易引入误差,导致性能下降。如何设计一种结构化、动态、鲁棒的适应框架,兼容多种偏移类型,成为亟待解决的核心问题。

Innovation

引入多层次线性层(Matryoshka结构),组织编码器表示空间,提升表达丰富性。结合动态梯度范数选择机制,自动识别最适合当前偏移的层次;利用任务向量实现跨层信息融合,增强表达能力;通过层间一致性检测,识别异常样本,避免误导性微调。这一系列创新突破了传统单一映射的限制,显著提升模型适应复杂偏移的能力。

Methodology

  • �� 构建多层次线性层(层数和维度可调)组织编码器表示空间。• 利用梯度范数(∥∇Wϕ L∥)衡量每层的适应需求,选择最小的层进行微调。• 采用余弦相似度计算任务向量(Wϕ)之间的相似性,融合相似层的权重,促进信息共享。• 通过互信息(I(pϕ∗ ; pϕ))检测层间输出一致性,识别离群样本,决定是否跳过微调。• 结合现有方法(如Tent、SAR)进行微调,优化目标包括交叉熵和信息熵,确保鲁棒性。

Experiments

在CIFAR-10-C、CIFAR-100-C、ImageNet-C等多个偏移场景中,评估Hi-Vec结合不同基线方法的性能。采用准确率、AUC和H-Score作为指标,比较不同偏移类型(噪声、离群、虚假相关)下的表现。设置不同批次大小和噪声比,验证算法的稳定性。通过消融实验分析动态选择、任务向量融合和一致性检测的贡献。结果显示,Hi-Vec显著优于单一方法,提升准确率平均达3%以上,鲁棒性增强。

Results

在CIFAR-10-C噪声场景中,结合Stamp提升准确率至83.6%,比单一方法最高提升5.7%;在ImageNet-C,平均准确率提升3.2%,AUC提升4.1%;在抗离群和虚假相关场景中,模型准确率和最差组性能均有明显改善,验证了其鲁棒性和适应性。

Applications

该框架适用于自动驾驶、医疗影像、工业检测等需应对环境变化的场景。只需预训练多层次线性层,结合现有测试时方法,即可实现动态、鲁棒的适应。未来,结合边缘计算和多模态数据,将进一步拓展其应用范围。

Limitations & Outlook

依赖预训练层次结构设计,可能在不同模型架构中表现不一;在极端偏移和噪声条件下仍有提升空间;算法复杂度增加,影响实时性。未来需优化效率和泛化能力。

Plain Language Accessible to non-experts

想象你在厨房做饭,面对不同的食材和调料。传统方法就像用一种调料应对所有菜肴,效果有限。Hi-Vec像是有多个调料架,从粗糙到细腻,能根据不同菜肴选择合适的调料。每次做菜前,根据菜的特点,自动挑选最合适的调料层,既快又准。还会把用过的调料信息分享给其他调料架,让整体味道更协调。如果遇到不认识的食材(噪声或异常),它会识别出来,避免调错味道。这样,厨房的菜肴就能每次都做得更好、更符合口味,适应各种不同的食材和环境。

ELI14 Explained like you're 14

想象你在学校里玩游戏,游戏里的角色会遇到不同的场景,比如晴天、雨天、夜晚。以前的游戏角色只能用一种技能应对所有场景,就像用一样的武器打怪,效果不总是好。现在,新的游戏角色有多个技能(比如跑步、跳跃、潜行),可以根据场景自动选择最合适的技能。每次遇到新场景时,它会判断哪个技能最有效,然后用那个技能来应对。它还会把用过的技能信息分享给其他技能,让整个团队变得更聪明。遇到特别难的场景(比如突然出现的怪物或噪声),它会识别出来,不会盲目用错技能。这样,游戏就变得更有趣,也更容易赢。这个方法就像让电脑学会像人一样聪明地应对各种变化,变得更强大、更可靠。

Glossary

Hierarchical Linear Layers (层次线性层)

一组按层级组织的线性映射层,用于多尺度特征表达。技术上,它们将编码器的表示空间划分为不同维度的子空间,提升模型表达能力。

论文中用于组织编码器表示,支持动态选择和信息融合。

Task Vectors (任务向量)

表示模型不同层的参数子集,用于跨层信息共享和融合。通过余弦相似度衡量相似性,促进目标信息传递。

实现目标信息融合机制,增强模型适应性。

Mutual Information (互信息)

衡量两个随机变量共享信息的量,用于检测模型输出的一致性。高互信息表示输出一致,低则可能为异常或偏移。

用于层间一致性检测,识别离群样本。

Open Questions Unanswered questions from this research

  • 1 如何在极端偏移或噪声环境下进一步提升模型的鲁棒性仍需研究,特别是在极小批次和实时场景中的适应能力。
  • 2 不同模型架构对层次线性结构的兼容性和效果差异尚未充分探索,未来应系统评估其泛化能力。

Abstract

Test-time adaptation allows pretrained models to adjust to incoming data streams, addressing distribution shifts between source and target domains. However, standard methods rely on single-dimensional linear classification layers, which often fail to handle diverse and complex shifts. We propose Hierarchical Adaptive Networks with Task Vectors (Hi-Vec), which leverages multiple layers of increasing size for dynamic test-time adaptation. By decomposing the encoder's representation space into such hierarchically organized layers, Hi-Vec, in a plug-and-play manner, allows existing methods to adapt to shifts of varying complexity. Our contributions are threefold: First, we propose dynamic layer selection for automatic identification of the optimal layer for adaptation to each test batch. Second, we propose a mechanism that merges weights from the dynamic layer to other layers, ensuring all layers receive target information. Third, we propose linear layer agreement that acts as a gating function, preventing erroneous fine-tuning by adaptation on noisy batches. We rigorously evaluate the performance of Hi-Vec in challenging scenarios and on multiple target datasets, proving its strong capability to advance state-of-the-art methods. Our results show that Hi-Vec improves robustness, addresses uncertainty, and handles limited batch sizes and increased outlier rates.

cs.LG cs.AI