Efficient Transfer Learning driven by Layer-wise Features Aggregation

Chanwoo Kim, Jeyoon Yeom, Joowang Kim, Suho Kang, Kyungwoo SongAFM @ NeurIPS 2024

TL;DR

This paper introduces Layer-wise Feature Aggregation (LFA), a novel method to boost the performance and efficiency of transfer learning by intelligently combining features from all layers of pre-trained models. LFA significantly improves performance on domain shift and few-shot learning tasks by leveraging a task-specific attention mechanism, all without requiring computationally expensive backpropagation through the entire pre-trained model.

What Problem Does This Paper Address?

Large pre-trained models, like those used in vision-language tasks (e.g., CLIP), are powerful feature extractors. However, fine-tuning them for new tasks often faces a trade-off between performance gains and computational efficiency. Existing methods like prompt tuning and adapters offer limited improvements. A key challenge is that most fine-tuning approaches focus heavily on the final layers of these models, potentially overlooking valuable, robust features present in earlier layers. These lower-level features are hypothesized to be more invariant to domain shifts and could significantly enhance generalization, especially in low-data scenarios. The paper aims to bridge this gap by proposing a method that effectively utilizes features from all layers of a pre-trained model to achieve better performance and efficiency.

Methods

The core of the proposed method is Layer-wise Feature Aggregation (LFA). It operates on pre-trained models (specifically, CLIP in their experiments) without requiring backpropagation through the entire model. Here's how it works:

  1. Feature Extraction: LFA extracts hidden feature vectors from all layers of both the visual and textual encoders of a pre-trained model.
  2. Attention Mechanism: A task-specific attention mechanism is employed.
  3. A query vector is derived from the final layer's hidden state of the visual encoder.
  4. Key and value vectors are generated from all layers of both the visual and textual encoders.
  5. Self-attention is applied independently to visual and textual features.
  6. Cross-attention is used to enhance textual features by incorporating visual information. This is crucial because visual features are often more diverse than textual features for the same class.
  7. Feature Aggregation: The outputs from the self-attention and cross-attention mechanisms are merged using a hyperparameter $\beta$, which balances their contributions. This aggregated feature vector represents the model's understanding of the input.
  8. Prediction: Logits are computed by taking the dot product of the final aggregated visual and textual feature vectors, enabling prediction through a softmax function.

The key innovation is that the optimization (training) process only involves the attention mechanism and the aggregation layer, bypassing the need to backpropagate gradients through the large pre-trained backbone. This significantly reduces computational cost and memory usage.

Datasets

The paper evaluates LFA on several benchmark datasets for different tasks:

  • Domain Generalization: DomainBed benchmark, which includes:
  • VLCS
    • PACS
    • OfficeHome
    • TerraIncognita
  • Few-shot Image Classification: A comprehensive set of datasets, including:
  • ImageNet
    • Caltech101
    • OxfordPets
    • StanfordCars
    • Flowers102
    • Food101
    • FGVCAircraft
    • SUN397
    • DTD
    • Eurosat
    • UCF101

Key Insights and Ideas

  • Lower layers matter: The paper provides evidence (Figure 4) that features from earlier layers of pre-trained models are not just noise but contain valuable information that can correct errors made by relying solely on the final layer. This challenges the common practice of focusing only on the last layer for fine-tuning.
  • Attention for aggregation: Using an attention mechanism to dynamically weigh and combine features from different layers allows the model to focus on the most relevant information for a given task, leading to richer representations.
  • Efficiency without compromise: The LFA approach achieves significant performance improvements without the computational burden of full backpropagation, making it highly practical for resource-constrained scenarios or when dealing with very large models.
  • Rank preservation: Theoretical analysis suggests that LFA helps preserve the "rank" of features, which can mitigate issues like overfitting and improve robustness to out-of-distribution data.

Key Results

  • Domain Generalization: CLIP + LFA outperforms other models on the PACS and OfficeHome datasets and achieves the highest average performance across various backbone models on the DomainBed benchmark. For example, on the DomainNet dataset, CLIP + LFA achieved 73.9% accuracy, outperforming CLIP + DPL (72.7%) and CLIP + QLORA (72.7%).
  • Few-shot Image Classification: LFA consistently improves the performance of various pre-trained CLIP-based models (Zero-Shot CLIP, LinearProbing CLIP, CoOp, CLIP-Adapter, MaPLe) when applied. While not always dramatic, the improvements are noteworthy, especially for models already performing well. For instance, applying LFA to MaPLe resulted in an average accuracy of 82.05%, compared to 78.26% for MaPLe alone.
  • Learning Efficiency: LFA demonstrates superior learning efficiency, requiring less peak memory and training time compared to methods that involve backpropagation through the entire model (e.g., CLIP + DPL). Table 3 shows CLIP + LFA using 1757 MB of peak memory and 2m 4s of training time for VLCS, significantly less than CLIP + DPL (8716 MB and 11m 32s).

Limitations and Future Work

  • Dataset Scope: The evaluation of LFA has so far been limited to CLIP-based models. The authors suggest exploring its application to other pre-trained models and tasks.
  • Optimization: Future work could focus on optimizing LFA for even larger models and environments with more stringent resource constraints.
  • Hyperparameter Tuning: While the paper explores the hyperparameter $\beta$ (balancing self and cross-attention), further research into optimal hyperparameter selection for diverse tasks could be beneficial.

Summary updated

BibTeX
@inproceedings{kim2024efficient,
  author = {Chanwoo Kim and Jeyoon Yeom and JOOWANG KIM and Suho Kang and Kyungwoo Song},
  title = {{Efficient Transfer Learning driven by Layer-wise Features Aggregation}},
  booktitle = {AFM @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=Q0tfRYadhc},
}
Figure