ai-toolkit icon indicating copy to clipboard operation
ai-toolkit copied to clipboard

RLHF Flow-GRPO implementation POC

Open ifilipis opened this issue 7 months ago • 4 comments

Added reinforcement learning (Flow-GRPO) that seems to work quite universally across models.

It implements Flow-GRPO and lets you vote live and thus create a LoRA

Default parameters seem quite well tuned for quick results within a few iterations. For extra fast results, set LR to 0.005 and behold the speed The only difference in this implementation vs original: rewards are binary instead of relying on a ranking model

There's a new job type dropdown for creating Flow-GRPO tasks, and GRPO job has a voting interface that lets you generate samples and vote on them

Stuff yet to do:

  • [ ] Manual checkpoints
  • [x] Reduce memory usage (Z-Image now takes 6.5GB in uint4) and improve speed
  • [x] UI polishing
  • [x] - Prevent prompt settings from resetting on leaving the tab
  • [x] - Fix skip button color when selected
  • [x] - Add fixed/random seed
  • [x] - Improve progress indication when generating candidates ~~- Maybe fix concurrency of training/generation~~
  • [x] - Improve candidate images layout
  • [x] - Add input images for editing models
  • [ ] Keep testing the algorithm on all models

ifilipis avatar Apr 28 '26 22:04 ifilipis

Can it support the training of the editing model? (Add control image and caption)

xd2333 avatar May 04 '26 01:05 xd2333

Can it support the training of the editing model? (Add control image and caption)

Reference latents are implemented, but not added to the UI yet

ifilipis avatar May 04 '26 08:05 ifilipis

Hi, thank you for such a cool feature!

I tried to finetune my Flux Klein Base 9B lora for image editing task, but i see that applying vote takes ~20min on RTX4090 48GB, is this an expected behaviour?

georgeYanch avatar Jun 09 '26 09:06 georgeYanch

Yeah, this is expected. With 4 candidates and 30 steps, the trainer actually makes 120 timesteps. What you can do for Flux is take this https://huggingface.co/bghira/flux2-klein-9b-distillation-adapter and add it as both assistant lora and inference lora in config. Then you can reduce generation step count to around 10 or sometimes less. The model will slightly drift after RLHF (it won't be visible in comfyui though), so the best I found is to do another 50-100 regular lora steps after this manipulation

ifilipis avatar Jun 09 '26 14:06 ifilipis