V-GRPO: Online Reinforcement Learning for Denoising Generative Models Is Easier than You Think

1. Motivation(研究动机)

  • 现有方法的问题:policy-gradient online RL 直接用于 diffusion / flow matching 模型时,精确 通常不可得。主流绕法是把采样轨迹建成 MDP,逐步优化 reverse transition kernel;这虽然稳定,但有三个具体瓶颈:收敛慢、被绑定到一阶随机 SDE 采样、优化目标与 rollout transition kernel 强耦合,导致 MixGRPO / BranchGRPO 等方法不得不用更复杂的采样树、滑窗或 ODE-SDE 混合设计来补效率。
  • 本文要解决的问题: 重新启用与 diffusion ELBO / pretraining loss 相连的 likelihood surrogate,把它放进 GRPO 里直接优化最终样本的“原子动作”概率,同时修复先前 DDPO / FPO 式 surrogate 在视觉生成上不稳定、欠收敛的问题。
  • 为什么重要: 如果 ELBO surrogate 可稳定工作,就能把 pretraining objective、高阶 ODE rollout 与 online RL 对齐到同一框架里,避免 MDP 化带来的 per-step policy coupling;在多 reward 图像对齐任务上,这意味着更少 function evaluations、更少梯度步、更简单的实现,同时保持或超过强基线质量。

2. Idea(核心思想)

  • 核心洞察: ELBO surrogate 本身不是失败根因,失败主要来自 surrogate 的相对量级方差过大:不同时间步、不同噪声样本造成的 loss scale 变化会淹没 group-relative reward signal。只要让同组样本在可比较的 timestep-noise basis 上估计 likelihood,并控制更新步幅,ELBO surrogate 可以比 MDP-based GRPO 更简单、更快。
  • 关键创新: V-GRPO 用 negative weighted pretraining loss 近似 ,再用 GRPO 的 importance ratio 做 online update;同时引入三类 surrogate variance reduction:group-shared timestep-noise pairsstratified timestep samplingadaptive loss weighting,并按场景使用 importance ratio clipping / KL penalty / advantage soft-clipping 控制步幅。
  • 与代表性方法的本质区别: 相比 MixGRPO / BranchGRPO 把 generation 建成 MDP 并优化 trajectory transitions,V-GRPO 把完整生成结果当作一个 atomic action,用 ELBO-style surrogate 直接近似 final-output likelihood;相比 DiffusionNFT 的正负策略对比,它不需要维护两套模型权重。

3. Method(方法)

总体框架

直觉段落。 传统 MDP 化的视觉 RL 把每个 denoising step 都当作 action,这让 policy gradient 可计算,但也把训练强行锁进一阶 stochastic sampler:rollout 生成时的每个 transition kernel 必须和优化时的 log-prob 对齐。V-GRPO 反过来利用 diffusion / flow matching 预训练本来就在估计“给定数据样本在某个 noise level 下的重构误差”这一事实:对于固定生成样本 ,其 weighted denoising loss 可看成 negative likelihood surrogate。问题在于 raw surrogate 的 scale 很不均匀,因此本文的核心不是发明复杂策略梯度,而是把这个 surrogate 的估计方差压到 group-relative advantage 能稳定发挥作用的范围。

Figure 1 解读: 图中统计同一类 per-sample loss term 在不同 timestep 上的均值与方差。它显示 raw ELBO surrogate 的量级随 timestep 明显变化;若每个 output 独立抽 timestep / noise,同组样本之间的 surrogate 差异会混入大量采样噪声,导致 advantage 排序不再可靠。

Figure 2 解读: 该图把 surrogate magnitude 与 gradient norm 关联起来,说明 surrogate 方差会进一步转化为梯度方差。应用三种 variance-reduction 技术后,组内 CV 从 0.170 降到 0.038,overall surrogate CV 从 0.230 降到 0.128,gradient norm 对 surrogate magnitude 的二次拟合 0.406 降到 0.328

ELBO-based likelihood surrogate

预训练 denoising / flow matching 模型通常最小化 weighted regression:

V-GRPO 将最终输出 和 prompt 条件化后,把 negative loss 替代 log likelihood:

对应 importance ratio 为:

实际用 个 timestep-noise pair 估计:

三个 surrogate variance reduction 组件

  1. Group-shared timestep-noise pairs: 对同一个 prompt 下的 个输出,共享同一组 ,避免同组样本因随机抽样 basis 不同而不可比较。
  2. Stratified timestep sampling: 把 schedule 分成 个等长区间,每个区间抽一个 timestep,保证每个样本覆盖完整噪声时间轴。
  3. Adaptive loss weighting: 先把 model output 重参数化成 -prediction,如 rectified flow 中 ,再用 self-normalized loss:

三类 gradient-step regulation

  • Importance ratio clipping: 默认最常用,按 PPO/GRPO 形式限制 ,在 FLUX.1-dev 主实验中足以防止 loss spikes。
  • KL penalty: 不额外维护 reference model,而对 behavior policy 罚偏离,只需存旧 surrogate:
  • Advantage soft-clipping: 对 fully on-policy 或采样步数很少的设置,用

平滑限制极端 advantage;在 SD 3.5 M Stage-1FLUX 16-step 设置更有用。

论文算法伪代码(非源码实现)

代码搜索说明:论文脚注写明 https://github.com/tang-bd/v-grpo,但当前公开访问为 404;GitHub 用户 tang-bd 的公开 repo 列表中未出现 v-grpo;WebSearch / GitHub code search 也未找到可核对官方实现。因此下面是按 Algorithm 1 和公式整理的论文级 PyTorch-style 伪代码,不是源代码复刻。

import torch
import torch.nn.functional as F
 
 
def group_relative_advantages(rewards: torch.Tensor, eta: float | None = None):
    # rewards: [batch, group, num_rewards] or [batch, group]
    if rewards.dim() == 3:
        rewards = rewards.mean(dim=-1)
    mean = rewards.mean(dim=1, keepdim=True)
    std = rewards.std(dim=1, keepdim=True).clamp_min(1e-6)
    adv = (rewards - mean) / std
    if eta is not None:
        adv = eta * torch.tanh(adv / eta)
    return adv
import torch
 
 
def sample_shared_stratified_pairs(batch_size, group_size, n_mc, latent_shape, device):
    # one shared basis per prompt group, then expanded to all outputs of that prompt
    bins = torch.linspace(0, 1, n_mc + 1, device=device)
    u = torch.rand(batch_size, n_mc, device=device)
    t = bins[:-1] + u * (bins[1:] - bins[:-1])
    eps = torch.randn(batch_size, n_mc, *latent_shape, device=device)
    t = t[:, None].expand(batch_size, group_size, n_mc)
    eps = eps[:, None].expand(batch_size, group_size, n_mc, *latent_shape)
    return t, eps
import torch
 
 
def adaptive_elbo_surrogate(model, sample_o, prompt_emb, t, eps, schedule):
    # sample_o: generated clean image/latent o_i; t, eps shared within prompt group
    z_t = schedule.noise(sample_o, eps, t)
    pred = model(z_t, t, prompt_emb)
    x_pred = schedule.to_x_prediction(z_t, pred, t)
    l2 = (x_pred - sample_o).pow(2).flatten(2).sum(dim=-1)
    l1 = (x_pred - sample_o).abs().flatten(2).mean(dim=-1).detach().clamp_min(1e-8)
    return (l2 / l1).mean(dim=-1)  # average over N_MC
import torch
 
 
def v_grpo_update(model, old_model, batch, rewards, optimizer, beta, eps_clip, eta, n_mc):
    prompts, old_outputs = batch["prompts"], batch["outputs"]
    t, noise = sample_shared_stratified_pairs(
        batch_size=old_outputs.size(0),
        group_size=old_outputs.size(1),
        n_mc=n_mc,
        latent_shape=old_outputs.shape[2:],
        device=old_outputs.device,
    )
    with torch.no_grad():
        old_loss = adaptive_elbo_surrogate(old_model, old_outputs, prompts, t, noise, batch["schedule"])
    new_loss = adaptive_elbo_surrogate(model, old_outputs, prompts, t, noise, batch["schedule"])
    ratio = torch.exp(-new_loss + old_loss)
    adv = group_relative_advantages(rewards, eta=eta)
    clipped = torch.clamp(ratio, 1 - eps_clip, 1 + eps_clip) * adv
    objective = torch.minimum(ratio * adv, clipped)
    kl = (batch["schedule"].to_x_prediction_current(model, old_outputs, prompts, t, noise)
          - batch["schedule"].to_x_prediction_current(old_model, old_outputs, prompts, t, noise)).pow(2).mean()
    loss = -(objective.mean() - beta * kl)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    return loss.detach()

Code reference: no public code found (2026-04-28) — paper footnote URL https://github.com/tang-bd/v-grpo returned 404; pseudocode and mapping are paper-derived, not implementation-anchored.

Paper ConceptSource FileKey Class/Function
ELBO surrogate replacing 论文 Section 4.1 / Eq. before Eq. (loss_term)adaptive_elbo_surrogate(上方论文级伪代码)
Group-shared stratified timestep-noise pairsAlgorithm 1 + Section 4.3sample_shared_stratified_pairs(上方论文级伪代码)
Advantage soft-clippingAlgorithm 1 + Section 4.4group_relative_advantages(..., eta)(上方论文级伪代码)
Importance ratio + GRPO clipped objective + KL penaltyAlgorithm 1 + Eq. for / v_grpo_update(上方论文级伪代码)

关键图表解读

Figure 3 解读: FLUX.1-dev 主实验定性图展示 V-GRPO 在 alignment、coherence、style 上优于 baseline;第二个例子突出其未使用 OCR reward / task-specific dataset 也能改善 text rendering。

Figure 4 解读: FLUX 消融显示 naive ELBO-GRPO 明显不稳定;去掉 group-shared pair 或 stratified sampling 都会破坏收敛,去掉 adaptive weighting 则略降性能,说明稳定性主要来自 surrogate basis 的可比较性。

Figure 5 解读: 对 FLUX 来说,单独 KL penalty 无法抑制 loss spikes;importance ratio clipping 更适合作为常规稳定器。

Figure 6 解读: 在 SD 3.5 M fully on-policy Stage-1 中,soft-clipping advantage 可以稳定训练;这是因为只有 1 个 gradient step 时 ,importance ratio clipping 不再起作用。

Figure 7 解读: 采样步数降到 16 时,advantage soft-clipping 对 FLUX 训练也有稳定效果,说明它适合“每次 rollout 信息更稀疏 / 更新更激进”的场景。

Figure 8 解读: 在 SD 3.5 M Stage-2 的粗粒度 GenEval reward 任务中,importance ratio clipping + 2 gradient steps 优于 advantage soft-clipping,说明不同 reward granularity 需要不同 update regulator。

Figure 9 解读: 不足以收敛, 已较好,增到 8 只有边际收益;这与 MDP-based 方法中“optimized timesteps”饱和现象一致。

Figure 10 解读: SD 3.5 M 对 ELBO surrogate 更鲁棒;去掉单个组件影响不如 FLUX 剧烈,但三项技术整体仍有收益。

Figure 11 解读: adaptive loss weighting 中使用 -prediction 最优;-prediction 会训练 collapse,-prediction 稳定但收敛略慢。

Figure 12 解读: 补充 FLUX 定性图表明 V-GRPO 不只提升局部美学,也能改善复杂世界知识和 prompt coherence。

Figure 13 解读: SD 3.5 M 多阶段训练的定性图展示 V-GRPO 在 alignment、coherence、style 上达到与 DiffusionNFT 接近或更好的结果,同时训练步数更少。

4. Experimental Setup(实验设置)

  • Base models: FLUX.1-dev(guidance-distilled,通常不显式使用 CFG)与 Stable Diffusion 3.5 Medium(训练与评估均关闭 CFG;作者观察 online RL 可起到 guidance distillation 作用)。
  • Datasets / prompts: FLUX.1-dev 实验使用 HPDv2 prompts;SD 3.5 M 按 DiffusionNFT,GenEval / OCR 用 Flow-GRPO prompt sets,其余训练用 Pick-a-Pic,评估用 DrawBench。论文未在正文列出每个 prompt set 的完整样本数;只明确训练设置与评估协议跟随对应 baseline。
  • Rewards / metrics: 规则类 GenEval(组合图文对齐)、OCR(文字渲染);模型类 HPSv2.1、PickScore、CLIPScore、ImageReward、UnifiedReward、Aesthetics,评估 image quality、image-text alignment 与 human preference。
  • Training config: FLUX 主实验训练 300 iterations,每轮 4 gradient steps,global batch size 8/step,group size 12,AdamW lr=1e-5、weight decay 1e-4,720×720 rollout,16 或 25 sampling steps,评估 1024×1024 / 50 steps,并用 MixGRPO hybrid sampling)。SD 3.5 M 使用 LoRA r=32, alpha=64,AdamW lr=3e-4、weight decay 1e-4,global batch size 48,group size 24,五阶段总 580 gradient steps,512×512 / 40 steps;BF16 rollout,master weights、surrogate 与 backward 用 FP32。

5. Experimental Results(实验结果)

Teaser speed / average reward(Table 1)

MethodStepsReward
FLUX.1-dev1.25
+ BranchGRPO30013.6813.681.40
+ MixGRPO3002541.41
+ V-GRPO15016 + 441.42
+ V-GRPO30016 + 441.45
SD 3.5 M (w/o CFG)0.95
+ DiffusionNFT1.7K40 + 40401.71
+ V-GRPO58040 + 6.96.91.71

FLUX.1-dev multi-reward(Table 2)

MethodHPS-v2.1PickScoreImageRewardUnifiedReward
FLUX.1-dev0.3130.2271.0883.370
DanceGRPO2540.3340.2251.3353.374
DanceGRPO*2540.3330.2291.2353.325
DanceGRPO25140.3560.2331.4363.397
BranchGRPO-WidPru13.688.6250.3640.2311.6093.383
BranchGRPO-DepPru13.688.6250.3690.2351.6253.404
BranchGRPO-Mix13.684.250.3630.2301.5983.384
BranchGRPO13.6813.680.3630.2291.6033.386
MixGRPO-Flash*840.3570.2321.6243.402
MixGRPO-Flash1640.3580.2361.5283.407
MixGRPO2540.3670.2371.6293.418
V-GRPO16 + 440.3720.2411.7313.437
V-GRPO25 + 440.3720.2411.7493.436

SD 3.5 M multi-stage multi-reward(Table 3)

MethodStepsGenEvalOCRPickScoreCLIPScoreHPSv2.1AestheticsImgRwdUniRwd
SD XL†0.550.140.22420.2870.2805.600.762.93
SD 3.5 L†0.710.680.22910.2890.2885.500.963.25
SD 3.5 M (w/o CFG)0.240.120.20510.2370.2045.13-0.582.02
+ CFG0.630.590.22340.2850.2795.360.853.03
+ FlowGRPO>5K40400.950.660.22510.2930.2745.321.063.18
+ FlowGRPO2K40400.660.920.22410.2900.2805.320.953.15
+ FlowGRPO4K40400.540.680.23500.2800.3165.901.293.37
+ DiffusionNFT1.7K40 + 40400.940.910.23800.2930.3316.011.493.49
+ V-GRPO58040 + 6.96.90.910.910.23500.2980.3416.021.523.43

KL 保留旧能力(Table 4)

MethodGenEvalOCR
Importance ratio clipping 0.870.93
KL penalty 0.910.91

训练效率(Appendix Table 5)

StageDiffusionNFT StepsDiffusionNFT NFEV-GRPO StepsV-GRPO NFE
1 Human Preferences80012015048
2 GenEval30012020060
3 Human Preferences20012015048
4 GenEval2001205060
5 OCR1001203060
Total170012058053.8

SD 3.5 M single-reward(Appendix Table 6)

Setting / MethodStepsGenEvalOCRPickScoreCLIPScoreHPSv2.1AestheticImgRwdUniRwd
SD 3.5 M (w/o CFG)0.240.120.20510.2370.2045.13-0.582.02
+ CFG0.630.590.22340.2850.2795.360.853.03
GenEval / FlowGRPO4K0.970.300.21780.2770.2485.150.742.87
GenEval / DiffusionNFT1K0.980.360.21920.2710.2515.330.682.91
GenEval / V-GRPO6000.970.340.21500.2800.2255.200.352.80
OCR / FlowGRPO1K0.660.960.21940.2800.2575.180.312.86
OCR / DiffusionNFT1500.540.970.21630.2810.2465.190.372.81
OCR / V-GRPO250.470.980.21700.2770.2435.210.282.83
PickScore / FlowGRPO4K0.540.600.23620.2570.2956.421.173.17
PickScore / DiffusionNFT2K0.530.640.24030.2700.3156.171.293.40
PickScore / V-GRPO3000.660.620.24030.2670.3086.421.303.26

关键发现与局限

  • 主要结论: V-GRPO 在 FLUX 主实验四项 reward 指标全领先或并列最优;在 SD 3.5 M 上以 580 steps 匹配 DiffusionNFT 1.7K steps 的综合 reward,并以更低 达到 梯度步加速。
  • 消融结论: surrogate variance reduction 是 FLUX 成败关键; 存在饱和,4 是主要实验折中;KL penalty 适合保留旧能力,importance ratio clipping 适合抑制 spikes,advantage soft-clipping 适合 fully on-policy 或低采样步数场景。
  • 作者明示边界: 结论指向“robustness and scalability”仍需进一步研究;官方源码当前未公开可访问,复现需要等待或自行实现 Algorithm 1。