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.