What Would Bayes Do
for Next-Gen Neural Network Design?

Images by me (2019) & by Nano Banana 2 (gemini-3.1-flash-image, 2026)

pre-ChatGPT (- 2022)

AGI (when?)

What’s the Future of Bayesian Deep Learning?

1

Build network architectures

with Bayesian principles

Build Bayesian procedures

on frontier models

Many of you have contributed wonderful works in these developments ☺

\[(t_{2i-1},t_{2i})=(\mathbf{x}_i,\mathbf{y}_i)\]
\[(t_{2n+1},t_{2n+2})=(\mathbf{x}^{*},\mathbf{y}^{*})\]
\[{\color[RGB]{32,76,154}p(\mathbf{y}_i\mid\mathbf{x}_i,\mathbf{x}_{<i},\mathbf{y}_{<i})=p_{\phi}^{2i}(t_{2i}\mid t_{1:2i-1})}\]
\[{\color[RGB]{180,86,21}p(\mathbf{y}^{*}\mid\mathbf{x}^{*},\mathcal{D})=p_{\phi}^{2n+2}(t_{2n+2}\mid t_{1:2n+1})}\]

In-context learning & predictive resampling

Agentic AI: Bayesian pipeline

Bayesian NNs: weight/function-space posterior inference

NN layer design with Bayesian principles

MLSys work needed

(mostly absent now!)

”Modernization” via ”Bayesian LoRA” (?)

What Can Bayes Say about NN Arch Design?

Entrée: Uncertainty quantification

Main: Memory updates & maintenance

2

Naoki Kiyohara

Harrison Bo Hua Zhu

Riccardo El Hassanin

Wenlong Chen

Work led by my amazing current/former PhD students

Idea 1: Leverage probabilistic models to improve the “reliability” of attention-based Transformers (e.g., ”reliable uncertainty”)

Sparse Gaussian Process Attention

- a Deep GP tailored to Transformer architectures

Chen and Li, ICLR 2023,

Calibrating Transformers via Sparse Gaussian Processes.

3

Wenlong Chen

Attention in Transformers

Vaswani et al. Attention is all you need. NeurIPS 2017

Tsai et al. Transformer dissection: A unified understanding for transformer’s attention via the lens of kernel. EMNLP 2019

Single head attention

Attention matrix

Replace attention matrix with kernel matrix:

\[Attention(\mathbf{q},\mathbf{k},\mathbf{v})={\color[rgb]{0,0,1}activation(\mathbf{q}\mathbf{k}^{\top})}\mathbf{v}\]
\[KernelAttention(\mathbf{q},\mathbf{k},\mathbf{v})={\color[rgb]{0,0,1}\mathbf{K}_{\mathbf{qk}}}\mathbf{v}\]

4

Kernel Attention as the Mean of an SVGP

Kernel Attention:

\[\mathbf{F}={\color[rgb]{0,0,1}\mathbf{K}_{\mathbf{qk}}}{\color[rgb]{1,0,0}\mathbf{v}}\]

Recall posterior mean of SVGP:

Equivalent by identifying:

q (queries) = x (queried input locations)

k (keys) = z (inducing locations)

v (values) = γ (variational parameters)

\[[{\color[rgb]{0,0,1}\mathbf{K}_{\mathbf{qk}}}]_{ij}\]

similarity between and

\[\mathbf{q}_i\]
\[\mathbf{k}_j\]

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

5

γ=Kzz−1mz

μ=Kxzγ

mz is a free-parameter, Kzz is invertible

=> Can optimize γ as a free-parameter

Adding Covariance Function to Transformer

\[\boldsymbol{\Sigma}^{(post)}=\mathbf{K}_{\mathbf{qq}}+\mathbf{K}_{\mathbf{qk}}(\mathbf{K}_{\mathbf{kk}}^{-1}{\color[rgb]{1,0,0}\mathbf{S}}\mathbf{K}_{\mathbf{kk}}^{-1}-\mathbf{K}_{\mathbf{kk}}^{-1})\mathbf{K}_{\mathbf{kq}}\]
\[\mathbf{m}^{(post)}={\color[rgb]{0,0,1}\mathbf{K}_{\mathbf{qk}}}{\color[rgb]{1,0,0}\mathbf{v}}\]

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

6

Amortized Inference for Self-Attention

 

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

7

 

Computation Reduction for Self-Attention

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

Cheng and Boots. Variational Inference for Gaussian Process Models with Linear Complexity. NIPS 2017

8

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

9

OOD Detection

\[\widehat{Y}=\mathbb{1}\{H[\hat{p}]>\tau\}\]

ViTs trained on CIFAR10

Reflections on SGPA

Kernel attention = mean of SVGP

So can think about how GP methods inspire memory design

SGPA = Deep Sparse GP modernised with Transformer arch.

So still fall in the traditional BNN category

Evaluations on calibration & OOD detection

Frequentist methods are computationally simpler and competitive here

Chen and Li. Calibrating Transformers via Sparse Gaussian Processes. ICLR 2023

10

Idea 2:

Exploit the kernel interpretation of attention;

Introduce interdomain methods for ”memory maintenance”

Interdomain Attention

– a hybrid attention that implicitly approximate attention with recurrent memory

Kiyohara et al., In submission,

Interdomain Attention:

Beyond Token-Level Key-Value Memory.

11

Naoki Kiyohara

Harrison Bo Hua Zhu

Riccardo El Hassanin

Wenlong Chen

KV Cache 101

12

1. Prefill (parallel compute)

Use the last output token xN as input

Read from KV cache for {kn,vn}n=1N−1

Compute and write kN, vN in KV cache, and compute with query qi, i=N:

The output oi propagates and leads to generated token xN+1

\[o_i=\frac{\sum_{n=1}^{N}\mathcal{K}(q_i,k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\mathcal{K}(q_i,k_{n^{\prime}})}\]

2. Decode (sequential compute)

LLM “inference” compute in two stages:

User provides prompt token sequence {xn}n=1N

Compute in parallel {qn, kn,vn}n=1N

Cache {kn,vn}n=1N as memory (KV cache)

Growing memory size…

A New Type of Memory

13

Consider approximating kernel as dot-product of features

\[\mathcal{K}(q,k)\approx\xi(q)^{\top}\xi(k)\]
\[o_i=\frac{\sum_{n=1}^{N}\mathcal{K}(q_i,k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\mathcal{K}(q_i,k_{n^{\prime}})}\]

The ith output of the attention procedure (with query qi):

\[o_i\approx\hat{o}_i=\frac{\sum_{n=1}^{N}\xi(q_i)^{\top}\xi(k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\xi(q_i)^{\top}\xi(k_{n^{\prime}})}\]

⇒

Idea in a nutshell:

Step 1: Construct memory for ξ(kn), vn

Step 2: “reconstruct” ξ(kn) from the memory

Step 3: Plug-in the “reconstructions” to perform attention

Steps 2 & 3 can be done together!

(no explicit reconstruction & attention)

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

A New Type of Memory

14

Key idea: function projection as memory

\[o_i\approx\hat{o}_i=\frac{\sum_{n=1}^{N}\xi(q_i)^{\top}\xi(k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\xi(q_i)^{\top}\xi(k_{n^{\prime}})}\]

Step 1.1. Treat the keys and values as functions of time

k(tn):=kn

v(tn):=vn

Step 1.2. Project key features and values onto a set of basis functions {ϕm(tN)}m=1M:

\[{\color[RGB]{76,134,37}u_m^{(t_N)}=\int\xi(k(t))\,\phi_m^{(t_N)}(t)\,dt}\]
\[{\color[RGB]{32,76,154}\gamma_m^{(t_N)}=\int v(t)\,\phi_m^{(t_N)}(t)\,dt}\]

Step 2 + 3 (virtual): Reconstruct the key features

+ perform attention (assume we have the values vn)

\[{\color[RGB]{76,134,37}\xi(k_n)\approx\sum_m u_m\,\phi_m(t_n)}\]

∑n=1Nξ(qi)⊤ξ(kn)vn≈ξ(qi)⊤∑n=1N∑mumϕm(tn)vn=ξ(qi)⊤∑mum∑nNϕm(tn)vn≈ξ(qi)⊤∑mumγm

discretized sum (up to const.)

reconstruct

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

A New Type of Memory

15

Key idea: function projection as memory

\[o_i\approx\hat{o}_i=\frac{\sum_{n=1}^{N}\xi(q_i)^{\top}\xi(k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\xi(q_i)^{\top}\xi(k_{n^{\prime}})}\]

Step 1.1. Treat the keys and values as functions of time

k(tn):=kn

v(tn):=vn

Step 1.2. Project key features and values onto a set of basis functions {ϕm(tN)}m=1M:

\[{\color[RGB]{76,134,37}u_m^{(t_N)}=\int\xi(k(t))\,\phi_m^{(t_N)}(t)\,dt}\]
\[{\color[RGB]{32,76,154}\gamma_m^{(t_N)}=\int v(t)\,\phi_m^{(t_N)}(t)\,dt}\]
\[{\color[RGB]{180,86,21}\eta_m^{(t_N)}=\int\phi_m^{(t_N)}(t)\,dt}\]

Step 2 + 3 (virtual): Reconstruct the key features

+ perform attention (denominator, optional)

\[{\color[RGB]{76,134,37}\xi(k_n)\approx\sum_m u_m\,\phi_m(t_n)}\]

∑n=1Nξ(qi)⊤ξ(kn)≈ξ(qi)⊤∑n=1N∑mumϕm(tn)=ξ(qi)⊤∑mum∑nNϕm(tn)≈ξ(qi)⊤∑mumηm

discretized sum (up to const.)

reconstruct

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

A New Type of Memory

16

Key idea: function projection as memory

\[o_i\approx\hat{o}_i=\frac{\sum_{n=1}^{N}\xi(q_i)^{\top}\xi(k_n)\,v_n}{\sum_{n^{\prime}=1}^{N}\xi(q_i)^{\top}\xi(k_{n^{\prime}})}\]

Step 1.1. Treat the keys and values as functions of time

k(tn):=kn

v(tn):=vn

Step 1.2. Project key features and values onto a set of basis functions {ϕm(tN)}m=1M:

\[{\color[RGB]{76,134,37}u_m^{(t_N)}=\int\xi(k(t))\,\phi_m^{(t_N)}(t)\,dt}\]
\[{\color[RGB]{32,76,154}\gamma_m^{(t_N)}=\int v(t)\,\phi_m^{(t_N)}(t)\,dt}\]

Step 2 + 3: Implement reconstruction + approximate attention in one go!

ôi≈õi=∑m=1M(ξ(qi)⊤um)γm∑m=1M(ξ(qi)⊤um)ηm

\[{\color[RGB]{180,86,21}\eta_m^{(t_N)}=\int\phi_m^{(t_N)}(t)\,dt}\]

Õ=(FqU⊤Γ) ⊘(FqU⊤η)

\[F_q=[\xi(q_1),\ldots,\xi(q_{N_q})]^{\top}\]
\[{\color[RGB]{76,134,37}U=[u_1,\ldots,u_M]^{\top}}\]
\[{\color[RGB]{49,110,165}\Gamma=[\gamma_1,\ldots,\gamma_M]^{\top}}\]
\[{\color[RGB]{180,86,21}\eta=[\eta_1,\ldots,\eta_M]^{\top}}\]

query features

“KV” memory

Helper terms

⇒

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Connection to Interdomain Inducing Points in SVGPs

Lázaro-Gredilla and Figueiras-Vidal. Inter-domain Gaussian Processes for Sparse Inference using Inducing Features. NIPS 2009

17

How to construct this function projection in an online manner?

γ=KZZ−1mz

SVGP approximate posterior mean:

μ=KXZγ

mz is a free-parameter, KZZ is invertible

=> Can optimize γ as a free-parameter

Interdomain inducing points: projections on orthogonal basis functions:

(KXZ)nm:=Cov(f(xn), ∫f(x)ϕm(x)dx)=∫K(xn,x)ϕm(x)dx

≈⟨ξ(xn), ∫ξ(x)ϕm(x)dx⟩

(RFF approx.)

μn=KxnZγ≈ξ(xn)⊤∑m=1M∫ξ(x)ϕm(x)dxγm

≈ξ(xn)⊤∑m=1M∫∑m′=1Mum′ϕm′(x)ϕm(x)dxγm

Plug-in to the mean computation, with γ:=[γ1,…, γm]⊤:

=ξ(xn)⊤∑m,m′Mum′δ(m′=m)γm

=ξ(xn)⊤∑m=1Mumγm=ξ(xn)⊤Uγ

(reconstruct ξ(x) )

(∫ϕm′(x)ϕm(x)dx=δ(m′=m))

(rewrite matrix-vector product)

HiPPO - An Online Representation of Sequential Data

Legendre polynomial

“Memorising” a function via projection to finite basis:

Given f(x),  x∈[−1,1],

u – coefficients of f projected to span{Pn(x)}n=0N−1

Pn(x),x∈[−1,1]
f(x)≈∑n=0N−1unPn(x),un=∫−11f(x)Pn(x)dx

Can be viewed as a finite-dim memory for a function (infinite-dim object)

18

Fig: wikipedia

Gu et al. Recurrent Memory with Optimal Polynomial Projections. NeurIPS 2020

un:=∫−11f(x)Pn(x)dx

HiPPO - An Online Representation of Sequential Data

“Memorising” a function via projection to finite basis:

Given f(x),  x∈[0,t],

un(t) – coefficients of f projected to span{Pn(t)(x)}n=0N−1

Rescaled Legendre polynomial

0

t

w(t)(x)=1t1x∈[0,1]

1/t

0

f(x)≈∑n=0N−1un(t)Pn(t)(x),un(t)=∫0tf(x)Pn(t)(x)dx

Can be viewed as a finite-dim memory for a function (infinite-dim object)

Memory “evolves” when t increases!

19

Gu et al. Recurrent Memory with Optimal Polynomial Projections. NeurIPS 2020

un≔∫f(x)Pn(t)(x)w(t)(x)dx

Pn(t)(x):=Pn((2x −t)/t)

x

f(x)

t

0

1t

ω(t)(x)

x

gn(t)(x)

t+Δt

ω(t+Δt)(x)

gn(t+Δt)(x)

un(t)=∫−∞∞f(x)gn(t)(x)ω(t)(x)dx

un: n-th coefficient

f(x): Target function for x∈[0, +∞)

gn(t)(x): Normalised & scaled n-th basis

ω(t)(x): Normalised measure (mask)

HiPPO - An Online Representation of Sequential Data

20

20

Gu et al. Recurrent Memory with Optimal Polynomial Projections. NeurIPS 2020

gn(t)(x)=Pn(2xt−1)

The evolution of u(t)=[u0(t),…,uN−1(t)] over time t follows linear ODE:

ddtu(t)=A(t)u(t)+B(t)f(t)

We can obtain the coefficients u(t)
as a summary of the function up to time t in an online manner.

Input sequence to memorize

Specific matrix and vector corresponding to function basis and measure

Gu et al. Recurrent Memory with Optimal Polynomial Projections. NeurIPS 2020

HiPPO - An Online Representation of Sequential Data

21

Gu et al. Recurrent Memory with Optimal Polynomial Projections. NeurIPS 2020

HiPPO - An Online Representation of Sequential Data

22

Interlude: Recurrent Memory for GPs!

23

Chen et al. Recurrent Memory for Online Interdomain Gaussian Processes. NeurIPS 2025

Interlude: Recurrent Memory for GPs!

24

Chen et al. Recurrent Memory for Online Interdomain Gaussian Processes. NeurIPS 2025

Bui et al. Streaming Sparse Gaussian Process Approximations. NIPS 2017

KV cache ⇔ growing number of data-space inducing points

Recurrent memory ⇔ interdomain inducing points (fixed state dim. = fixed #basis)

Interdomain Attention

25

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Interdomain Attention

26

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Yang et al. Gated Linear Attention Transformers with Hardware-Efficient Training. ICML 2024

Gu et al. On the Parameterization and Initialization of Diagonal State Space Models. NeurIPS 2022

Practical Implementation (with deep learning magic 🪄)

1. Kernel feature: ξ(⋅)=L2Norm(SiLU(conv1D(⋅))) + RoPE

Tried RFF with (learnable) frequencies, didn’t work well

2. Apply RMSNorm to ξ(kt) and vt before entering the recurrent memory

Mainly to stabilise the recurrent memory updates

vt in SVGPs are “free parameters” anyway

3. Complex S4D as the recurrent memory module

Several gating and selective update mechanism tried

4. Optional: construct q from input x with non-linear projection

Combined with (2): the kernel now becomes asymmetric

Extensive amount of engineering for GPU kernel implementations!

(our implementation is still sub-optimal even with chunking)

IA Empirical Performances: Text

27

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Perplexity = exp(avg. NLL)

IA Empirical Performances: Text

28

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Downstream tasks (reasoning) performance

IA Empirical Performances: Genomics

29

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Downstream tasks performance

IA Empirical Performances: Ablations

30

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

Query-conditioned read-out

is the main improvement factor

Some deep learning magic 🪄

also helps

Reflections on Interdomain Attention

Recurrent memory ≈ interdomain inducing points

So can think about how GP methods inspire memory design

Think about sequence layers as online learners

Now can think about network layer design in a “statistical modelling” way!

Bayes can already say quite something for NN design:

“knowledge adaptation” ≈ online learning + memory management

31

Engineering & MLSys work may feel less “pleasant”:

We had to throw away some “elegant ideas”

But what if: hardware info should enter in your “prior beliefs” of models?

Kiyohara et al. Interdomain Attention: Beyond Token-Level Key-Value Memory. In submission

What Would Bayes Do
for Next-Gen Neural Network Design?

Uncertainty quantification?

Memory updates & maintenance?

Maximally “squeezing” out the “value” of each token?

How to build a hierarchy of features?

Your thoughts?

Thank you!

Innovations are from my great students, errors are mine :)

Questions? Ask now, or contact

yingzhen.li@imperial.ac.uk

yingzhen.li@ntu.edu.sg

PhD & Postdoc positions available on Bayesian deep learning

Naoki Kiyohara

Harrison Bo Hua Zhu

Riccardo El Hassanin

Wenlong Chen