Manuscript Offprint
arXiv:2610.08578Random Feature Gaussian Process Attention: Linear-Time Probabilistic Attention with Calibrated Uncertainty
Abstract
Transformers provide a state-of-the-art modeling framework, yet poor calibration limits their reliability in safety-critical applications. A promising direction addresses this issue by interpreting attention as a Gaussian process (GP) posterior, which enables principled uncertainty calibration but incurs cubic complexity in sequence length due to the inversion of the kernel; although decoupled GP variants reduced the cost to quadratic, the computation remains prohibitive in practice. In this paper, we propose the plug-and-play random Fourier feature Gaussian process attention (RFF-GPA) module, which represents the attention as a GP with a stationary kernel approximated by random Fourier features. This low-rank approximation results in linear-time complexity for approximating the posterior mean and variance, making it far more scalable compared to previous work. Empirical results on multiple real-world datasets show that our attention module improves calibration while maintaining predictive accuracy, and simultaneously reduces computational complexity to linear in the sequence length.
1 Introduction
Large language models (LLMs) such as GPT-3 and its successors (Brown et al. 2020; Zhao et al. 2023) are built upon the Transformer architecture (Vaswani et al. 2017). The core of the Transformer is the self-attention mechanism, which enables scalable modeling of long-range dependencies. Transformers have achieved breakthroughs by leveraging this design, not only in natural language processing but also in vision and multimodal learning (Vaswani et al. 2017; Dosovitskiy et al. 2021; Brown et al. 2020), thereby becoming the leading architecture in modern artificial intelligence.
Despite their apparent successes, Transformers are often overconfident in their predictions and lack principled mechanisms for uncertainty quantification, which makes them unreliable in applications where the downstream tasks are consequential (Guo et al. 2017; Minderer et al. 2021; Papamarkou et al. 2024). Recent work has bridged the standard attention output to the mean of a Gaussian process (GP) posterior (Williams and Rasmussen 2006). Specifically, Chen and Li (2023); Bui et al. (2024) describe an exact and a sparse GP formulation where the number of inducing points equals the sequence length L. From this perspective, we can extend the framework to incorporate the posterior covariance, which naturally provides a principled and well-calibrated quantification of uncertainty that is absent in vanilla Transformers.
Nevertheless, existing approaches remain computationally expensive. Typically, inference requires inversion of a -dimensional kernel matrix, resulting in cubic time and quadratic memory complexity, which makes these methods impractical for long sequences in real-world applications. While Chen and Li (2023) introduced a decoupled GP variant to reduce the complexity from cubic to quadratic by decoupling the inducing points for mean and covariance representations, the resulting cost remains impractical for long sequences.
To obtain a model that combines calibrated uncertainty, strong predictive accuracy, and low computational cost, we propose random Fourier feature Gaussian process attention (RFF-GPA), a plug-and-play attention module for Transformer architectures.
Figure 1 summarizes the progression from standard attention to GP attention and illustrates how our random-feature formulation preserves posterior uncertainty while moving the expensive computation from token space to feature space. Our main contributions are summarized as follows:
• We introduce RFF-GPA, which approximates the attention kernel with random Fourier features (RFF) (Rahimi and Recht 2007) and performs GP posterior inference in the resulting feature space. Using the Woodbury matrix identity (Hager 1989), RFF-GPA avoids direct inversion of the full kernel matrix and computes predictive means and covariance estimates in linear time with respect to the sequence length.
• To relax the symmetry constraint between key and query induced by stationary kernels, we further extend the model to a correlated random-feature GP attention variant, RFF-CGP. This variant models query and key representations through a shared latent GP structure, enabling a more flexible attention mechanism while retaining the computational advantages of the random-feature formulation.
• We evaluate the proposed models on image and text classification benchmarks, as well as under distribution shift on CIFAR-10-C. The results show that our methods improve calibration while maintaining competitive accuracy. They also achieve better runtime and memory scaling than inducing-point GP attention, highlighting the favorable
Equal contribution.
accuracy–calibration–efficiency trade-off of our approach.
2.1 Self-Attention
Given an input sequence of tokens, each represented by a -dimensional vector, the self-attention mechanism first projects the inputs into three different latent spaces (Vaswani et al. 2017):
where , , and are learnable weight matrices that project the input into , , and , referred to as queries, keys, and values, respectively. In standard self-attention, we set the latent dimensionalities of the queries, keys and values to be equal, , and let , yielding for simplicity (Vaswani et al. 2017).
Then, the attention matrix is
where the softmax is applied row-wise. The output is . Here, each row of specifies how a token (i.e., an element of the input sequence) aggregates information from all others, weighted by their query-key similarity.
Furthermore, multi-head self-attention (MHSA) applies the above operation in parallel across H heads, each with its own parameter set . For the h-th head, the output is
and the final output is obtained by concatenating all head outputs and projecting back:
where is a learnable projection. This design allows different heads to capture diverse similarity patterns among tokens, enhancing the expressiveness of the model.
2.2 Kernel Attention
The attention matrix can be further viewed as a softmax similarity with a positive-definite kernel, . Tsai et al. (2019) established a direct connection between the attention module and the classic kernel methods. Generally, we may represent the attention module as a kernel function:
\begin{align*}\mathcal{K}_{QK}&\in\mathbb{R}^{L\times L},\\[\mathcal{K}_{QK}]_{ij}&=\kappa(\mathbf{q}_{i},\mathbf{k}_{j})=\kappa(\mathbf{x}_{i}\mathbf{W}_{Q},\mathbf{x}_{j}\mathbf{W}_{K}),\end{align*}(5)
and the outputs of the Transformer take the form
Note that, to guarantee kernel symmetry in the attention mechanism, we must enforce
that requires , which in turn reduces the expressive capacity of the Transformer. Moreover, the connection (Eq. 6) between kernels and attention modules is crucial for making the probabilistic connection between Transformers and GPs.
2.3 Gaussian Processes
A Gaussian process (GP),
is a distribution over functions such that any finite collection of function values is jointly Gaussian (Williams and Rasmussen 2006). Formally, for inputs , we have
We assume we have noisy observations with . We let and we define the Gram matrix, , to have entries . For test inputs , the predictive posterior distribution is a multivariate Gaussian distribution, , with mean and variance:
2.4 Random Fourier Features
Random Fourier features are a technique to accelerate computation of kernel methods through a low-rank factorization. The basic theorem necessary to approximate a stationary kernel is Bochner's theorem (Bochner 1959), which states that any continuous shift-invariant kernel, , can be expressed as the Fourier transform of a nonnegative spectral density , namely:
Based on this result, Rahimi and Recht (2007) proposed to first draw frequencies , and then obtain an unbiased estimator for kernel function:
where the randomized feature mapping is:
As a result, the full kernel matrix is approximated by with , allowing scalable GP computations through low-rank approximations instead of the direct inversion of .
A Standard Attention
B Gaussian Process
D Exact GP Attention

Figure 1: Overview of RFF-GPA. (A) Standard attention produces deterministic token representations without explicit uncertainty. (B,D) A GP formulation provides posterior mean and variance, but exact GP attention requires an expensive token-space inverse. (C) Random Fourier features provide a compact approximation of the stationary kernel. (E) RFF-GPA performs GP inference in the resulting feature space, replacing the inverse with an inverse while retaining the posterior mean and token-wise predictive variance.
2.5 Related Works
Subsequent extensions of the Transformer have accordingly combined the RFF approximations and the attention kernel. Peng et al. (2021) introduced random feature attention (RFA) as a direct replacement of the linear projections of the queries and keys in the original Transformer with the basis function in Eq. (13). In parallel, Choromanski et al. (2021) introduced positivity and orthogonality constraints for the random feature approximation of the attention module. These approaches are efficient and but they only model the interaction between the queries and keys as a kernel. Moreover, they do not pose the Transformer as a fully Bayesian model and therefore lack principled uncertainty quantification.
In Bayesian deep learning, Neal (1995) originally established the connection between Gaussian processes and neural networks. Damianou and Lawrence (2013) then introduced the deep Gaussian process, which applies the feedforward network structure to Gaussian process regression. Gal and Ghahramani (2016) further established the connection between training deep neural networks with approximate Bayesian inference for deep Gaussian processes.
Comparatively, the Bayesian perspective on Transformers remains underexplored. Tran et al. (2019); Fan et al. (2020); Xue et al. (2021) implemented Bayesian Transformers with varying architectures and priors on the network parameters, but these methods overlook the kernelized attention structure which limits their modeling capacity. As we will demonstrate, unifying attention modules, random feature kernel approximations, and Gaussian processes will be crucial to obtain properly calibrated probabilistic Transformers.
3 Methodology
This section first presents the proposed random Fourier feature Gaussian process attention module (Sec. 3.1), then details its integration into the standard Transformer (Sec. 3.2), and finally provides an illustrative implementation in GP-based Transformers (Sec. 3.3).
Algorithm 1 RFF-GPA (Single-Head): Random Fourier Feature Gaussian Process Attention
Require: Sequence of tokens
1: Compute using Eq. (1).
2: Draw samples from using the reparameterization trick.
3: Compute the feature maps and using , and sampled spectral points .
4: Compute and using Eq. (20).
5: Draw samples from using the reparameterization trick.
6: Evaluate the ELBO using Eq. (26).
7: Maximize the ELBO and update using Adam (Kingma and Ba 2015).
Ensure: Model parameters and variational parameters .
3.1 Random Fourier Feature Gaussian Process Attention (RFF-GPA)
In a typical GP-based Transformer (Bui et al. 2024; Chen and Li 2023), the output of the kernel attention module is modeled as the predictive posterior mean of a Gaussian process. We interpret the keys as the “training inputs”, the value matrix as the corresponding (noisy) observations, and the queries as the “test inputs”. Let denote the kernel Gram matrix with keys as inputs. Denoting the -th column of and as and , respectively, the -th column of the kernel attention output is precisely the GP predictive posterior mean (see Eq. 9):
Based on this interpretation, it is straightforward to obtain the attention covariance as
The overall output of the kernel attention module Y can thus be interpreted as the predictive mean of D independent GPs, with the corresponding predictive covariance capturing the associated uncertainty. This view extends naturally to multi-head self-attention, where the predictive outputs from all heads are concatenated and mapped through the output projection .
Unfortunately, inverting the kernel Gram matrix incurs cubic complexity, which is impractical for long sequences. Two common strategies to reduce the cost of GP inference are: (i) inducing points (sparse GPs) and (ii) RFFs. Chen and Li (2023) interpret the attention module as a sparse GP by treating queries as inducing points, which makes the number of inducing points equal to L but still results in complexity. Alternatively, we turn to RFFs (Eq. 12), where the kernel Gram matrices can be approximated as and . Substituting those approximations into Eq. (14) and Eq. (15) yields :
For simplicity, we denote the computational demanding term as
By exploiting the low-rank structure of , we can apply the Woodbury identity and obtain
where we only need to invert an matrix, with pre-selected, thereby reducing the overall cost to , i.e., linear in .
Replacing the Eq. (18) within Eq. (16), we can obtain
Instead of predicting the full covariance function, we only report the diagonal variance, denoted as , that represents the uncertainty for each token.
In supervised Transformer applications, the latent Gaussian attention output Y serves as the representation passed to the final prediction head. Consequently, the observed labels are modeled through a likelihood , yielding the overall supervised joint distribution
where denotes the categorical likelihood induced by the prediction head.
3.2 Variational Inference for Standard Transformers with RFF-GPA Module
The RFF-GPA module introduces latent attention outputs and spectral points whose exact posterior is not available in closed form, so we use variational inference to obtain a tractable training objective. We now describe how to train a Transformer equipped with the proposed RFF-GPA module within a variational inference (VI) framework. Our goal is to jointly learn the model parameters , , and infer the posterior distribution of the spectral points given the observations . Since the exact posterior is intractable, VI posits a tractable family to approximate it and optimizes both the variational parameters of and the model parameters by maximizing the evidence lower bound (ELBO).
Following the settings in Li et al. (2024); Yang et al. (2025), we assume that the variational distribution coincides with the prior ,
For clarity, the following derivations focus on a single head, but the extension to the multi-head case is straightforward.
Note that, for notational simplicity, now denote the corresponding parameters for all layers and heads.
See Appendix A for an empirical Bayes view.
where denotes the mean and S is a diagonal covariance matrix. Consequently, the ELBO is:
where the expectation over the log-likelihood, , is required since the attention output is a random latent variable rather than a deterministic value, with its mean and covariance given by Eq. (19) and Eq. (20), respectively.
This term indeed measures the expected reconstruction accuracy. For evaluation, we employ the reparameterization trick to draw samples from and :
and thereby obtain an unbiased Monte Carlo estimator of the reconstruction term:
Consequently, we optimize the above objective with respect to both the model parameters and the variational parameters . The complete procedure is summarized in Algorithm 1.
3.3 Random Fourier Feature Correlated Gaussian Process Attention (RFF-CGP)
Although RFF-GPA provides scalable uncertainty-aware attention, its stationary-kernel construction still inherits a symmetry constraint from standard kernel attention: the query and key projections are tied through the same kernel structure, limiting the ability to model asymmetric query-key interactions. This can be undesirable because queries and keys play different roles in attention, and forcing them into a symmetric kernel space can restrict representation capacity. To address this limitation, we extend our random-feature formulation to correlated Gaussian process attention (CGP) (Bui et al. 2024), yielding random Fourier feature correlated Gaussian process attention (RFF-CGP).
CGP attention models the self-attention output as the cross-covariance between two correlated Gaussian processes, each defined by an affine transformation of a latent canonical GP. This construction naturally removes the requirement that , which allows asymmetric kernels and enhances representation capacity. In particular, the d-th output column can be expressed as
where are the Gram or cross-covariance matrices induced by the canonical kernel, and is the d-th column of the value matrix , as in Eq. (14).
To make Eq. (27) scalable, we first substitute each kernel matrix with its RFF approximations. Let be the RFF embeddings of queries, keys, and the latent canonical GP inputs, respectively. Then, we have:
(28)
Substituting into Eq. (27) gives the following predictive mean:
Both inverses in Eq. (29) involve matrices of size . Using the Woodbury identity, they can be rewritten as inversions of matrices:
Analogous to Eq. (20), the predictive covariance of RFF-CGP can be derived in closed form by substituting the RFF approximations into the CGP conditional covariance (Bui et al. 2024). Specifically, in the CGP construction, the query process is conditioned on the canonical latent GP O; the resulting token-wise predictive variance is therefore the residual query variance after this conditioning,
which is the exact one-step posterior variance and reduces to the RFF-GPA variance in Eq. (20) when (i.e. ). The data-dependent terms of the full CGP conditional covariance cancel against the mean outer product, so Eq. (30) is independent of , positive semi-definite, and computed in via the same inversion as in Eq. (29).
4 Experiments
We first evaluate our proposed method (RFF-GPA and RFF-CGP) on in-distribution accuracy and calibration in Sec. 4.1. We then demonstrate its efficiency and scalability in terms of computation and memory on synthetic sequence benchmarks in Sec. 4.2, and finally evaluate out-of-distribution robustness under distribution shift on CIFAR-10-C in Sec. 4.3.
4.1 In-Distribution Accuracy and Calibration
We first evaluate in-distribution accuracy and calibration across a broad suite of six classification benchmarks spanning both modalities: three image datasets (Fashion-MNIST, CIFAR-10, SVHN) and three text datasets (20 Newsgroups, Hyperpartisan, SST-2). All methods share an identical Transformer backbone and training protocol, differing only in the attention/output uncertainty mechanism, so that differences in Table 1 reflect the uncertainty mechanism rather than
Appendix B provides detailed descriptions of all baseline methods, together with their training configurations and hyperparameter settings.
Full dataset descriptions, splits, and preprocessing are provided in Appendix C.
| METHOD | IMAGE | TEXT | ||||
|---|---|---|---|---|---|---|
| F-MNIST | CIFAR-10 | SVHN | 20NG | Hyperp. | SST-2 | |
| METRIC | ACC ↑ | |||||
| MLE | 0.889 ± 0.003 | 0.715 ± 0.008 | 0.909 ± 0.007 | 0.654 ± 0.015 | 0.744 ± 0.015 | 0.775 ± 0.009 |
| MLE+Temp | 0.889 ± 0.003 | 0.715 ± 0.008 | 0.909 ± 0.007 | 0.654 ± 0.015 | 0.744 ± 0.015 | 0.775 ± 0.009 |
| MCD | 0.885 ± 0.001 | 0.713 ± 0.002 | 0.902 ± 0.001 | 0.682 ± 0.004 | 0.785 ± 0.010 | 0.781 ± 0.006 |
| SNGP | 0.903 ± 0.002 | 0.727 ± 0.007 | 0.913 ± 0.004 | 0.680 ± 0.009 | 0.774 ± 0.015 | 0.789 ± 0.004 |
| SGPA | 0.888 ± 0.002 | 0.665 ± 0.017 | 0.851 ± 0.007 | 0.680 ± 0.002 | 0.749 ± 0.036 | 0.785 ± 0.004 |
| RFF-CGP (ours) | 0.902 ± 0.002 | 0.737 ± 0.003 | 0.910 ± 0.006 | 0.651 ± 0.020 | 0.815 ± 0.036 | 0.790 ± 0.009 |
| RFF-GPA (ours) | 0.915 ± 0.003 | 0.759 ± 0.001 | 0.915 ± 0.000 | 0.682 ± 0.010 | 0.800 ± 0.015 | 0.789 ± 0.010 |
| METRIC | NLL ↓ | |||||
| MLE | 0.317 ± 0.005 | 0.837 ± 0.022 | 0.316 ± 0.020 | 1.483 ± 0.045 | 0.538 ± 0.023 | 0.599 ± 0.042 |
| MLE+Temp | 0.304 ± 0.008 | 0.814 ± 0.024 | 0.305 ± 0.019 | 1.224 ± 0.041 | 0.527 ± 0.030 | 0.555 ± 0.017 |
| MCD | 0.317 ± 0.004 | 0.819 ± 0.012 | 0.323 ± 0.006 | 1.388 ± 0.025 | 0.558 ± 0.018 | 0.535 ± 0.018 |
| SNGP | 0.282 ± 0.008 | 0.807 ± 0.014 | 0.299 ± 0.007 | 1.381 ± 0.052 | 0.511 ± 0.027 | 0.641 ± 0.045 |
| SGPA | 0.313 ± 0.003 | 0.948 ± 0.043 | 0.483 ± 0.024 | 1.291 ± 0.010 | 0.548 ± 0.046 | 0.592 ± 0.057 |
| RFF-CGP (ours) | 0.284 ± 0.003 | 0.802 ± 0.005 | 0.313 ± 0.006 | 1.643 ± 0.173 | 0.415 ± 0.037 | 0.532 ± 0.043 |
| RFF-GPA (ours) | 0.252 ± 0.003 | 0.713 ± 0.007 | 0.292 ± 0.001 | 1.316 ± 0.050 | 0.501 ± 0.007 | 0.546 ± 0.062 |
| METRIC | ECE ↓ | |||||
| MLE | 0.051 ± 0.005 | 0.065 ± 0.005 | 0.030 ± 0.003 | 0.158 ± 0.015 | 0.120 ± 0.009 | 0.135 ± 0.017 |
| MLE+Temp | 0.031 ± 0.003 | 0.062 ± 0.001 | 0.027 ± 0.001 | 0.152 ± 0.006 | 0.114 ± 0.001 | 0.127 ± 0.009 |
| MCD | 0.030 ± 0.002 | 0.064 ± 0.004 | 0.025 ± 0.002 | 0.136 ± 0.006 | 0.156 ± 0.010 | 0.107 ± 0.006 |
| SNGP | 0.026 ± 0.006 | 0.063 ± 0.006 | 0.017 ± 0.003 | 0.156 ± 0.007 | 0.122 ± 0.035 | 0.132 ± 0.009 |
| SGPA | 0.021 ± 0.002 | 0.025 ± 0.013 | 0.016 ± 0.005 | 0.134 ± 0.003 | 0.136 ± 0.073 | 0.127 ± 0.016 |
| RFF-CGP (ours) | 0.029 ± 0.004 | 0.066 ± 0.013 | 0.023 ± 0.008 | 0.137 ± 0.034 | 0.111 ± 0.028 | 0.101 ± 0.014 |
| RFF-GPA (ours) | 0.021 ± 0.003 | 0.046 ± 0.003 | 0.013 ± 0.001 | 0.130 ± 0.010 | 0.123 ± 0.017 | 0.105 ± 0.011 |
Table 1: In-distribution accuracy and calibration on three image and three text classification benchmarks. Each column reports one dataset; row blocks report ACC ↑, NLL ↓, and ECE ↓. Mean and standard deviation are computed over five runs. The best result per column is bolded and the second-best is underlined.
backbone architecture or tuning. We compare our random-feature GP attention (RFF-GPA and RFF-CGP) against a deterministic maximum-likelihood head (Vaswani et al. 2017, MLE), its post-hoc temperature-scaled variant (Guo et al. 2017, MLE+Temp), Monte Carlo dropout (Gal and Ghahramani 2016, MCD), the spectral-normalized neural GP (Liu et al. 2020, SNGP), and sparse GP attention (Chen and Li 2023, SGPA). Accuracy is measured by top-1 accuracy (ACC; higher is better), and calibration by negative log-likelihood (NLL) and expected calibration error (ECE), both lower being better.
Accuracy. RFF-GPA is strongest on the image benchmarks, attaining the best accuracy on Fashion-MNIST (0.915), CIFAR-10 (0.759), and SVHN (0.915), while also matching the best mean accuracy on 20 Newsgroups. On the text benchmarks, the two random-feature variants are complementary: RFF-CGP achieves the best accuracy on Hyperpartisan (0.815) and SST-2 (0.790), while RFF-GPA remains second-best on both. Notably, RFF-GPA substantially improves over SGPA on the image datasets (e.g. +9.4 points on CIFAR-10 and +6.4 on SVHN), indicating that the random-feature GP formulation not only reduces cost but can also yield a more effective attention mechanism than inducing-point sparse GPs.
Calibration. RFF-GPA delivers strong calibration on the image benchmarks, achieving the best NLL on Fashion-MNIST, CIFAR-10, and SVHN. For ECE, it is best on SVHN and 20 Newsgroups, ties SGPA for the best result on Fashion-MNIST, and is second-best on CIFAR-10 and SST-2. RFF-CGP is particularly strong on the text benchmarks, attaining the best NLL and ECE on Hyperpartisan and SST-2. This modality-dependent pattern suggests that the independent-head RFF-GPA formulation is especially effective for local visual patch interactions, whereas the correlated query-key structure in RFF-CGP can better capture asymmetric semantic interactions in text. Overall, the two random-feature GP variants provide competitive or leading accuracy while yielding well-calibrated predictive uncertainty in a single, linear-time forward pass, without the ensembling or inducing-point machinery required by competing approaches.
Training Time vs L

Throughput vs L
Sequence length L

Sequence length L
Figure 2: Training Time (Left): Training time per step as a function of sequence length L across all methods (log–log axes; shaded 95% CI). Throughput (Right): Throughput (tokens/sec) as a function of L. Curves for the inducing-point baselines (SGPA, SCGP) are continued past their largest feasible length along their fitted scaling trend.
4.2 Efficiency and Scalability
We now show that RFF-GPA delivers favorable runtime–calibration behavior compared with inducing-point GP attention. Following the linear-time analysis in Sec. 3.1, we benchmark a single attention block with a lightweight readout on synthetic inputs while varying the sequence length Figure 2 reports training time per optimization step and throughput (tokens/sec) as functions of L, each averaged over five runs with 95% confidence intervals.
RFF-GPA and RFF-CGP scale linearly with L, thanks to the RFF approximation that only inverts an matrix. In contrast, the MLE and SNGP softmax heads scale quadratically with sequence length, while inducing-point variants such as SGPA and SCGP exhibit the expected super-linear scaling and incur steep computational costs once . These trends are consistent with the complexity analysis in Sec. 3.1.
The key reason is that the random-feature dimension M is fixed independently of the sequence length, so increasing L only adds feature evaluations and matrix multiplications involving and . The expensive inverse remains in the feature space rather than the token space. By contrast, inducing-point GP attention still materializes sequence-dependent kernel matrices and repeatedly applies kernel operations whose memory footprint grows with L, which explains the sharp throughput degradation of SGPA and SCGP at longer sequences. Thus, the empirical scaling curves reflect the intended computational design rather than an implementation artifact. This also makes the cost predictable across batch sizes and sequence lengths, since the dominant operations depend on the chosen feature budget rather than on a growing token-token covariance matrix that must be recomputed for each input.
4.3 Out-of-Distribution Robustness
We finally evaluate robustness under distribution shift using the CIFAR-10-C benchmark (Hendrycks and Dietterich 2019), which applies 19 common corruption types (e.g., noise, blur, weather effects) at five severity levels to the CIFAR-10 test set. We take the models trained on clean CIFAR-10 in Sec. 4.1 and evaluate them on the corrupted test sets without any re-training or fine-tuning, so the benchmark measures how gracefully each method degrades once deployed beyond its training distribution. Table 2 reports the clean CIFAR-10 result at s=0 and, for , each metric averaged over the 19 corruptions at every severity level as mean confidence interval over five runs.
Accuracy. RFF-GPA is the most accurate method at every severity level, from the clean set (0.759) down to the most severe corruptions (0.514 at s=5), consistently ahead of the strong SNGP baseline and improving on the inducing-point SGPA by a large margin (e.g. +7.3 points at s=5). This shows that the accuracy advantage of the random-feature GP formulation is preserved, not merely retained, under distribution shift.
Calibration. The central finding is that RFF-GPA is the best-calibrated method across the corruption range in terms of NLL and ECE: it attains the lowest NLL at every severity and the lowest ECE at every non-clean severity ( ), while remaining second only to SGPA on the clean set. Crucially, SGPA reaches competitive ECE only with a substantial loss in accuracy, whereas RFF-GPA combines the best accuracy with the strongest aggregate NLL/ECE. This distinction matters because calibration under shift is meaningful only when
The full benchmark protocol—backbone, hyperparameters, hardware, and measurement details—is given in Appendix E.
We reuse the exact CIFAR-10 checkpoints, backbone, and evaluation protocol from Sec. 4.1; the corruption pipeline, normalization, and per-severity averaging are detailed in Appendix F; baseline and backbone details follow Appendix B.
| METHOD | s=0 (clean) | s=1 | s=2 | s=3 | s=4 | s=5 |
|---|---|---|---|---|---|---|
| METRIC | ACC ↑ | |||||
| MLE | 0.715 ± 0.008 | 0.681 ± 0.010 | 0.637 ± 0.009 | 0.605 ± 0.009 | 0.564 ± 0.010 | 0.503 ± 0.008 |
| SNGP | 0.727 ± 0.007 | 0.693 ± 0.006 | 0.647 ± 0.001 | 0.613 ± 0.001 | 0.572 ± 0.002 | 0.508 ± 0.003 |
| SGPA | 0.665 ± 0.023 | 0.613 ± 0.023 | 0.556 ± 0.024 | 0.530 ± 0.018 | 0.495 ± 0.014 | 0.441 ± 0.012 |
| RFF-CGP (ours) | 0.737 ± 0.003 | 0.664 ± 0.003 | 0.616 ± 0.004 | 0.588 ± 0.004 | 0.548 ± 0.001 | 0.490 ± 0.002 |
| RFF-GPA (ours) | 0.759 ± 0.001 | 0.702 ± 0.001 | 0.653 ± 0.002 | 0.620 ± 0.002 | 0.576 ± 0.003 | 0.514 ± 0.002 |
| METRIC | NLL ↓ | |||||
| MLE | 0.837 ± 0.022 | 0.946 ± 0.023 | 1.102 ± 0.015 | 1.238 ± 0.010 | 1.421 ± 0.019 | 1.718 ± 0.009 |
| SNGP | 0.807 ± 0.014 | 0.921 ± 0.010 | 1.088 ± 0.023 | 1.234 ± 0.031 | 1.425 ± 0.044 | 1.747 ± 0.060 |
| SGPA | 0.948 ± 0.060 | 1.111 ± 0.062 | 1.298 ± 0.069 | 1.396 ± 0.043 | 1.539 ± 0.020 | 1.770 ± 0.017 |
| RFF-CGP (ours) | 0.802 ± 0.005 | 0.990 ± 0.023 | 1.155 ± 0.031 | 1.271 ± 0.031 | 1.445 ± 0.033 | 1.714 ± 0.047 |
| RFF-GPA (ours) | 0.713 ± 0.007 | 0.865 ± 0.012 | 1.025 ± 0.016 | 1.151 ± 0.023 | 1.326 ± 0.028 | 1.613 ± 0.027 |
| METRIC | ECE ↓ | |||||
| MLE | 0.065 ± 0.005 | 0.079 ± 0.008 | 0.106 ± 0.009 | 0.131 ± 0.008 | 0.164 ± 0.007 | 0.209 ± 0.012 |
| SNGP | 0.063 ± 0.006 | 0.080 ± 0.011 | 0.107 ± 0.016 | 0.132 ± 0.014 | 0.163 ± 0.015 | 0.207 ± 0.013 |
| SGPA | 0.025 ± 0.013 | 0.055 ± 0.020 | 0.090 ± 0.023 | 0.104 ± 0.016 | 0.130 ± 0.011 | 0.161 ± 0.009 |
| RFF-CGP (ours) | 0.066 ± 0.013 | 0.080 ± 0.020 | 0.108 ± 0.019 | 0.128 ± 0.016 | 0.157 ± 0.014 | 0.197 ± 0.014 |
| RFF-GPA (ours) | 0.046 ± 0.003 | 0.047 ± 0.005 | 0.074 ± 0.005 | 0.094 ± 0.006 | 0.123 ± 0.004 | 0.160 ± 0.003 |
Table 2: Out-of-distribution robustness on CIFAR-10-C. Each metric is averaged over the 19 corruption types at severity ; is the clean CIFAR-10 test set. Row blocks report ACC ↑, NLL ↓, and ECE ↓. Values are mean ± 95% CI over five runs; all models are evaluated without re-training. The best result per column is bolded and the second-best is underlined.
the model still preserves useful predictive power: a method can appear well calibrated by becoming uniformly uncertain, but that behavior is less useful if accuracy collapses. RFF-GPA avoids this failure mode by reducing overconfidence while retaining the strongest predictions across severity levels. The deterministic MLE head degrades sharply in NLL as severity grows (0.84 → 1.72), reflecting increasingly overconfident predictions under corruption. Overall, the CIFAR-10-C results confirm that the random-feature GP framework yields reliable uncertainty under distribution shift while preserving predictive performance.
Spatial uncertainty. We next examine whether the token-wise GP posterior variance, , responds locally to input ambiguity. Figure 3 shows final-layer uncertainty before and after adding Gaussian noise to only 12 of the 256 CIFAR-10 patch tokens. Variance is averaged over four heads and 30 paired Monte Carlo passes, with the same random-feature draw reused for each clean/corrupted pair. For both an object-side perturbation and a matched background perturbation, the prediction remains bird, while positive is concentrated around the perturbed tokens. This provides a spatial complement to the image-level calibration results above.

Figure 3: Localized token-wise posterior uncertainty. Object perturbation (top) and matched background perturbation (bottom). Red grids mark the 12 perturbed tokens; clean and corrupted uncertainty maps use a shared scale.
5 Conclusion
In this paper, we introduced a Gaussian process Transformer where we model the attention kernel using a random Fourier feature approximation. By taking advantage of the low-rank factorization of the attention module, we can obtain a fully Bayesian model that is scalable with respect to the sequence length. We have demonstrated the effectiveness of the RFF-GPA on image and text data sets, especially with respect to uncertainty-aware metrics, compared to the vanilla Transformer and other competing GP-based methods. In future work, we hope to further enrich the approximate kernel structure by modeling non-stationarity across each head, or by assuming a deep generative model as a prior on the random frequencies.
References
Bochner, S. 1959. Lectures on Fourier Integrals, volume 42. Princeton University Press.
Brown, T.; Mann, B.; Ryder, N.; Subbiah, M.; Kaplan, J. D.; Dhariwal, P.; Neelakantan, A.; Shyam, P.; Sastry, G.; Askell, A.; et al. 2020. Language models are few-shot learners. Advances in Neural Information Processing Systems, 33: 1877–1901.
Bui, L. M.; Huu, T. T.; Dinh, D.; Nguyen, T. M.; and Hoang, T. N. 2024. Revisiting Kernel Attention with Correlated Gaussian Process Representation. In Uncertainty in Artificial Intelligence.
Chen, W.; and Li, Y. 2023. Calibrating Transformers via sparse Gaussian processes. In International Conference on Learning Representations.
Choromanski, K.; Likhosherstov, V.; Dohan, D.; Song, X.; Gane, A.; Sarlos, T.; Hawkins, P.; Davis, J.; Mohiuddin, A.; Kaiser, L.; et al. 2021. Rethinking attention with performers. In International Conference on Learning Representations.
Damianou, A.; and Lawrence, N. D. 2013. Deep Gaussian processes. In Artificial Intelligence and Statistics, 207–215. PMLR.
Dosovitskiy, A.; Beyer, L.; Kolesnikov, A.; Weissenborn, D.; Zhai, X.; Unterthiner, T.; Dehghani, M.; Minderer, M.; Heigold, G.; Gelly, S.; et al. 2021. An image is worth words: Transformers for image recognition at scale. In International Conference on Learning Representations.
Fan, X.; Zhang, S.; Chen, B.; and Zhou, M. 2020. Bayesian attention modules. Advances in Neural Information Processing Systems, 33: 16362–16376.
Gal, Y.; and Ghahramani, Z. 2016. Dropout as a Bayesian approximation: Representing model uncertainty in deep learning. In International Conference on Machine Learning, 1050–1059. PMLR.
Guo, C.; Pleiss, G.; Sun, Y.; and Weinberger, K. Q. 2017. On calibration of modern neural networks. In International Conference on Machine Learning, 1321–1330. PMLR.
Hager, W. W. 1989. Updating the inverse of a matrix. SIAM Review, 31(2): 221–239.
Hendrycks, D.; and Dietterich, T. 2019. Benchmarking Neural Network Robustness to Common Corruptions and Perturbations. In International Conference on Learning Representations.
Kiesel, J.; Mestre, M.; Shukla, R.; Vincent, E.; Adineh, P.; Corney, D.; Stein, B.; and Potthast, M. 2019. SemEval-2019 Task 4: Hyperpartisan News Detection. In Proceedings of the 13th International Workshop on Semantic Evaluation, 829–839.
Kingma, D. P.; and Ba, J. 2015. Adam: A method for stochastic optimization. In International Conference on Learning Representations.
Krizhevsky, A.; and Hinton, G. 2009. Learning multiple layers of features from tiny images. Technical report, University of Toronto.
Lang, K. 1995. NewsWeeder: Learning to filter netnews. In Machine Learning Proceedings 1995, 331–339. Elsevier.
Li, Y.; Lin, Z.; Yin, F.; and Zhang, M. M. 2024. Preventing Model Collapse in Gaussian Process Latent Variable Models. In International Conference on Machine Learning, 28278–28308. PMLR.
Liu, J.; Lin, Z.; Padhy, S.; Tran, D.; Bedrax Weiss, T.; and Lakshminarayanan, B. 2020. Simple and principled uncertainty estimation with deterministic deep learning via distance awareness. Advances in Neural Information Processing Systems, 33: 7498–7512.
Minderer, M.; Djolonga, J.; Romijnders, R.; Hubis, F.; Zhai, X.; Houlsby, N.; Tran, D.; and Lucic, M. 2021. Revisiting the calibration of modern neural networks. Advances in Neural Information Processing Systems, 34: 15682–15694.
Neal, R. M. 1995. Bayesian Learning for Neural Networks. Ph.D. thesis, University of Toronto.
Netzer, Y.; Wang, T.; Coates, A.; Bissacco, A.; Wu, B.; and Ng, A. Y. 2011. Reading digits in natural images with unsupervised feature learning. In NIPS Workshop on Deep Learning and Unsupervised Feature Learning.
Papamarkou, T.; Skoularidou, M.; Palla, K.; Aitchison, L.; Arbel, J.; Dunson, D.; Filippone, M.; Fortuin, V.; Hennig, P.; Hernández-Lobato, J. M.; et al. 2024. Position: Bayesian deep learning is needed in the age of large-scale AI. In International Conference on Machine Learning, 39556–39586.
Peng, H.; Pappas, N.; Yogatama, D.; Schwartz, R.; Smith, N.; and Kong, L. 2021. Random Feature Attention. In International Conference on Learning Representations.
Rahimi, A.; and Recht, B. 2007. Random features for large-scale kernel machines. Advances in Neural Information Processing Systems, 20.
Socher, R.; Perelygin, A.; Wu, J.; Chuang, J.; Manning, C. D.; Ng, A. Y.; and Potts, C. 2013. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, 1631–1642.
Tran, D.; Dusenberry, M.; van der Wilk, M.; and Hafner, D. 2019. Bayesian layers: A module for neural network uncertainty. Advances in Neural Information Processing Systems, 32.
Tsai, Y.-H. H.; Bai, S.; Yamada, M.; Morency, L.-P.; and Salakhutdinov, R. 2019. Transformer Dissection: A Unified Understanding for Transformer's Attention via the Lens of Kernel. In Proceedings of the Conference on Empirical Methods in Natural Language Processing.
Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A. N.; Kaiser, L.; and Polosukhin, I. 2017. Attention is all you need. Advances in Neural Information Processing Systems, 30.
Williams, C. K.; and Rasmussen, C. E. 2006. Gaussian Processes for Machine Learning, volume 2. MIT Press.
Xiao, H.; Rasul, K.; and Vollgraf, R. 2017. Fashion-MNIST: a novel image dataset for benchmarking machine learning algorithms. arXiv preprint arXiv:1708.07747.
Xue, B.; Yu, J.; Xu, J.; Liu, S.; Hu, S.; Ye, Z.; Geng, M.; Liu, X.; and Meng, H. 2021. Bayesian transformer language models for speech recognition. In ICASSP 2021-2021 IEEE International Conference on Acoustics, Speech and Signal Processing, 7378–7382. IEEE.
Yang, Z.; Li, Y.; Lin, Z.; Zhang, M. M.; and Olmos, P. M. 2025. Multi-View Oriented GPLVM: Expressiveness and Efficiency. In Advances in Neural Information Processing Systems.
Zhao, W. X.; Zhou, K.; Li, J.; Tang, T.; Wang, X.; Dou, Z.; and Wen, J.-R. 2023. A Survey of Large Language Models. arXiv preprint arXiv:2303.18223.
APPENDICES
APPENDIX CONTENTS
Appendix A Clarification on the Empirical Bayes Treatment of Spectral Points
Appendix B Baseline Methods
Appendix C Datasets
Appendix D Model Configuration and Experimental Design
Appendix E Efficiency and Scalability Benchmark
Appendix F Out-of-Distribution Robustness Protocol
A Clarification on the Empirical Bayes Treatment of Spectral Points
In principle, one could introduce a more flexible variational posterior for the spectral points, jointly with the latent Gaussian attention distribution . The resulting ELBO would take the general form
However, in our setting the spectral points only influence the model through the GP prior structure in the attention kernel. We empirically observed that optimizing the ELBO with a highly expressive tends to drive the KL term toward zero, yielding . In other words, the variational posterior typically collapses back to the parametric prior family, while introducing additional variance and instability during training.
Motivated by these observations, we adopt the simplified assumption and directly optimize the prior parameters (e.g., mean and diagonal covariance). This provides a lightweight and stable empirical Bayes treatment of the spectral density, while retaining the probabilistic interpretation of the GP-based attention module.
B Baseline Methods
This appendix summarizes the baseline methods used in our experiments, together with their modeling assumptions and sources of uncertainty. All baselines are implemented using the same backbone architecture and training protocol unless otherwise stated.
SGPA (Sparse Gaussian Process Attention). SGPA performs Bayesian inference directly in the output space of multi-head attention by replacing the scaled dot-product similarity with a valid kernel, and placing a sparse variational Gaussian process (SVGP) posterior over the attention outputs. Concretely, SGPA models the attention output as a GP mapping with a kernel matrix computed from queries and keys, and uses inducing variables to obtain a scalable variational posterior. This yields calibrated predictive uncertainty while keeping the computation tractable via sparse GP machinery (Chen and Li 2023).
SCGP (Sparse Correlated Gaussian Process). SCGP is a scalable correlated-GP formulation for kernel attention, derived from correlated Gaussian-process Transformer models. It introduces a sparse approximation (via inducing inputs) to mitigate the cubic cost of correlated GP inference, while retaining correlation structure in the GP treatment of kernel attention. In practice, SCGP computes kernel-attention statistics through a correlated GP posterior with a sparse scheme, improving scalability compared to the full correlated GP formulation (Bui et al. 2024).
SNGP (Spectral-normalized Neural Gaussian Process). SNGP is a neural Gaussian process model that combines a deterministic deep neural network with a GP-inspired output layer. Specifically, the penultimate layer features are treated as inputs to a GP classifier, and spectral normalization is applied to the network weights to ensure distance awareness and improved uncertainty estimates. Unlike fully Bayesian neural networks, SNGP performs deterministic training while approximating predictive uncertainty through a GP-style output covariance, making it a strong and scalable baseline for uncertainty estimation in deep models (Liu et al. 2020).
MCD (Monte Carlo Dropout). Monte Carlo dropout (MCD) is a widely used Bayesian approximation for deep neural networks, where dropout is interpreted as approximate variational inference over network weights. At test time, multiple stochastic forward passes are performed with dropout enabled, and predictive uncertainty is estimated from the empirical mean and variance of the outputs:
where denotes a random realization of the network weights induced by dropout. MCD captures parameter-level (episodic) uncertainty without modifying the attention mechanism itself, and serves as a standard baseline for uncertainty-aware Transformers (Gal and Ghahramani 2016).
| Name | Description | Size | Citation/source |
|---|---|---|---|
| Fashion-MNIST | Grayscale 28×28 clothing-image classification with 10 classes; patch size 4×4 gives sequence length 49. | 60k train / 10k test | Xiao, Rasul, and Vollgraf (2017) |
| CIFAR-10 | Color 32×32 natural-image classification with 10 classes; patch size 2×2 gives sequence length 256. | 50k train / 10k test | Krizhevsky and Hinton (2009) |
| SVHN | Real-world 32×32 street-view house-number digit classification with 10 classes; sequence length 256. | ~73k train / 26k test | Netzer et al. (2011) |
| CIFAR-10-C | Distribution-shift benchmark built from CIFAR-10 with common image corruptions at multiple severities. | 19 corruptions × 5 severities × 10k images | Hendrycks and Dietterich (2019) |
| 20 Newsgroups | Topic classification over newsgroup posts with 20 classes; text is truncated/padded to 512 tokens. | ~18k documents | Lang (1995) |
| Hyperpartisan | Binary news-bias classification using the by-article split; text is truncated/padded to 512 tokens. | Small by-article split | Kiesel et al. (2019) |
| SST-2 | Binary sentiment classification from GLUE; we evaluate on the development set because test labels are withheld. | ~67k train; dev evaluation | Socher et al. (2013) |
Table 3: Datasets used in the in-distribution and out-of-distribution experiments. Images are patchified inside the Vision-Transformer backbone and standardized per channel; text uses a shared WordPiece tokenizer.
MLE (Deterministic Maximum-Likelihood Head). The MLE baseline corresponds to a standard deterministic Transformer trained by maximizing the likelihood (or equivalently minimizing cross-entropy loss) with a softmax output layer. Predictions are obtained from a single forward pass, and no explicit uncertainty modeling is performed beyond the softmax probabilities. This baseline serves as a reference point for evaluating the benefits of uncertainty-aware modeling in terms of calibration and robustness.
MLE+Temp (Temperature Scaling). Temperature scaling is a simple, single-parameter post-hoc calibration method applied to the trained MLE model (Guo et al. 2017). A scalar temperature is fit on the validation set by minimizing the negative log-likelihood of the temperature-scaled logits , and predictions at test time use the rescaled softmax softmax(). Since it only rescales confidences without changing the predicted class, MLE+Temp leaves accuracy unchanged while typically improving calibration, and provides a strong, essentially free reference for the calibration metrics. Because it is purely post-hoc, temperature scaling is orthogonal to and can be composed with any of the methods considered here, including ours.
C Datasets
We evaluate on seven publicly available classification benchmarks covering both image and text modalities, summarized in Table 3. Unless noted otherwise, we hold out a fixed validation split shared across all methods and seeds for model selection and temperature fitting.
D Model Configuration and Experimental Design
Overall design. Across all image and text benchmarks in Table 3, we keep the backbone, optimizer, training schedule, validation split, and evaluation metrics fixed within each dataset, changing only the attention or output-layer uncertainty mechanism. This controlled design ensures that differences among MLE, MLE+Temp, MCD, SNGP, SGPA, RFF-GPA, and RFF-CGP reflect the uncertainty mechanism rather than unrelated architectural or tuning choices.
Image classification setup. For Fashion-MNIST, CIFAR-10, SVHN, and CIFAR-10-C, we use a compact Vision-Transformer-style encoder with patch embeddings, learned positional embeddings, a learnable [CLS] token, pre-norm residual blocks, and a classification head on the [CLS] representation. Images are converted to tensors and standardized per channel using dataset-specific statistics; we do not use aggressive data augmentation so that calibration comparisons are not confounded by augmentation policy. Patch sizes and resulting sequence lengths follow Table 3.
Text classification setup. For 20 Newsgroups, Hyperpartisan, and SST-2, we use the same Transformer classification template with shared WordPiece tokenization, learned positional embeddings, a [CLS]-style pooled representation, and a linear classification head. Text sequences are truncated or padded to the maximum lengths reported in Table 3. As with the image experiments, all compared uncertainty mechanisms use the same dataset-specific backbone and training protocol. Unless otherwise stated, the text encoder uses the same model scale as the image encoder: 5 Transformer blocks, hidden size 128, MLP dimension 128, 4 attention heads, and dropout 0.1.
Shared model configuration. For every dataset, all compared methods use the same dataset-specific Transformer encoder and differ only in the uncertainty mechanism being evaluated. Thus, MLE, MLE+Temp, MCD, SNGP, SGPA/SCGP, RFF-GPA, and RFF-CGP are compared under matched depth, hidden size, number of heads, dropout, optimizer, validation split, and evaluation protocol for a given benchmark. For GP-based attention models, the corresponding image or text backbone is instantiated with the GP attention layer in every Transformer block. The sparse GP attention baselines (SGPA/SCGP) use the same backbone and classification head but replace random features with inducing-point GP attention. The deterministic MLE baseline uses the identical architecture with standard scaled dot-product attention (kernel_type = scale_dot), while SNGP keeps the attention mechanism deterministic and replaces the output head with a stochastic neural GP layer.
Across the GP-based models, we use one Monte Carlo sample per example during training, add a numerical jitter of in Cholesky/Woodbury solves, and anneal the KL regularization coefficient linearly from 0 to 1 over training via
where e is the epoch index and E is the total number of training epochs for that dataset. Randomness is controlled via a single seed parameter (-seed), and we train each model over five seeds to compute the reported error bars.
Training protocol. All in-distribution experiments use the Adam optimizer
with no weight decay, i.e., . The learning rate is recomputed at the start of each epoch using a piecewise-linear warmup and decay schedule: we set the initial learning rate to , the base learning rate to , and the minimum learning rate to . The warmup phase spans epochs, during which the learning rate increases linearly from to . This is followed by a linear decay phase of epochs down to . For image benchmarks, we use a global batch size of for training and for validation and test. For text benchmarks, each method uses the same tokenizer, maximum length, batch size, optimizer, and model-selection split within that dataset.
Image-model instantiation. The image encoder used for Fashion-MNIST, CIFAR-10, SVHN, and CIFAR-10-C is a compact Vision Transformer with transformer blocks, hidden size , MLP dimension , and attention heads per layer. We use pre-norm residual blocks and apply dropout with rate in the attention and MLP layers. Images are split into non-overlapping patches according to Table 3, prepended with a learnable [CLS] token, and combined with learned positional embeddings. For CIFAR-10 and SVHN, patches yield patch tokens; for Fashion-MNIST, patches yield patch tokens.
Random-feature and inducing-point settings. Across both image and text benchmarks, we use keys_len = 32 for our random-feature GP attention, which yields an effective random-feature dimension per head via cosine-sine pairs. RFF-GPA draws 32 frequencies and forms cosine/sine features, while RFF-CGP uses cosine-sine features from 32 shared frequencies. The inducing-point baselines (SGPA/SCGP) use 16 inducing points under the same backbone and training protocol.
CIFAR-10-C evaluation. CIFAR-10 consists of 50,000 training and 10,000 test images of size across 10 classes. From the 50,000 training images, we hold out 5,000 examples as a validation set and train on the remaining 45,000 examples. CIFAR-10-C is used only for inference-time distribution-shift evaluation: we reuse the corresponding CIFAR-10 checkpoints and evaluate on all 19 corruption types at 5 severity levels, reporting averages over corruptions and severities.
E Efficiency and Scalability Benchmark
This appendix details the efficiency and scalability protocol summarized in Sec. 4.2. All measurements probe asymptotic behavior and hardware efficiency independent of data loading, so we use synthetic inputs and benchmark a single attention block rather than an end-to-end model.
Benchmark unit. For each method we build one attention layer followed by a lightweight readout (LayerNorm → GELU → Linear to a scalar), and feed it a synthetic input tensor with . The attention layers are the exact same implementations used in our in-distribution experiments (Appendix B); only the surrounding backbone is replaced by the synthetic-input readout so that the measured cost reflects the attention mechanism itself. We sweep the sequence length and, for the inducing-point baselines, draw a fresh set of inducing keys per step.
Model configuration. To match the in-distribution setup (Appendix B), all methods use hidden size , attention heads, batch size , and float32. Random-feature methods use an effective feature count of per head (RFF-GPA: feature_mode=rff with keys_len = 16; RFF-CGP: ); inducing-point methods (SGPA, SCGP) use 16 inducing points; and we set the GP jitter to and dropout to 0.1. GP variants draw a single Monte-Carlo sample per forward pass at training time and 5 samples at inference time, while the deterministic MLE and SNGP heads use a single pass.
Timing and memory measurement. Each configuration is run with 10 untimed warmup steps followed by 60 timed steps; every step performs a full forward pass, backward pass, and AdamW update (learning rate ). We use torch.cuda.synchronize around each phase, report the mean per-step time (with forward/backward/optimizer components measured separately), compute throughput as divided by the mean step time, and read peak memory from torch.cuda.max_memory_allocated. For the runtime–calibration comparison in Sec. 4.2, runtime is reported as time per 1000 tokens at , and the corresponding ECE values are taken from the in-distribution CIFAR-10 evaluation in Sec. 4.1. All runs are repeated over five seeds.
Hardware and large-L handling. All timing and memory results are measured on a single RTX 4090-class GPU (24 GB). The inducing-point baselines materialize an kernel and therefore grow quadratically in memory: SCGP exhausts the 24 GB budget beyond , and SGPA beyond . For these methods we measure up to their largest feasible length and fit a power-law trend to the measured values (metric ), consistent with their known scaling; the random-feature methods (RFF-GPA, RFF-CGP) and the softmax heads (MLE, SNGP) are measured directly across the entire range.
F Out-of-Distribution Robustness Protocol
This appendix details the CIFAR-10-C evaluation summarized in Sec. 4.3 and reported in Table 2. The evaluation is inference-only: we reuse the exact CIFAR-10 checkpoints, backbone, and metrics from the in-distribution experiment (Sec. 4.1, Appendix B) and never re-train or fine-tune on corrupted data, so the results measure how the trained models generalize to a shifted input distribution rather than the effect of any additional training.
Corruption benchmark. We use the standard CIFAR-10-C benchmark (Hendrycks and Dietterich 2019), which perturbs the 10,000-image CIFAR-10 test set with 19 corruption types spanning four families—noise (Gaussian, shot, impulse, speckle), blur (defocus, glass, motion, zoom, Gaussian), weather (snow, frost, fog, brightness, spatter), and digital (contrast, elastic transform, pixelate, JPEG compression, saturate)—each applied at five severity levels . Every corruption/severity pair thus yields a 10,000-image corrupted test set with the original CIFAR-10 labels. We treat the clean CIFAR-10 test set as severity , taken directly from the in-distribution evaluation in Sec. 4.1. In total each model is evaluated on corrupted test sets plus the clean set.
Preprocessing. Corrupted images are provided as raw RGB arrays. We apply the same preprocessing as during training—conversion to tensors followed by per-channel standardization with the CIFAR-10 training mean and standard deviation —and apply no test-time augmentation. Using the training-time normalization statistics is essential: any mismatch would itself introduce a distribution shift and confound the corruption effect we intend to measure. Patchification into a length-256 token sequence is handled inside the ViT backbone, identically to the in-distribution setting.
Inference and metrics. Each checkpoint is evaluated with the same predictive protocol as in Sec. 4.1: GP-based variants (SGPA, RFF-CGP, RFF-GPA) average 10 Monte-Carlo samples per input, whereas the deterministic MLE and SNGP heads use a single forward pass. For every corruption/severity pair we compute accuracy (ACC), negative log-likelihood (NLL), and expected calibration error (ECE, 15 equal-width confidence bins) on the predicted class probabilities, using the identical metric implementations as the in-distribution experiment.
Aggregation. For each model and severity level we first average every metric over the 19 corruption types, yielding one per-severity value per run. We repeat the whole evaluation for the five training seeds and report, in Table 2, the mean over seeds together with a 95% confidence interval (computed as ). The clean column ( ) is the seed-averaged in-distribution CIFAR-10 result under the same aggregation. This corruption-averaged, per-severity summary follows standard practice for CIFAR-10-C and isolates the effect of increasing corruption strength from the idiosyncrasies of individual corruption types.