Continual learning in transformers is commonly addressed through parameter-efficient adaptation: prompts, adapters, or LoRA modules are specialized per task while the backbone remains frozen. Although effective in controlled multi-epoch settings, these approaches rely on gradual gradient-based specialization and struggle in Online Continual Learning (OCL), where data arrive as a non-stationary stream and each sample may be observed only once. We recast continual learning in transformers as a routing problem: under strict online constraints, the model must dynamically select the appropriate representational subspace for each input without explicit task identifiers or repeated optimization. We thus introduce Routing without Forgetting (RwF), a transformer architecture augmented with energy-based associative retrieval layers inspired by Modern Hopfield Networks. Instead of storing or merging task-specific prompts, RwF generates dynamic prompts through single-step associative retrieval over the transformer token embeddings at each layer. Retrieval corresponds to the closed-form minimization of a strictly convex free-energy functional, enabling input-conditioned routing within each forward pass, independently of iterative gradient refinement. Across challenging class-incremental benchmarks, RwF improves over existing prompt-based methods. On Split-ImageNet-R and Split-ImageNet-S, RwF outperforms prior prompt-based approaches by a large margin, even in few-shot learning regimes. These results indicate that embedding energy-based associative routing directly within the transformer backbone provides a principled and effective foundation for OCL.
Figures & tables
Figure 1: RwF layer: routing-augmented transformer block. Given input tokens Zℓ , a Hopfield-based associative retrieval module generates input-conditioned routing prompts Pℓ via energy-based pooling over token features. The retrieved Pℓ are concatenated with the Zℓ tokens and processed by the standard Multi-Head Self-Attention (MHSA). After MHSA, only the backbone tokens Z~ℓ are propagated to the MLP blocks and then to the next RwF transformer layer ℓ+1 , while P~ℓ are discarded.
Split-CIFAR100
Split-ImageNet-R
Split-ImageNet-S
Method
AFinal(↑)
Forgetting (↓)
AFinal(↑)
Forgetting (↓)
AFinal(↑)
Forgetting (↓)
Joint
89.50 ± 0.04
–
76.78 ± 0.44
–
63.82 ± 0.02
–
Finetune
15.83 ± 0.25
79.68 ± 0.08
12.06 ± 0.34
79.61 ± 0.04
7.09 ± 0.08
26.45 ± 0.14
AGEM [ 11 ]
12.67 ± 1.87
82.51 ± 2.27
5.60 ± 2.42
53.97 ± 1.97
0.16 ± 0.04
9.42 ± 0.17
ER [ 12 ]
44.85 ± 1.83
44.67 ± 4.29
40.99 ± 3.96
32.38 ± 0.89
30.21 ± 0.70
37.14 ± 1.83
EWC++ [ 19 ]
10.61 ± 0.74
84.10 ± 1.11
3.86 ± 2.02
36.95 ± 1.46
0.32 ± 0.28
22.46 ± 4.69
Table 1: OCL performance comparison. Final Average Accuracy AFinal(↑) and Forgetting (↓) on Split-CIFAR100, Split-ImageNet-R, and Split-ImageNet-S. Best: bold, second: underline, third: italic. RwF achieves top performance on large-scale ImageNet benchmarks while ranking competitively on CIFAR100.
Split-ImageNet-R
Method
100%
70%
50%
20%
L2P [ 2 ]
57.97 ± 0.31
56.15 ± 0.13
53.71 ± 0.32
44.79 ± 1.14
CODA-Prompt [ 4 ]
66.16 ± 0.39
64.60 ± 1.04
61.63 ± 0.28
54.79 ± 1.16
DualPrompt [ 3 ]
60.88 ± 0.62
58.67 ± 0.81
56.87 ± 0.33
47.68 ± 0.52
InfLoRA [ 8 ]
62.20 ± 0.87
51.94 ± 0.67
37.90 ± 0.98
6.65 ± 0.08
APER [ 5 ]
55.12 ± 0.02
55.04 ± 0.27
54.16 ± 0.45
49.72 ± 0.13
Table 2: Performance under few-shot data regimes (Split-ImageNet-R). Final Average Accuracy ( AFinal(↑) ) as the fraction of available training samples decreases from 100% to 20%. Best: bold, second: underline, third: italic. RwF maintains the highest accuracy across all evaluated data regimes.
Figure 2: Performance scaling with increasing task fragmentation (Split-ImageNet-R). Final Average Accuracy ( AFinal ) (↑) as the number of sequential tasks t increases from 5 to 40.
k
%
Split-CIFAR100
Split-ImageNet-R
Split-ImageNet-S
First- k
Last- k
First- k
Last- k
First- k
Last- k
0
0.0
15.83 ± 0.25
12.06 ± 0.34
7.09 ± 0.08
1
0.7
79.57 ± 0.54
65.98 ± 0.73
67.78 ± 1.02
60.10 ± 0.61
58.36 ± 0.55
49.19 ± 0.60
3
2.1
82.48 ± 0.31
60.81 ± 4.12
74.09 ± 0.29
55.92 ± 0.61
61.37 ± 0.43
48.88 ± 0.62
5
3.5
82.89 ± 0.47
61.56 ± 3.16
74.68 ± 0.04
60.64 ± 2.00
62.19 ± 0.48
51.83 ± 0.29
7
4.9
81.65 ± 1.06
64.77 ± 0.59
75.39 ± 0.17
63.95 ± 0.52
62.88 ± 0.57
53.83 ± 0.42
Table 3: Effect of routing depth on Split-CIFAR100, Split-ImageNet-R and Split-ImageNet-S. Final Average Accuracy ( AFinal(↑) ) as the number of HopfieldPooling (HP) layers k increases. First- k inserts HP layers in the first k transformer block; Last- k inserts them in last k blocks ( 12…12−k+1 ). Best: bold, second: underline, third: italic. Green cells indicate chosen configuration used for all paper results.
Model
# params
L2P [ 2 ]
0.47%
DualPrompt [ 3 ]
0.58%
CODA-Prompt [ 4 ]
5.00%
InfLoRA [ 8 ]
1.70%
APER [ 5 ]
1.50%
EASE [ 6 ]
1.32%
Table 4: Trainable parameters (%) relative to the full ViT backbone. RwF maintains a low parameter footprint, comparable to other parameter-efficient CL methods.
Continual learning (CL) aims to incrementally acquire knowledge from sequential data while avoiding catastrophic forgetting. Recently, prompt tuning has attracted increasing attention as an efficient approach for adapting pre-trained models to CL tasks. However, existing prompt design paradigms commonly suffer from retrieval dependence and classifier bias, which make model adaptation sensitive to prompt selection and bias predictions toward newly arrived classes. To address these challenges, we propose Decoupled Prompt Tuning for Continual Learning (DPT4CL), which decouples the CLIP textual prompt into a task-shared prompt distribution and class-specific prompts. The task-shared prompt distribution is derived by optimizing an Information Bottleneck objective to facilitate cross-task knowledge transfer and alleviate classifier bias, while class-specific prompts enhance inter-class separability without relying on explicit prompt retrieval. Furthermore, we establish a unified excess risk bound from an information-theoretic perspective, providing theoretical support for the robust generalization and forgetting mitigation of the proposed framework. Extensive experiments on standard CL benchmarks demonstrate that DPT4CL achieves state-of-the-art performance. The source code is available at https://github.com/Cloudfly-Z/DPT4CL
Yunfei Zhang, Wen Wen, Tieliang Gong +1
National Engineering Lab for Big Data Analytics, School of Computer Science and Technology, Xi’an Jiaotong University, Xi’an 710049, China
Task-free online continual learning has recently emerged as a realistic paradigm for addressing continual learning in dynamic, real-world environments, where data arrive in a non-stationary stream without clear task boundaries and can only be observed once. To consider such challenging scenarios, many recent approaches have employed prompt selection, an adaptive strategy that selects prompts from a pool based on input signals. However, we observe that such selection strategies often fail to select appropriate prompts, yielding suboptimal results despite additional training of key parameters. Motivated by this observation, we propose a simple yet effective SinglePrompt that eliminates the need for prompt selection and focuses on classifier optimization. Specifically, we simply (i) inject a single prompt into each self-attention block, (ii) employ a cosine similarity-based logit design to alleviate the forgetting effect inherent in the classifier weights, and (iii) mask logits for unexposed classes in the current minibatch. With this simple task-free design, our framework achieves state-of-the-art performance across various online continual learning benchmarks. Source code is available at https://github.com/efficient-learning-lab/SinglePrompt.
Identifying and exploiting common features across domains is at the heart of the human ability to make analogies, and is believed to be crucial for the ability to continually learn. To do this successfully, general and flexible computational strategies must be developed. While the extent to which Transformer neural network models can perform compositional reasoning has been the subject of intensive recent investigation, little work has been done to systematically understand how well these models can leverage their representations to learn new, related experiences. To address this gap, we expand the previously developed Learning Equality and Group Operations (LEGO) framework to a continual learning (CL) setting ("continual LEGO"). Using this continual LEGO experimental paradigm, we study the capability of feedforward and recurrent Transformer models to perform CL. We find that BERT, a canonical feedforward Transformer model, learns shortcut solutions that limits its ability to generalize and prevents strong forward transfer to new experiences. In contrast, we find evidence supporting the hypothesis that ALBERT, a recurrent version of BERT, learns a For loop-esque solution, which leads to better CL performance. When applying BERT and ALBERT models to a CL setting that requires composition across experiences, we find that both model families fail. Our investigation suggests that ALBERT models can have their performance drop rescued by use of training strategies that combine data across experiences, but this is not true for BERT models, where a detrimental shortcut solution becomes entrenched with initial training. Our results demonstrate that the recurrent ALBERT model may have an inductive bias better suited for CL and motivate future investigation of the interplay between Transformer architecture and computational solutions that emerge in modern models and tasks.
William T. Redman, Erik C. Johnson, Brian Robinson