Safe Few-Step Generation via Velocity Editing

Yujin Choi, Jaehong YoonNeurIPS 2026

TL;DR

Modern text-to-image generators like FLUX are getting blazingly fast—producing crisp images in just four to eight steps—but that speed breaks existing safety guardrails that need dozens of steps to nudge an image away from harmful content. Enter VESFlow, a training-free technique that mathematically reshapes the model's underlying "velocity field" on the fly, steering generation toward safe outputs in just a few steps without mangling harmless prompts.

What Problem Does This Paper Address?

Traditional diffusion models generate images by chipping away at random noise over 50 or more steps. Newer flow matching models (like Stable Diffusion 3 and FLUX) instead learn a direct, near-linear velocity field—think of it as a river current carrying a boat directly from pure noise to a finished image. Distilled variants like MeanFlow learn the average velocity between points, cutting the journey down to just four steps.

Keeping these ultra-fast models safe without retraining them from scratch is surprisingly tricky. Existing training-free guardrails generally rely on one of two strategies, and both hit a wall here:

  1. Trajectory steering: Giving the image a tiny "repulsive nudge" away from unsafe territory at each generation step. With 50 steps, gentle nudges accumulate nicely. With 4 steps, gentle nudges fail to turn the boat in time, while shoving harder knocks the boat off the river entirely, ruining image quality.
  2. Prompt editing: Surgically removing toxic words from the text representation. Older models used CLIP text encoders where concepts lived in neat, isolated tokens. Modern models use LLM-style encoders (like T5) where meaning is woven across the entire sentence, making surgical word removal ineffective.

Methods

Instead of nudging the boat or rewriting the map, the authors reshape the river itself. They propose VESFlow (Velocity Editing for Safe Flow matching).

Because flow matching models explicitly predict a velocity vector pointing toward the expected final image, the authors use Bayes' rule to ask: What would this velocity vector look like if we conditioned it on the final image landing strictly in a "safe" region?

Here is how it works at each step:

  • Lookahead: Using the model's current velocity, VESFlow estimates what the final clean image currently looks like.
  • Safety Check: It passes this estimated image through a lightweight, pre-trained safety classifier (e.g., an NSFW detector) to get the probability of it being unsafe, along with the gradient pointing away from the unsafe features.
  • Velocity Update: It adds a corrective term directly to the velocity vector (or average velocity in MeanFlow), scaled by a time-dependent factor $t / (1 - t)$ inherited naturally from flow-matching math. To keep this fraction from blowing up to infinity at the very start ($t=1$), they cap the time variable at a ceiling like $t_{\max} = 0.99$.
Figure 2: Sampling trajectories un- der the safe-conditional velocity field across different sampling steps. Blue and red denote safe and unsafe generated samples x0, respectively.

Finally, calculating classifier gradients at every step costs extra compute. To skip this when it isn't needed, the authors add risk score-based filtering: before generation begins, they check the cosine similarity between the prompt's CLIP embedding and a list of known unsafe words. If the risk score is below a conservative threshold, VESFlow steps aside completely.

Datasets

No new benchmarks were introduced; the authors used standard datasets to test safety and quality:

  • Safety Evaluation: Ring-A-Bell (nudity and violence adversarial prompts) and MMA-Diffusion (nudity prompts).
  • Benign Image Quality: MS-COCO (1,000 everyday prompts to ensure normal images still look great).
  • Verifier Training: I2P (Inappropriate Image Prompts) was used to train a lightweight MLP classifier for detecting violence.

Key Insights and Ideas

  • Built-in "Early Intervention" Scheduling: Prior research showed that safety interventions work best early in generation when big-picture layouts are formed. Remarkably, VESFlow's Bayesian math produces the $t/(1-t)$ term organically—applying strong corrections near pure noise ($t \approx 1$) and naturally vanishing to zero as fine details settle ($t \to 0$).
  • Benign Prompts Stay Untouched Automatically: If a prompt is harmless (like "a smiling girl"), the safety classifier outputs a near-zero probability and a vanishing gradient. Consequently, VESFlow leaves safe images virtually identical even if you crank the guidance strength way up! The pre-filtering step isn't needed to protect image quality—it's purely a free speedup.

Increasing guidance strength leaves a benign prompt virtually untouched while progressively adding clothing to an unsafe prompt. (Note: See Figure 3 in the paper, illustrated below) Effect of guidance scale on safe vs. toxic prompts.

Figure 3: Effect of guidance scale on safe and toxic prompts. For safe prompts, the output remains nearly unchanged as the guidance scale increases. For toxic prompts, stronger guidance progressively suppresses unsafe content, with the usual trade-off between safety and fidelity.
  • Scorer Agnosticism: Whether guided by a LAION CLIP-based detector or NudeNet, independent evaluations by GPT-4o and LLaVA-1.5 show VESFlow achieves nearly identical safety gains, proving the framework isn't brittle or overfitted to one specific classifier.

Key Results

Tested on 8-step FLUX.1-lite and 4-step MeanFlow, VESFlow substantially outperformed both inference-time baselines and weight-fine-tuning methods:

  • 4-Step MeanFlow (Nudity): VESFlow slashed the Attack Success Rate (ASR) from 70.9% down to 15.2% on Ring-A-Bell, and from 41.7% down to 7.5% on MMA-Diffusion.
  • 8-Step FLUX (Nudity): Reduced ASR from 64.6% to 26.6% on Ring-A-Bell, and from 66.5% to 5.2% on MMA-Diffusion.
  • Zero Quality Tax: On MS-COCO, FID and CLIP alignment scores remained virtually identical to the unguided baselines (e.g., 59.98 vs. 59.95 FID on MeanFlow; identical 0.257 CLIP score).
  • Runtime: Without filtering, gradient calculations roughly double generation time on FLUX (2.16s vs. 0.95s per image). With risk-score filtering active, benign prompts run in 0.96s—virtually zero overhead.
Qualitative comparisons showing VESFlow removing nudity, weapons, and self-harm across FLUX and MeanFlow while preserving scene context.

Limitations and Future Work

While the authors do not include a formal "Limitations and Future Work" section, they candidly note several practical trade-offs in their experiments:

  • Worst-Case Compute Overhead: Whenever an unsafe prompt triggers velocity editing, backpropagating through the safety classifier roughly doubles the per-image sampling time compared to unguided generation.
  • Boundary Sensitivity: The $t/(1-t)$ scheduler diverges at $t=1$. Simply skipping the first step severely degrades safety in 4-step models, requiring careful tuning of the $t_{\max}$ cap—pushing $t_{\max}$ too high paired with high guidance scales begins to degrade image fidelity.
  • Category Sensitivity: Reusing hyperparameters tuned for nudity on violence prompts resulted in somewhat higher residual attack success rates (~43%–50%, down from ~81%–82%), indicating different concepts may benefit from tailored classifier tuning.

Summary updated

Abstract

Flow matching has recently emerged as a strong paradigm for state-of-the-art text-to-image (T2I) generation, enabling high-quality generation with a small number of sampling steps. As these models are increasingly integrated into real-world applications, ensuring safety has become a critical requirement. However, adapting safety and concept removal methods to this new generation framework remains an open challenge. Specifically, prior methods largely rely on iterative trajectory steering across a number of denoising steps or on CLIP-centric prompt embedding manipulation. These design assumptions pose fundamental bottlenecks for safety in flow matching-based T2I generation, where limited sampling steps constrain iterative correction and modern context-aware text encoders diminish the effectiveness of embedding-level interventions. In this paper, we propose VESFlow, a training-free safety method tailored to flow matching, even with extremely few sampling steps. Leveraging the fact that flow matching models learn the marginal velocity (or average velocity in MeanFlow), we directly edit the velocity field via a Bayesian decomposition of the safe-conditional posterior. VESFlow steers the trajectory toward safe outputs while leaving the conditioning prompt unchanged. Building on the observation that VESFlow leaves outputs unchanged under benign prompts, we further introduce a risk score-based filtering that bypasses velocity editing to reduce computational cost while preserving benign prompt generation. Experimental results show that VESFlow removes the target concept, reducing the attack success rate by NudeNet to 15.2\% on Ring-A-Bell and 7.5\% on MMA-Diffusion on the 4-step MeanFlow model, while preserving fidelity on benign prompts.
BibTeX
@inproceedings{choi2026safe,
  author = {Yujin Choi and Jaehong Yoon},
  title = {{Safe Few-Step Generation via Velocity Editing}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=tJYkz9rQMx},
}
Figure