Contextual Flow Matching for High-quality Visual Content Generation

Bozhi Luan, Hong Chen, Jianmin Bao, Liang Hou, Yuan Gao, Xin Tao, Pengfei Wan, Wengang Zhou, Houqiang LiNeurIPS 2026

TL;DR

Imagine painting a landscape by trying to get every single millimeter of canvas right independently, without ever stepping back to sketch the horizon first. Standard Flow Matching image generators train in a similarly isolated, pixel-by-pixel way—leading to slow training and fuzzy textures. Contextual Flow Matching (CtxFM) fixes this by organizing training into a coarse-to-fine hierarchy across the network's depth, dramatically accelerating convergence and sharpening visual fidelity without adding external teacher models or changing how images are sampled.

What Problem Does This Paper Address?

Modern visual generative models increasingly rely on Flow Matching (FM)—a framework that teaches neural networks to transform random noise into crisp images by predicting a "velocity field" (essentially, the straight-line path each pixel or latent token needs to travel from noise to data).

The catch? Standard Flow Matching uses a pointwise loss function. It grades the network's prediction at coordinate $(i, j)$ completely independently of its neighbor at $(i+1, j)$. While Transformer backbones can theoretically figure out spatial relationships via self-attention, the training signal itself ignores the fact that natural images are densely correlated.

Because the model has to figure out broad layouts and tiny details simultaneously from isolated error signals, it suffers from spectral bias: it learns low-frequency global shapes at a different pace than high-frequency sharp textures. This desynchronization slows down training and leaves fine details prone to jitter and blurriness.

Methods

Instead of inventing a complicated multi-stage pipeline or relying on massive pre-trained vision models (like DINO or CLIP) to guide training, the authors reshape the loss function itself using simple linear spatial operators. CtxFM keeps the standard pointwise FM loss, and adds two complementary supervision tasks mapped to different depths of the Transformer:

Figure 1: The Contextual Flow Matching Framework. We generalize the standard flow matching objective by introducing two complementary operators to enforce spatial coherence. The Aggregate Operator Aw, applied to intermediate velocity predictions, stabilizes global structure, while the Differential Operator Dδ, applied to the output velocity, sharpens high-frequency textures. This coarse-to-fine formulation explicitly mitigates spectral bias during training.
  1. Aggregate Context Operator (Shallow Layers): Acting like a low-pass boxcar filter (average pooling over a small window, e.g., $2 \times 2$), this operator is applied to intermediate layers of the network. To avoid adding new parameters, hidden tokens from early blocks are passed directly through the model's existing final output head. Matching the local mean of the velocity field early on forces the network to lock in coherent global layouts right out of the gate.
  2. Differential Context Operator (Final Output): Acting like a high-pass finite-difference filter, this operator computes the difference between neighboring velocity vectors separated by a small stride (dilation offset $\delta = 2$). Applied at the final layer, it explicitly penalizes errors in local contrast and edges, forcing sharp boundaries and crisp textures that standard mean-squared error tends to smooth over.

Crucially, because both operators are only used to compute losses during training, inference and sampling remain 100% unchanged.

Datasets

All models and ablations are trained and evaluated on ImageNet-1K at a $256 \times 256$ resolution for class-conditional image generation. No new benchmarks are introduced; the authors test across both latent-space setups (using Stable Diffusion VAE and VAVAE) and raw pixel-space setups.

Key Insights and Ideas

  • Depth-placement matters—a lot: You can't just slap regional supervision anywhere. Applying the low-pass Aggregate operator at shallow layers (Layers 2 and 4) significantly boosts performance, whereas applying that exact same task deeper in the network (Layer 8) actually hurts performance compared to the baseline (degrading FID from 34.74 to 36.04). Early layers naturally build layout; late layers need freedom to resolve detail.
  • It’s not just "deep supervision": A fair question is whether early layers just benefit from any extra gradient signal. Control experiments replacing the Aggregate operator with standard pointwise intermediate supervision perform noticeably worse, proving that the spatial averaging itself is doing the heavy lifting.
  • Stride beats immediate neighbors for high frequencies: For the Differential operator, looking at adjacent latent tokens ($\delta = 1$) actually degrades performance compared to using Aggregate-only, likely due to sensitivity to local noise. Stepping out to a dilated offset of $\delta = 2$ hits the sweet spot for supervising meaningful texture gradients.
  • Self-contained structural guidance: Recent fast-converging models rely on aligning internal features with external pre-trained encoders. CtxFM shows that the target velocity field already contains rich structural supervision—you just have to filter it into the right frequency bands.
Figure 4: Frequency-wise velocity-error diagnostics. The left panel shows normalized velocity prediction error across radial-frequency bins, and the right panel shows relative error reduction over the baseline at epoch 80. “Ours” denotes CtxFM.

Key Results

CtxFM consistently speeds up training and boosts final image quality (measured via Fréchet Inception Distance, or FID, where lower is better):

  • Massive Convergence Speedup (SiT-XL/2): On ImageNet $256 \times 256$ (without classifier-free guidance), CtxFM drops 80-epoch FID from the published 17.20 reference down to 12.04. By 300 epochs, it hits 7.97 FID—beating the vanilla SiT baseline trained for 1,400 epochs (8.26 FID) in nearly a fifth of the training time. At 800 epochs, it reaches 7.57 FID.
  • Pushing State-of-the-Art Backbones (LightningDiT): In fast-training regimes, adding CtxFM to LightningDiT improves 64-epoch unguided FID from 5.14 to 4.67. At 800 epochs with classifier-free guidance, it achieves a crisp 1.24 FID (improving on LightningDiT's 1.35).
  • Works in Raw Pixel Space (JiT-B): Applied to a model predicting clean images directly in pixel space, CtxFM improves FID from 47.41 to 44.72 and boosts Inception Score from 30.92 to 34.31.
Figure 2: Qualitative Generation Results on ImageNet 256 × 256. Samples generated by our SiT + CtxFM model. By explicitly modeling contextual dependencies, CtxFM produces images with coherent global geometry and crisp local textures.

Limitations and Future Work

While the main text does not include a dedicated limitations section, a few practical constraints are apparent from the methodology and ablations:

  • Hyperparameter Sensitivity: CtxFM introduces several new knobs to tune—specifically which intermediate layers to supervise, pooling window sizes ($w$), dilation offsets ($\delta$), and loss weights ($\lambda_\text{A}, \lambda_\text{D}$). As the ablations show, misplacing the operator depth or choosing the wrong offset ($\delta=1$) can hurt performance, meaning optimal settings may need recalibration for new resolutions or architectures.
  • Future Directions: The authors frame CtxFM as evidence that spatial content and supervision depth are vital design dimensions for generative objectives, opening the door to exploring richer linear or frequency-aware operators across other visual modalities (like video or higher resolutions).

Summary updated

Abstract

Visual generation requires learning spatial relationships at multiple granularities, from coherent regional structure to local variation. Velocity predictions trained with standard Flow Matching contain errors at all spatial frequencies, but its pointwise objective does not explicitly organize these relationships into distinct learning tasks. We propose Contextual Flow Matching (CtxFM), which organizes the existing velocity target across spatial granularity and network depth. Aggregate supervision gives intermediate predictions a regional task, while Differential supervision guides local changes at the final output. Together with standard FM, they form a jointly trained coarse-to-fine hierarchy without an external teacher or changes to sampling. Our analysis explains how spatial operators shape the residual metric. On ImageNet 256 × 256, our CtxFM improves SiT-XL/2 from the published 17.20 FID reference to 12.04 at 80 epochs, and reaches 7.97 at 300 epochs versus 8.26 for the 1,400-epoch reference. Component studies examine task content and placement, and improvements extend to LightningDiT and pixel-space JiT. These results highlight the value of organizing an existing generative target into complementary spatial tasks across depth.
BibTeX
@inproceedings{luan2026contextual,
  author = {Bozhi Luan and Hong Chen and Jianmin Bao and Liang Hou and Yuan Gao and Xin Tao and Pengfei Wan and Wengang Zhou and Houqiang Li},
  title = {{Contextual Flow Matching for High-quality Visual Content Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=1AXA4TdiEG},
}
Figure