Test-Time Learning for LLM Adaptation
Test-Time Learning for LLM Adaptation
Jinwu Hu 1 2 * Zitian Zhang 1 * Guohao Chen 1 2 * Xutao Wen 1 Chao Shuai 3 Wei Luo 2 4 *
Bin Xiao 5 † Yuanqing Li 2 † Mingkui Tan 1 6 †
Abstract 1. Introduction
arXiv:2505.20633v1 [[Link]] 27 May 2025
While Large Language Models (LLMs) have ex- Large Language Models (LLMs) such as GPT-4 (Achiam
hibited remarkable emergent capabilities through et al., 2023) and LLaMA (Dubey et al., 2024) have signif-
extensive pre-training, they still face critical limi- icantly advanced the field of natural language processing
tations in generalizing to specialized domains and (NLP), demonstrating exceptional capabilities in both un-
handling diverse linguistic variations, known as derstanding and generating human-like text (Wang et al.,
distribution shifts. In this paper, we propose a 2025a). Such success is achieved through extensive pre-
Test-Time Learning (TTL) paradigm for LLMs, training on massive corpora, enabling them to learn rich lan-
namely TLM, which dynamically adapts LLMs guage representations that facilitate superior performance
to target domains using only unlabeled test data in various NLP tasks (Hu et al., 2025a; Zhong et al., 2024).
during testing. Specifically, we first provide em-
Despite their impressive capabilities, LLMs face significant
pirical evidence and theoretical insights to reveal
challenges when deployed in real-world environments with
that more accurate predictions from LLMs can be
dynamic and diverse data distributions. These challenges
achieved by minimizing the input perplexity of the
stem from the inherent sensitivity of deep learning models,
unlabeled test data. Based on this insight, we for-
including LLMs, to distribution shifts between training and
mulate the Test-Time Learning process of LLMs
test data, often leading to substantial performance degrada-
as input perplexity minimization, enabling self-
tion (Akyürek et al., 2024). These distributional shifts mani-
supervised enhancement of LLM performance.
fest in two main ways: 1) Domain-Specific Terminology:
Furthermore, we observe that high-perplexity
Encountering rare or specialized terms and structures in
samples tend to be more informative for model
fields such as medicine or agriculture may limit the model’s
optimization. Accordingly, we introduce a Sam-
performance (Gu et al., 2021). 2) Linguistic Diversity
ple Efficient Learning Strategy that actively se-
Variations: Variations in user intent and linguistic diversity,
lects and emphasizes these high-perplexity sam-
including dialects and slang, lead to distributional discrep-
ples for test-time updates. Lastly, to mitigate
ancies that negatively affect the model’s comprehension and
catastrophic forgetting and ensure adaptation sta-
response generation (Bella et al., 2024).
bility, we adopt Low-Rank Adaptation (LoRA)
instead of full-parameter optimization, which al- Recently, several attempts have been proposed to improve
lows lightweight model updates while preserving the performance of models in dynamic and diverse real-
more original knowledge from the model. We world environments. Most existing methods can be broadly
introduce the AdaptEval benchmark for TTL and categorized into four types, as shown in Table 1. Fine-
demonstrate through experiments that TLM im- tuning (Hu et al., 2022; Thirunavukarasu et al., 2023) adapts
proves performance by at least 20% compared to pre-trained models to specific tasks by updating their pa-
original LLMs on domain knowledge adaptation. rameters with labeled data, but it is constrained by the need
for extensive labeled datasets, limiting its practicality in
dynamic environments. Retrieval-Augmented Generation
*
Equal contribution 1 School of Software Engineering, South (RAG) (Fan et al., 2024) improves performance without
China University of Technology, China 2 Pazhou Laboratory, China requiring labeled data updates by leveraging external knowl-
3
Zhejiang University, China 4 South China Agricultural University, edge retrieved during inference, but its success depends
China. 5 Chongqing University of Posts and Telecommunications, heavily on the quality of the retrieved information. Test-
China 6 Key Laboratory of Big Data and Intelligent Robot, Ministry
of Education, China. Correspondence to: Mingkui Tan <mingkui- Time Adaptation (TTA) (Wang et al., 2021; Niu et al., 2022a;
tan@[Link]>, Yuanqing Li <auyqli@[Link]>, Bin Xiao Chen et al., 2024b) adjusts model parameters during infer-
<xiaobin@[Link]>. ence using only unlabeled test data, allowing the model to
adapt to distribution shifts in real-time. However, most TTA
Preprint.
1
Test-Time Learning for Large Language Models
Table 1. Characteristics of problem settings for adapting trained models to potentially shifted test domains.
Setting Knowledge Source Data Target Data Training Loss Testing Loss Learning Type
Fine-tuning % % xt , y t L(xt , y t ) – Supervised
Retrieval-Augmented Generation (Fan et al., 2024) ! % xt – – –
Test-Time Adaptation (Wang et al., 2021) % % xt % L(xt ) Unsupervised
Test-Time Training (Hardt & Sun, 2024) ! xs , y s xt % L(xt ; xs , y s ) –
Test-Time Learning (Ours) % % xt % L(xt ) Self-supervised
methods rely on entropy minimization as the optimization (LoRA) (Hu et al., 2022) is more effective at mitigating
objective, which overlooks the autoregressive dependencies catastrophic forgetting compared to full parameter updates
within LLMs, limiting its effectiveness in improving perfor- (see Observation 3). Based on this, we utilize LoRA for
mance on dynamic tasks (see Figure 1a). Test-Time Training TTL parameter updates, enabling lightweight training and
(TTT) (Hardt & Sun, 2024; Hübotter et al., 2024) retrieves effectively mitigating catastrophic forgetting, in contrast to
data relevant to the input from the training set or knowledge updating the full parameters of LLMs. Lastly, we construct
base during inference to fine-tune the model, improving its a comprehensive benchmark named AdaptEval for TTL.
performance in dynamic scenarios. However, these methods
We summarize our main contributions as follows:
assume that the model’s training data or knowledge data is
accessible, which is often not the case in practice, and they
also incur additional retrieval overhead. • Empirical Insights on Input Perplexity Minimiza-
tion: We empirically demonstrate that output perplex-
Although recent methods address distributional shifts in test ity can be reduced by minimizing input perplexity.
data, they still face the following limitations: 1) Difficulty Based on this insight, we adopt input perplexity mini-
in acquiring labeled data: High-quality labeled data for mization as the optimization objective, enabling LLMs
SFT of LLMs, especially for domain-specific tasks, is time- to adapt effectively to target domains during test time.
consuming, and becomes more difficult in online model up-
dates. 2) Neglecting autoregressive dependencies: Many • Sample Efficient Learning Strategy with High-
existing methods, such as TTA, overlook the autoregressive Perplexity Focus: We propose a Sample Efficient
nature of LLMs, leading to potential harm when using en- Learning Strategy using a perplexity-based weighting
tropy minimization for parameter updates. 3) High training scheme to select high-perplexity test samples for up-
overhead and catastrophic forgetting: Many methods re- date, ensuring efficient utilization of computational re-
quire substantial computational resources to update model sources. Moreover, we use LoRA to enable lightweight
parameters and may suffer from catastrophic forgetting. training and mitigate catastrophic forgetting.
To address these limitations, we propose a Test-Time • Benchmark and Experimental Validation of Test-
Learning (TTL) method for Large Language Models, Time Learning: We establish the AdaptEval bench-
namely TLM, which dynamically adapts LLMs using only mark for TTL and demonstrate through experiments
unlabeled test data. Specifically, we provide empirical evi- that our TLM improves performance by at least 20%
dence and theoretical insights to reveal that more accurate over original LLMs on domain knowledge adaptation.
autoregressive predictions from LLMs can be achieved by
minimizing the input perplexity of the unlabeled test data 2. Related Work
(see Observation 1). Based on this insight, we formulate
the TTL process of LLMs as input perplexity minimization, The adaptability of deep learning models to dynamic and di-
enabling self-supervised enhancement of LLM performance. verse real-world environments has emerged as a prominent
Furthermore, we observe that high-perplexity test samples focus in recent research. Various methods have been pro-
contribute more significantly to model updates compared to posed to enhance model performance under distributional
low-perplexity samples (see Observation 2). Building on shifts, as summarized in Table 1.
this observation, we propose a Sample Efficient Learning
Fine-Tuning adapts pre-trained models to specific tasks
Strategy that employs a perplexity-based weighting scheme
or domains by updating their parameters, such as LoRA,
to actively select and emphasize high-perplexity test samples
with labeled data (Hu et al., 2022; Thirunavukarasu et al.,
for backpropagation, thereby facilitating efficient parameter
2023; Chen et al., 2024c; Wang et al., 2025b). This ap-
updates during Test-Time Learning. Moreover, we observe
proach allows models to specialize in domain-specific tasks
that during the Test-Time Learning, Low-Rank Adaptation
by leveraging transfer learning to refine their capabilities.
2
Test-Time Learning for Large Language Models
However, it is often constrained by the need for extensive is often impractical. Unlike TTT, our focus is on TTL,
labeled datasets and high computational costs, which limit which dynamically updates LLMs during test time using
its practicality in dynamic environments where data distri- only unlabeled test data.
butions are continuously evolving. In contrast, our work
aims to dynamically update the model at test-time using 3. Problem Formulation
unlabeled input data, eliminating the need for extensive
labeled datasets and addressing the challenges posed by Without loss of generality, let P (x) denote the distribution
evolving data distributions. of the training data {xi }N
i=1 , where xi ∼ P (x). The fΘ◦ (x)
represent a general Large Language Model (LLM) that has
Retrieval-Augmented Generation (RAG) incorporates ex-
been supervised fine-tuned (SFT) on labeled training data
ternal knowledge by retrieving relevant information from a ◦
{(xi , yi )}N
i=1 , with parameters Θ . During training, the
knowledge base during inference (Jiang et al., 2024; Qian
model fΘ◦ (x) is optimized to generate coherent and contex-
et al., 2024; Asai et al., 2024). This allows the model to gen-
tually appropriate sequences by predicting the next token
erate more accurate and contextually grounded responses
in an autoregressive manner, effectively fitting the training
without requiring parameter updates. Qian et al. (2024) pro-
data and generalizing to test data from the same distribution
pose MemoRAG, a retrieval-augmented generation frame-
x ∼ P (x). However, in real-world deployments, the distri-
work enhanced by long-term memory for improved task
bution of test data may differ significantly from the training
performance. RAG is effective for tasks requiring up-to-
distribution due to various factors, leading to a phenomenon
date or domain knowledge but relies heavily on the quality
known as distribution shift. For general LLMs (e.g., LLaMA
of retrieved information and incurs additional computational
and Qwen), two primary types of out-of-distribution (OOD)
latency, limiting its suitability for time-sensitive tasks.
scenarios can occur during inference: 1) Vertical Domain
Test-Time Adaptation (TTA) dynamically updates model Shift: This occurs when test data contains domain-specific
parameters during inference by utilizing unlabeled test data terminology, such as in medical, legal, or technical fields,
(Wang et al., 2021; Niu et al., 2022a; 2023; Chen et al., which the model was not explicitly trained on, impairing its
2024b;a; Liang et al., 2024; Yi et al., 2024). This approach performance. 2) Distributional Shift in Non-Specific Do-
enables real-time adaptation to distributional shifts, making mains: Even without a specific vertical domain, factors like
it suitable for scenarios where labeled data is unavailable user intent variations and linguistic diversity (e.g., dialects,
or the test data distribution deviates significantly from the slang) can shift test data distribution from training data, af-
training distribution. Wang et al. (2021) propose the test fecting model understanding and response generation. In
entropy minimization method, which improves model con- these cases, the generative performance of the model fΘ◦ (x)
fidence by minimizing prediction entropy through online may deteriorate significantly because the model has not been
updates of normalization statistics and affine transforma- explicitly trained to handle such distribution shifts, resulting
tions. Most TTA methods rely on entropy minimization, in less coherent or contextually appropriate text generation
but this approach is not well-suited for the dynamic updates on OOD test samples x ∼ Q(x), where Q(x) ̸= P (x).
required by LLMs, as shown in Figure 1a. To address this
Test-Time Learning (TTL) seeks to improve the perfor-
issue, we propose minimizing the perplexity of test samples
mance of LLMs in the target domain by adjusting the model
as the optimization objective, which effectively enhances
using only test data. Specifically, given a set of OOD test
the performance of LLMs in dynamic environments.
samples {xj }Mj=1 , where xj ∼ Q(x), the goal of TTL is to
Test-Time Training (TTT) retrieves relevant data from optimize the model parameters Θ to improve the quality and
the training set or a knowledge base during inference and coherence of generated text for these test samples. Formally,
uses it to fine-tune the models (Niu et al., 2022b; Hardt & TTL can be framed as the following optimization problem,
Sun, 2024; Hübotter et al., 2024). This allows the model to where the objective is to minimize an unsupervised criterion
leverage adjacent data to better adapt to current test inputs, defined over the test data:
improving its performance in dynamic scenarios. Hardt &
Sun (2024) propose a test-time training approach for LLMs min L(x; Θ), x ∼ Q(x), (1)
by fine-tuning the model on retrieved nearest neighbors from Θ
3
Test-Time Learning for Large Language Models
* H R J U D S K \ / R Z S H U S O H [ L W \ V D P S O H V
$ J U L F X O W X U H + L J K S H U S O H [ L W \ V D P S O H V
0 H G L F L Q H