Abstract
Sequential fine-tuning of transformers is useful when new data arrive sequentially, especially with shifting distributions. Unlike batch learning, sequential learning demands that training be stabilized despite a small amount of data by balancing new information and previously learned knowledge in the pre-trained models. This challenge is further complicated when training is to be completed in latency-critical environments and learning must additionally quantify and be mediated by uncertainty. Motivated by these challenges, we propose a novel method that frames sequential fine-tuning as a posterior inference problem within a Bayesian framework. Our approach integrates closed-form moment propagation of random variables, Kalman Bayesian Neural Networks, and Taylor approximations of the moments of softmax functions. By explicitly accounting for pre-trained models as priors and adaptively balancing them against new information based on quantified uncertainty, our method achieves robust and data-efficient sequential learning. The effectiveness of our method is demonstrated through numerical simulations involving sequential adaptation of a decision transformer to tasks characterized by distribution shifts and limited memory resources.
Introduction
Standard batch fine-tuning of transformers is computationally intensive and requires storing large datasets. In real-world robotics or edge applications, data arrives sequentially, onboard memory is strictly limited, and the environment's distribution might shift over time. Sequential fine-tuning on small batches often leads to "catastrophic forgetting," where the model rapidly overwrites past knowledge to fit new observations. Furthermore, high-stakes environments require uncertainty quantification, which traditional Bayesian methods like MCMC or Variational Inference cannot provide efficiently for latency-critical systems. The Kalman Bayesian Transformer aims to bridge this gap by creating a fast, sequential, and uncertainty-aware fine-tuning mechanism.
Proposed Method
The proposed method frames sequential fine-tuning as a Bayesian posterior inference problem. The base transformer's attention layers are frozen, while the final linear output layers are replaced with a Bayesian Neural Network (BNN).
Key technical innovations include:
- Kalman Filtering/Smoothing: A Rauch-Tung-Striebel (RTS) Kalman smoother is used to update weight distributions in a single forward-backward pass, avoiding expensive iterative sampling.
- Closed-Form Moment Propagation: The mean and covariance of data are propagated analytically through network layers, reducing computational overhead.
- Softmax Taylor Approximation: A first-order Taylor approximation estimates the mean and covariance of the softmax output, making moment propagation through this non-linear operation tractable.
- Autoregressive Data Preprocessing: An algorithm unrolls autoregressive generation steps into independent, batched representations to satisfy the i.i.d. assumptions required for Kalman updates.
Experimental Evaluation
The method was evaluated using a simulated control task: Inverted Pendulum Control. A Decision Transformer was pre-trained to stabilize a pendulum with specific physical parameters (mass = 0.1, length = 0.5). During fine-tuning, these parameters were drastically changed (mass = 1, length = 5), forcing the model to adapt sequentially to a distribution shift using limited memory resources.
Results and Discussion
The Kalman Bayesian Transformer demonstrated significant improvements in both efficiency and robustness compared to standard retraining methods.
Sample and Memory Efficiency
As shown in the performance analysis, the proposed method achieved a near-perfect success rate in stabilizing the altered pendulum system while maintaining only a single sample in its memory buffer. In contrast, standard warm-started retraining baselines frequently failed due to catastrophic forgetting, even when provided with larger memory buffers ranging from 10 to 50 samples.
Computational Performance and Uncertainty
The method showed a flat scaling of processing time per sample, significantly outperforming standard retraining across all memory capacities. Additionally, the model's predicted variance accurately tracked injected data variance (tested at levels of 0, 10, 20, and 50), demonstrating reliable uncertainty quantification. This inherent robustness to forgetting stems from the Kalman update mechanism, which preserves weights where uncertainty is low and only updates where new data provides strong, confident signals.
Conclusion
By integrating Kalman filtering with transformer architectures, this work enables fast, sequential, and uncertainty-aware fine-tuning. This approach effectively eliminates the need for large replay buffers and protects against catastrophic forgetting. Future research will focus on improving the backward pass by accounting for off-diagonal cross-covariance terms in non-linear activation layers, which are currently ignored for mathematical tractability.
Summary updated