Skip to main content
QUICK REVIEW

[Paper Review] How to Fine-Tune Vision Models with SGD

Ananya Kumar, Ruoqi Shen|arXiv (Cornell University)|Nov 17, 2022
Advanced Neural Network ApplicationsComputer Science5 citations
TL;DR

This paper identifies that SGD underperforms AdamW on vision transformers and ConvNeXts under distribution shift due to disproportionately large gradients in the embedding layer. By freezing this small layer (<1% of parameters), SGD achieves performance on par with or better than AdamW while using significantly less memory—resulting in state-of-the-art accuracy on five distribution shift benchmarks.

ABSTRACT

SGD and AdamW are the two most used optimizers for fine-tuning large neural networks in computer vision. When the two methods perform the same, SGD is preferable because it uses less memory (12 bytes/parameter with momentum and 8 bytes/parameter without) than AdamW (16 bytes/parameter). However, on a suite of downstream tasks, especially those with distribution shifts, we find that fine-tuning with AdamW performs substantially better than SGD on modern Vision Transformer and ConvNeXt models. We find that large gaps in performance between SGD and AdamW occur when the fine-tuning gradients in the first "embedding" layer are much larger than in the rest of the model. Our analysis suggests an easy fix that works consistently across datasets and models: freezing the embedding layer (less than 1% of the parameters) leads to SGD with or without momentum performing slightly better than AdamW while using less memory (e.g., on ViT-L, SGD uses 33% less GPU memory). Our insights result in state-of-the-art accuracies on five popular distribution shift benchmarks: WILDS-FMoW, WILDS-Camelyon, BREEDS-Living-17, Waterbirds, and DomainNet.

Motivation & Objective

  • To understand why AdamW outperforms SGD in fine-tuning vision models under distribution shift.
  • To identify the root cause of performance gaps between SGD and AdamW in modern vision architectures.
  • To propose a minimal, memory-efficient modification to SGD that matches or exceeds AdamW performance.
  • To achieve state-of-the-art results on distribution shift benchmarks without increasing memory or computational cost.

Proposed method

  • Freeze the first embedding layer (less than 1% of parameters) during SGD fine-tuning to prevent overfitting to high-gradient initial updates.
  • Compare SGD with and without momentum, and with and without embedding layer freezing, across multiple models and datasets.
  • Analyze gradient norms at initialization across layers to identify disproportionate gradient magnitudes in the embedding layer.
  • Normalize gradients by parameter norm and by √(number of parameters) to assess relative update magnitudes across layers.
  • Profile memory usage to quantify the memory advantage of the proposed method over AdamW.
  • Evaluate performance on five distribution shift benchmarks: WILDS-FMoW, WILDS-Camelyon, BREEDS-Living-17, Waterbirds, and DomainNet.

Experimental results

Research questions

  • RQ1Why does AdamW outperform SGD on vision transformers and ConvNeXts when fine-tuning on distribution shift datasets?
  • RQ2What structural or optimization property of the model causes SGD to underperform relative to AdamW in such settings?
  • RQ3Does freezing the embedding layer—despite its small size—lead to consistent performance gains for SGD in fine-tuning?
  • RQ4Can a memory-efficient variant of SGD (without momentum) outperform both standard SGD and AdamW on OOD generalization?
  • RQ5Is the performance gain from freezing the embedding layer due to reduced gradient explosion, or is it an independent improvement from AdamW's adaptive learning rates?

Key findings

  • On CLIP ViT-B/16, AdamW achieves 2.1% higher in-distribution accuracy and 8.1% higher out-of-distribution accuracy than standard SGD.
  • Freezing the embedding layer enables SGD to match or exceed AdamW performance, achieving 76.7% OOD accuracy across all models and datasets.
  • The memory overhead of AdamW is 18% and 49% higher than SGD (freeze-embed, no momentum) on ViT-B/16 and ViT-L/14, respectively.
  • SGD with embedding layer freezing and no momentum achieves 76.9% OOD accuracy—slightly better than AdamW and the baseline SGD.
  • Gradient analysis shows the embedding layer has 2–3× larger gradients than other layers in SGD-pretrained models, and over 10× larger in AdamW-pretrained models.
  • Freezing the embedding layer eliminates the performance gap between SGD and AdamW, indicating it is the primary cause of SGD’s underperformance.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.