TL;DR
Adapting generative models to entirely new data distributions typically requires slow, computationally expensive fine-tuning or rigid conditioning variables. This paper introduces Function Projection for Flow Matching (FP-FM), a method that learns a set of basis functions spanning the velocity fields of training distributions. At inference time, FP-FM adapts to completely unseen target distributions instantly via a simple least-squares projection, delivering high-fidelity generation with zero additional training.
What Problem Does This Paper Address?
Conditional generative models (like diffusion or flow matching) excel when guided by text prompts or class labels. However, conditioning variables aren't always practical. For instance, if you want to generate images of a specific person or match a unique physical system, describing it in text is highly inefficient; providing a few example data points is much more intuitive.
This scenario is known as many-shot adaptation. The challenge is to take a small set of samples from an unseen target distribution and immediately generate new samples from that same distribution. Existing approaches either require test-time fine-tuning (which introduces massive latency) or struggle to generalize to out-of-distribution (OOD) data or novel mixtures of known classes. The authors set out to bridge this gap, aiming for an algorithm that is both highly expressive and computationally efficient at inference time.
Methods
FP-FM builds on the Flow Matching framework, which generates data by moving noise samples along a learned velocity field. The core innovation of FP-FM is treating these velocity fields as functions within a Hilbert space and applying Function Encoders to them.
During training, the algorithm learns a set of $k$ continuous basis functions ($g^i$) parameterized by neural networks. These bases span the space of velocity fields observed in the training distributions. At inference time, when presented with samples from a new target distribution, the model approximates the new velocity field by computing a linear combination of these learned bases. The coefficients ($c$) are calculated via a fast, closed-form least-squares projection.
The authors introduce three variants of FP-FM, offering a trade-off between expressivity and compute:
- Static FP-FM: Coefficients are fixed per distribution. It is the fastest but struggles with complex, unseen distributions due to the non-linear nature of fluid dynamics (the continuity equation).
- Temporal FP-FM: Coefficients depend on time ($t$), allowing the mixture of bases to shift as generation progresses.
- Dynamic FP-FM: Coefficients depend on both time ($t$) and the current state ($x$). To make this computationally tractable, the authors introduce a novel mathematical formulation (Theorem 1) that uses self-normalized importance sampling to estimate conditional expectations without needing unobserved trajectory data.
Datasets
The authors evaluated their approach across three distinct setups, testing for generalization across three splits: Training Distribution (TD), Unseen Distribution (UD) (mixtures of training classes), and Unseen Support (US) (entirely novel classes):
- 2D Arcs: A synthetic, low-dimensional dataset mapping uniform distributions over circle arcs. It serves as a clean baseline for visualizing how well the models capture complex geometric splits (like a spiral for the US split).
- MNIST: The classic handwritten digits dataset. The model trains on digits 0–8, evaluates mixtures for UD, and treats the digit 9 as the unseen support (US).
- ImageNet: A large-scale, high-dimensional image dataset. The authors trained a latent Vision Transformer (ViT) on 900 random classes and reserved the remaining 100 classes to evaluate out-of-distribution performance (US).
Key Insights and Ideas
- Velocity Fields as a Vector Space: The primary "aha!" moment is realizing that the velocity fields of different generative processes can be treated as vectors in a function space. This allows complex distribution matching to be reduced to linear algebra (least-squares projection).
- The Nonlinearity Fix: Because the relationship between a distribution and its velocity field is inherently non-linear, static coefficients fail to generalize to unseen mixtures. Making the coefficients time- and state-dependent acts as a powerful regularizer, allowing the basis functions to dynamically adapt mid-flight.
- Bypassing the Trajectory Bottleneck: In the dynamic variant, calculating coefficients requires knowing intermediate states that aren't directly observable from the target samples. Theorem 1 elegantly bypasses this by reframing the math as an expectation over the marginal distribution of the target data, making Monte Carlo estimation highly efficient.
Key Results
- Superior OOD Performance: Dynamic FP-FM consistently outperformed all baselines on unseen distributions. On the MNIST Unseen Support (digit 9) task, Dynamic FP-FM achieved an FID score of 11.25, vastly beating standard class-conditional models (31.56) and standard fine-tuning (29.24).
- High Precision: Many baseline models tend to over-approximate the data manifold, resulting in high recall but poor precision (generating unrealistic artifacts). FP-FM variants maintained exceptionally high precision, accurately capturing the boundaries of the target distributions.
- Drastic Speedups Over Fine-Tuning: While slightly slower than rigid conditional models due to the test-time projection step, FP-FM is orders of magnitude faster than fine-tuning. On MNIST, Dynamic FP-FM takes roughly 21 seconds to adapt and generate, compared to 209 seconds for standard fine-tuning.
Limitations and Future Work
- Sample Scarcity: As a "many-shot" method, FP-FM's performance degrades in extremely low-sample regimes. If only a handful of target data points are provided, the least-squares projection can struggle to accurately resolve the underlying distribution manifold.
- Inference Overhead: Computing coefficients at every single timestep (and per sample in the Dynamic variant) introduces a minor computational tax compared to standard conditional models that require a simple forward pass.
- Future Directions: The authors suggest exploring a continuous spectrum of controllable expressivity—for instance, enforcing Lipschitz constraints on the coefficients to fine-tune the balance between speed and generation quality.
Summary updated