Manuscript Offprint

arXiv:2610.13690

Transformer-based In-Context Score Operator Learning for Diffusion Models

Wuzhe Xu, Zhaiming Shen, Yulong Lu, Wenjing Liao, Rongjie Lai

A PREPRINT

Wuzhe Xu

South Dakota State University

wuzhe.xu@sdstate.edu

Zhaiming Shen

Georgia Institute of Technology

zshen49@gatech.edu

Wenjing Liao

Georgia Institute of Technology

wliao@gatech.edu

Yulong Lu

University of Minnesota

yulonglu@umn.edu

Rongjie Lai

Purdue University

lairj@purdue.edu

October 12, 2026

ABSTRACT

Diffusion models typically learn the generative dynamics of a single target distribution or a family of distributions indexed by conditioning variables fixed during training. This limits their ability to adapt to a previously unseen distribution from only a small set of examples. We introduce an in-context solution operator learning framework for diffusion models, in which each target distribution is treated as a task drawn from a meta-distribution and is specified at inference time by an empirical context set. Our method learns an in-context score operator that maps the context samples, a noisy query point, and the diffusion time to the task-dependent score, enabling reverse-diffusion sampling on unseen tasks without retraining or parameter updates. A key observation is that the task-dependent score admits a Gaussian-kernel conditional-mean representation. Its empirical Nadaraya–Watson approximation can be represented exactly by a model in our constructed transformer class, providing a principled foundation for the proposed query-dependent attention architecture. The operator is trained through amortized denoising score matching across task distributions. We establish generalization-error bounds that quantify the effects of the context size, the numbers of training tasks and within-task samples, model complexity, and intrinsic and ambient dimensions. Numerically, we evaluate the method on a range of scientific and visual datasets, including Navier-Stokes, ERA5 climate data [12], QuickDraw sketches [20], and Food-101 [3]. The results show that the proposed method performs well on relatively simple task families, while its performance degrades as task complexity increases, thereby illustrating both the promise and the limitations of in-context learning for diffusion models.

1 Introduction

Diffusion models have emerged as a powerful class of generative models, achieving strong empirical performance across a broad range of domains. They have been widely adopted in computer vision [42, 13, 43, 21, 2, 36], audio generation [23, 32, 18, 19], and reinforcement learning and control [35, 38, 56]. More recently, their applications have expanded to scientific and engineering problems, including data purification [34, 48, 49, 52], climate-data downscaling [44, 41], and partial differential equation (PDE) problems [17, 15, 51, 29]. Their success has been further enhanced by conditional generation techniques such as classifier guidance [8], classifier-free guidance [14], and conditioned latent diffusion [39], which provide substantial control over the generated samples.

Despite this progress, standard diffusion models typically learn the reverse generative dynamics associated with the distribution represented by a particular training dataset [42, 13, 43]. Conditional diffusion models extend this formulation to families of distributions indexed by predefined conditioning variables, such as class labels, classifier outputs, text embeddings, or other task-specific signals [8, 14, 39]. Although these models can generate from multi-

A PREPRINT

ple conditional distributions, the form and semantics of the conditioning mechanism are prescribed during training. Consequently, they are not generally designed to infer a previously unseen target distribution solely from a small, unordered set of contextual samples. Adapting to such a distribution may therefore require retraining, fine-tuning, or the construction of an additional conditioning representation. Recent few-shot and score-operator approaches have begun to relax this restriction [11, 27], but learning a general in-context score operator directly from empirical context sets remains underexplored.

Many applications, however, require generative models to operate over an entire family of target distributions. In scientific computing, for example, the relevant solution or data distribution may vary with the governing equation, physical parameters, forcing terms, initial or boundary conditions, or available observations. This family-level structure is central to operator-learning methods such as DeepONet and the Fourier neural operator, which learn mappings between problem specifications and their corresponding solutions [28, 26, 24]. Training an independent diffusion model for every possible configuration is computationally prohibitive and fails to exploit the structure shared across related problems. This motivates a solution-operator perspective for diffusion models: rather than learning the score function associated with a single prescribed target distribution, the objective is to learn an operator that maps information specifying a target distribution to its corresponding time-dependent score function [27]. Such an operator should generalize across a family of distributions and, ideally, adapt to previously unseen members of that family without retraining or parameter updates.

In this work, we introduce an in-context solution operator learning framework for diffusion models. Each target distribution, referred to as a task, is drawn from a meta-distribution over probability measures. More precisely, we learn an in-context score operator that maps the empirical context distribution, together with a noisy query point and the diffusion time, to the task-dependent score. This formulation casts task adaptation as an operator-evaluation problem: the context set identifies the target distribution, while the shared operator captures common structure across the task family. It thus extends diffusion modeling from learning a score function for a fixed target distribution to learning a reusable score operator over a family of distributions. The solution operator is trained through amortized denoising score matching across task distributions, allowing knowledge to be shared across the entire task family. Once trained, it can perform reverse diffusion for a previously unseen task directly from its prompt samples, without retraining, fine-tuning, or task-specific network parameter updates. This perspective is also closely related to recent work on in-context operator learning over probability measures [7].

Our method operates directly on the empirical context set and constructs score estimates through query-dependent interactions among the context samples, the noisy query point, and the diffusion time. A key observation is that the task-dependent score can be expressed through a Gaussian-kernel conditional-mean representation. Replacing the population conditional mean with its empirical counterpart yields a Nadaraya–Watson estimator based on the context samples. We show that this empirical estimator can be represented exactly by a model in our constructed transformer class. This connection provides a principled motivation for the proposed transformer-based in-context score operator, rather than treating the transformer architecture as an ad hoc design choice.

Theoretically, We further establish generalization-error bounds for the learned score operator in Section 4. This bounds quantify the dependence on the context size n, the number of training tasks K, the number of episodes per task J, the number of diffusion samples per episode NTN_T, and the intrinsic and ambient dimensions d and D. The finite-context error decays as n−2/(d+6)n^{-2/(d+6)}, with the intrinsic dimension governing the exponent and the ambient dimension entering only through polynomial and logarithmic factors. This distinction indicates that in-context score estimation is governed primarily by the intrinsic geometry of the task distributions, exhibiting a curse of intrinsic rather than ambient dimensionality. The statistical error contains terms of order K−1/2K^{-1/2}, (KJ)−1/2(KJ)^{-1/2}, and (KJNT)−1/2(KJN_T)^{-1/2}, separating the effects of the numbers of tasks, episodes, and diffusion samples. In particular, the task-level persistent K−1/2K^{-1/2} term is unaffected by J and NTN_T. Thus, within the present upper-bound analysis, increasing within-task sampling alone cannot reduce this contribution, highlighting the number and diversity of training tasks as fundamental to generalization..

We summarize our main contributions as follows:

• We formulate in-context learning for diffusion models at the level of task distributions. Each task is modeled as a probability distribution drawn from a meta-distribution, and a previously unseen task is specified at inference time by a small context set represented as an empirical measure.

• We show that the task-dependent score can be expressed in terms of a Gaussian-kernel conditional mean. We further prove that its empirical Nadaraya–Watson approximation, and hence the corresponding empirical score estimator, can be represented exactly by a model in our constructed transformer class. This connection provides a principled foundation for the proposed transformer-based in-context score operator. Trained through amortized denoising score matching across task distributions, the operator enables reverse-diffusion sampling on unseen tasks without retraining, fine-tuning, or task-specific parameter updates.

A PREPRINT

• We provide a theoretical analysis of the proposed neural operator and establish a generalization bound under suitable assumptions. The bound separates the contributions of finite context, finite meta-training data, and model complexity, while making explicit the dependence of the in-distribution generalization error on the context size, the numbers of training tasks and samples, and the intrinsic and ambient dimensions of the problem.

• We evaluate the proposed method on diverse scientific and visual datasets, including Navier–Stokes solution fields, ERA5 climate data, QuickDraw sketches, and Food-101 images. The results demonstrate strong performance in low-intrinsic-dimension regimes and reveal a gradual degradation as task complexity increases. For low-intrinsic-dimension problems such as Navier–Stokes, the method also exhibits modest generalization to out-of-distribution tasks.

The code is available at https://github.com/woodssss/In-context-learning-for-Diffusion-Models. The repository also provides a Lean 4 formalization of Theorem 1.

References (54)