Source-linked AI summary

Test-Time Training with Masked Autoencoders

Yossi Gandelsman, Yu Sun, Xinlei Chen, Alexei A. Efros

arXiv:2209.07522v1cs.CVcs.LG

TL;DR

The paper studies how to generalize when test distributions shift and labels are unavailable at deployment. It uses masked autoencoders for per-input self-supervised test-time training, finding improvements across object-recognition benchmarks and interpreting them through bias-variance trade-offs.

  • Problem

    Generalization is difficult when deployment distributions differ from training data, while selecting a self-supervised task that remains useful across test distributions is unresolved.

  • Method

    The method replaces TTT's self-supervised task with MAE reconstruction and adapts the encoder for each test input.

  • Results

    MAE is reported as well-suited for TTT and substantially improves object-recognition generalization on four datasets.

  • Takeaways & Limitations

    The theoretical analysis characterizes the improvement as a better bias-variance trade-off than applying a fixed model under distribution shifts.

  • Takeaways & Limitations

    The work covers only object recognition and a handful of popular distribution-shift benchmarks, with no guarantee that spatial autoencoding helps every task or test distribution.

Abstract

from arXiv · show

Test-time training adapts to a new test distribution on the fly by optimizing a model for each test input using self-supervision. In this paper, we use masked autoencoders for this one-sample learning problem. Empirically, our simple method improves generalization on many visual benchmarks for distribution shifts. Theoretically, we characterize this improvement in terms of the bias-variance trade-off.

1 Introduction

The paper addresses generalization when deployment data differ from training data by adapting to each test input through self-supervision. It uses masked autoencoders as the self-supervised task and reports improvements across four object-recognition datasets.

  • Distribution shifts make fixed deployed models difficult to prepare for because robustness to all possible futures can limit performance on any particular future.
  • Test-time training adapts the model after each test input arrives, using that input as a one-sample learning problem without requiring its ground-truth label.
  • Masked autoencoders are chosen because spatial autoencoding exploits local redundancy in natural images while providing a self-supervised signal.
  • The paper reports that MAE is well-suited for test-time training and substantially improves object-recognition generalization on four datasets, alongside a linear-model theoretical analysis.

2 Related Work

Related work frames test-time training as one-sample unsupervised adaptation and contrasts it with methods requiring prepared target data, batches, or less general pretext tasks. Masked autoencoders provide a spatial reconstruction alternative built on patch masking.

  • Generalization under distribution shifts: Distribution-shift methods commonly rely on wider training distributions, while robustness learned for one shift often does not transfer to another.
  • Unsupervised domain adaptation: Unsupervised domain adaptation uses unlabeled target data, making it easier but more restrictive than test-time training.
  • Test-time training: Test-time training produces a different model for every test input through self-supervision and has been applied across vision, robotics, language, and medical imaging.
  • Test-time training: Rotation prediction can be too easy or too hard across visual domains, limiting its generality as a test-time pretext task.
  • Test-time training: TTT is a one-sample UDA setting that needs no target data prepared in advance and only adapts to the test sample itself.
  • Test-time training: The paper evaluates each single test sample independently rather than assuming access to an entire target dataset or batch from one distribution.
  • Spatial autoencoding: MAE masks a majority of image patches and reconstructs the missing patches, while its encoder supplies features for downstream tasks such as object recognition.

3 Method

The method substitutes MAE reconstruction for TTT's self-supervised task, combining an MAE encoder-decoder with a separately trained recognition head. At test time, it updates the encoder and decoder per image, using SGD because continued iterations improve performance without validation-based early stopping.

  • TTT-MAE substitutes MAE reconstruction for the self-supervised component of test-time training.
  • Architecture: The Y-shaped architecture shares an MAE encoder between a reconstruction decoder and a main-task head, while retaining the MAE components for comparison.
  • Training setup: Fine-tuning is avoided because test-time reconstruction adaptation can remove recognition-only features on which its task head relies.
  • Training setup: ViT probing is the default because it trains 3.5 times fewer parameters than linear fine-tuning, using 86M versus 306M parameters.
  • Training-time training: The training setup freezes the MAE encoder while optimizing the main-task head with cross-entropy classification loss.
  • Test-time training: For each arriving test input, the method optimizes reconstruction from the pretrained encoder and decoder, then predicts with the adapted encoder and discards the adapted weights.
  • Optimizer for TTT: SGD keeps improving test accuracy beyond 20 iterations, whereas AdamW hurts performance with too many iterations and requires unrealistic early stopping.

4 Empirical Results

Across distribution-shift benchmarks, TTT-MAE uses a fixed MAE-based setup and adapts at test time, outperforming its baseline across ImageNet-C corruptions, ImageNet-A/R, and Portraits.

  • Implementation Details: TTT uses 20 SGD steps with momentum 0.9, weight decay 0.2, batch size 128, and learning rate 5e-3.The method uses 75% random masking and performs TTT on the same center crop later used for prediction.
  • ImageNet-C: ImageNet-C level-5 evaluation shows TTT-MAE significantly improves accuracy over the fixed baseline.The baseline is a ViT-probed model using a pretrained MAE encoder, while TTT-MAE adapts that model during testing.
  • ImageNet-C: TTT-MAE achieves higher performance gains than TTT-Rot across all ImageNet-C corruption types relative to their respective baselines.The comparison is made in relative terms because the baselines use different model strengths; TTT-MAE nevertheless improves over its ViT baseline for contrast.
  • ImageNet-C: On rotation-invariant classes, TTT-Rot hurts performance, whereas TTT-MAE still helps.Top-down images can make rotation prediction memorize auxiliary labels without forming semantic features, while MAE remains agnostic to rotation invariance.
  • ImageNet-C: Among training-time designs, TTT-MAE after ViT probing performs best across all ImageNet-C corruption types.Joint training is unsatisfactory on most corruptions, and fine-tuning is not amenable to TTT.
  • Additional Benchmarks: TTT-MAE improves over the baseline on ImageNet-A, ImageNet-R, and all three Portraits training-split experiments.ImageNet-A/R use the same hyper-parameters as ImageNet-C, while Portraits evaluates binary gender classification across temporally separated splits.

5 Theoretical Results

The theoretical analysis models distribution shifts as linear transformations and shows that test-time training with autoencoding can improve on a fixed model through a better bias-variance trade-off. In the linear setting, PCA provides a tractable analysis of how test-input information can be combined with training statistics.

  • Theory setup: The analysis restricts models to the linear world and distribution shifts to linear transformations, using dimensionality reduction as an analogue of masked autoencoding.The paper argues that autoencoding with dimensionality reduction and masking are closely related in essence.
  • Theory setup: Linear autoencoding is equivalent to PCA, yielding closed-form optimization solutions during training and test-time training.The analysis therefore uses PCA terminology and spectral decomposition of the training covariance matrix.
  • Algorithm: The method combines the training covariance matrix with a covariance matrix formed from the corrupted test input, controlled by hyper-parameter α.The resulting matrix is spectrally decomposed before making the prediction.
  • Bias-variance trade-off: α = 0 reproduces the fixed-model baseline, whereas α = 1 relies exclusively on the single test input and forgets the training data.Intermediate α values trade lower bias against higher variance as α increases.
  • Theorem: TTT with some α > 0 strictly dominates the α = 0 baseline in expected prediction risk under the theorem’s assumptions.The risk is defined as E[|ŷ − y|] over the corrupted test distribution.
  • Assumptions: The analysis assumes PCA is helpful on the training distribution and simplifies the proof with an eigenvalue condition, while suggesting extension to invertible linear transformations.The covariance matrix and predictor weights are treated as known, justified asymptotically as training size grows.

6 Limitations

The paper’s scope is limited by test-time cost, task and benchmark coverage, and uncertainty about whether spatial autoencoding transfers to every task and test distribution. It also points toward video streams as a setting where test-time training may have greater potential.

  • Efficiency: The method is slower at test time than applying a fixed model, and existing deep-learning tooling leaves room for improving test-time training efficiency.The authors identify hyper-parameters, optimizers, training techniques, and architectures as possible improvement areas.
  • Generality: Spatial autoencoding is not guaranteed to produce useful features for every main task on every test distribution.Its generality as a self-supervised task does not establish universal usefulness.
  • Evaluation scope: The empirical study covers only object recognition and a handful of popular distribution-shift benchmarks.This bounds how broadly the reported results can be interpreted.
  • Future setting: The authors suggest video streams may offer more potential for test-time training because self-supervision can use the current and past frames.They contrast this with evaluation using independently collected i.i.d. images.

Checklist

The checklist records affirmative answers for discussing contributions, limitations, theoretical assumptions and proofs, reproducibility materials, training details, and asset licensing. Several human-subject and data-consent questions are marked not applicable.

  • Author declarations: The authors report that they described the work’s contributions and scope and discussed its limitations.Both checklist responses are affirmative.
  • Ethics: The paper marks potential negative societal impacts as not applicable and states that the ethics review guidelines were followed.These responses appear in the ethics portion of the checklist.
  • Theory reporting: The authors state that they provided the full assumptions and complete proofs for theoretical results.The checklist records affirmative answers for both items.
  • Reproducibility and assets: The checklist reports that code, data, reproducibility instructions, training details, and asset citations or licensing information were included.The code-and-data response says release will occur upon acceptance, while licensing details are noted in the appendix.
  • Experiments: Error bars are marked not applicable under the convention used for the large-scale experiments.The checklist also records compute-resource reporting as affirmative.
  • Human subjects and data: Questions about consent, personally identifiable or offensive content, crowdsourcing instructions, participant risks, and compensation are marked not applicable.These checklist items concern human-subject or crowdsourced-data procedures.

A.1 Proof of Theorem 1

The proof uses rotational symmetry to set the training covariance basis to the identity-aligned case, differentiates the spectral decomposition of the interpolated matrix, and shows a positive improvement under a mild transformation condition.

  • Proof setup: Rotational symmetry lets the proof assume U = I, so the training covariance matrix becomes diagonal, Σ = D.This reduces the analysis to the eigenbasis of the covariance matrix.
  • Spectral derivatives: The proof differentiates the matrix decomposition M(α) = V(α)S(α)V(α)^⊤ through the test-input covariance perturbation.The derivative of M is expressed in terms of derivatives of V and S.
  • Spectral derivatives: Orthogonality of V implies that V(α)^⊤Ṽ(α) is skew-symmetric and constrains its off-diagonal entries through the transformed matrix derivative.These identities are used to compute the derivative at α = 0.
  • At α = 0: At α = 0, the proof evaluates the expected eigenvector derivative in relation to the first transformation direction r1.The calculation connects the spectral perturbation to the corruption’s effect on the leading component.
  • Conclusion: The derived improvement term is positive when 0 < r11 < 1, establishing the relevant strict inequality under that condition.Because ∥r1∥ = 1, the condition holds whenever the first component is mixed with another nonzero transformation component.

A.2 Additional Experiments on ImageNet-C

Additional ImageNet-C experiments examine reconstruction targets, optimization procedures, and masking ratios across corruption levels after test-time training.

  • ImageNet-C results: Tables 5-9 report accuracy (%) after 10 TTT steps for ImageNet-C corruption levels 1 through 5.The appendix provides results for all five corruption levels.
  • Reconstruction target: Normalized pixels as the reconstruction target improve representation quality on most corruptions.The comparison uses MSE between reconstructed pixels and original pixels versus pixel values normalized across each masked patch.
  • Optimization procedure: Encoder-only optimization and joint encoder-decoder optimization produce negligible differences.Both procedures also optimize the mask token and class token together.
  • Masking ratio: Masking-ratio experiments evaluate test-time training with different ratios while pre-training remains fixed at 75%.The appendix reports these comparisons in Table 12.
  • ImageNet-C benchmark: Figure 4 shows sample images from the ImageNet-C benchmark.
Loading 2209.07522v1…