Skip to content

refactor(diffusion): extract Flow-GRPO prepare/formula hooks and add DiffusionNFT - #63

Merged
Rockdu merged 12 commits into
radixark:mainfrom
niehen6174:refactor/flow-grpo-loss-hub
Jul 30, 2026
Merged

refactor(diffusion): extract Flow-GRPO prepare/formula hooks and add DiffusionNFT#63
Rockdu merged 12 commits into
radixark:mainfrom
niehen6174:refactor/flow-grpo-loss-hub

Conversation

@niehen6174

@niehen6174 niehen6174 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Keep a single FSDP train path in the actor: prepare → DiT forward → [optional ref] → loss formula → backward.
  • Extract Flow-GRPO into replaceable hooks (prepare_flow_grpo_batch / flow_grpo_loss_formula) instead of a whole-package loss_fn.
  • Add DiffusionNFT via the same hooks: K-expand convert, corrupt prepare, dual-policy x0-MSE formula, plus optional LoRA EMA as pi_old.
  • --loss-type nft only auto-fills convert / prepare / formula paths; DiT forward always stays in the actor.

Motivation

We need a second diffusion RL objective (DiffusionNFT) without forking the actor train loop or swapping an entire forward+loss bundle. Customization should replace parts—primarily the loss formula, plus convert/prepare when needed—while schedule, DiT forward, and backward remain shared.

Design

Part Flow-GRPO (default) NFT (--loss-type nft)
convert SDE adjacent pairs (x0, t)
prepare stack pair + CFG corrupt → xt, CFG off
forward actor actor
ref lora_base if kl_beta>0 EMA (fallback base)
formula SDE logprob + PPO (±KL) dual-policy x0-MSE

Test

PickScore reward during NFT training
image

Qualitative comparison on eval prompts — baseline vs. NFT checkpoint
image

@niehen6174
niehen6174 force-pushed the refactor/flow-grpo-loss-hub branch 2 times, most recently from a62e1b5 to a7e49fc Compare July 27, 2026 12:30
@niehen6174 niehen6174 changed the title refactor(diffusion): extract loss_hub for Flow-GRPO and custom loss dispatch refactor(diffusion): extract Flow-GRPO prepare/formula hooks and add DiffusionNFT Jul 27, 2026
niehen6174 added a commit to niehen6174/miles_diffusion that referenced this pull request Jul 28, 2026
No code changes — triggers stage-c-5 against the PR radixark#63 merge base (0533c99)
to verify the committed LTX standard still passes without the loss_hub refactor.
…formula

Keep DiT forward in the FSDP actor and swap convert/prepare/formula hooks for
Flow-GRPO vs NFT, instead of dispatching a whole-package loss_fn.
@niehen6174
niehen6174 force-pushed the refactor/flow-grpo-loss-hub branch from 36c1868 to 012dc10 Compare July 28, 2026 07:19
Separate DiT forward input preparation from loss formulas so Flow-GRPO and NFT prepare paths live in one module while losses.py stays formula-only.
Comment thread miles/backends/fsdp_utils/lora_ema.py Outdated
Comment thread miles/ray/rollout.py
Comment thread miles/ray/rollout.py Outdated
Comment thread miles/backends/fsdp_utils/loss_hub/nft.py Outdated
Comment thread miles/backends/fsdp_utils/loss_hub/nft.py Outdated
Comment thread miles/backends/fsdp_utils/actor.py Outdated
Comment thread miles/backends/fsdp_utils/actor.py Outdated
Comment thread miles/backends/fsdp_utils/actor.py
Comment thread miles/backends/fsdp_utils/actor.py
Comment thread miles/backends/fsdp_utils/lora_ema.py Outdated
…mode

Keep custom_convert as a full override, route NFT through a dedicated
converter after post_process_rewards, and resolve reference selection in
arguments.py so the actor only consumes args.ref_mode.
Rename lora_ema → ema / --ema-shadow and drop the --use-lora gate so full
finetune can share the same pi_old path as LoRA.
@Rockdu

Rockdu commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

TODO: add an e2e 2GPU ci for SD3.5 NFT

Rockdu and others added 4 commits July 30, 2026 02:59
Keep rollout orchestration generic while allowing NFT to provide its own sample expansion without a converter class.

Co-authored-by: Cursor <cursoragent@cursor.com>
Make Flow-GRPO the explicit actor fallback and keep NFT-specific preparation and loss behavior together without resolver helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Rockdu

Rockdu commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Follow-up changes

  • Replaced converter classes and resolver helpers with algorithm-specific function hooks, keeping Flow-GRPO as the explicit default.
  • Reorganized loss_hub so each algorithm owns its preparation and loss functions while the actor owns the DiT forward pass.
  • Simplified NFT/EMA configuration, validation, shared utilities, and tests without changing the core training math.

@Rockdu
Rockdu merged commit c0bf98d into radixark:main Jul 30, 2026
15 checks passed
@Rockdu

Rockdu commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks, the pr is now merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants