An official implementation of DanceGRPO: Unleashing GRPO on Visual Generation
1,655
stars
62
commits
Python
primary language
Oct 16, 2025
updated
This is the official implementation for paper, DanceGRPO: Unleashing GRPO on Visual Generation. We develop DanceGRPO based on FastVideo, a scalable and efficient framework for video and image generation.
DanceGRPO has the following features:
We have shared this work at many research labs, and the example slide can be found here. The trained FLUX checkpoints can be found here.
DanceGRPO is also a project dedicated to inspiring the community. If you have any research or engineering inquiries, feel free to open issues or email us directly at xuezeyue@connect.hku.hk.
You should use "mkdir" for these folders first.
For image generation,
"./data/stable-diffusion-v1-4"."./data/flux"."./hps_ckpt"."./hps_ckpt".For video generation,
"./data/HunyuanVideo"."./data/SkyReels-I2V"."./Qwen2-VL-2B-Instruct"."./videoalign_ckpt"../env_setup.sh fastvideo
# for Stable Diffusion, with 8 H800 GPUs
bash scripts/finetune/finetune_sd_grpo.sh
# for FLUX, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_flux_rl_embeddings.sh
# for FLUX, training with 16 H800 GPUs for better convergence,
# or you can use finetune_flux_grpo_8gpus.sh with 8 H800 GPUs, but with relatively slower convergence
# or you can try the LoRA version, which takes ~20GB VRAM per GPU with one node (8 GPUs).
bash scripts/finetune/finetune_flux_grpo.sh
For image generation open-source version, we use the prompts in HPD dataset for training, as shown in "./assets/prompts.txt".
# for HunyuanVideo, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_hunyuan_rl_embeddings.sh
# for HunyuanVideo, using the following script for training with 16/32 H800 GPUs,
bash scripts/finetune/finetune_hunyuan_grpo.sh
For the text-to-video generation open-source version, we filter the prompts from VidProM dataset for training, as shown in "./assets/video_prompts.txt".
# for SkyReels-I2V, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_skyreels_rl_embeddings.sh
# for SkyReels-I2V, using the following script for training with 32 H800 GPUs
# we use FLUX to generate the reference image, please download FLUX checkpoints to "./data/flux"
bash scripts/finetune/finetune_skyreels_i2v.sh
For the image-to-video generation open-source version, we filter the prompts from ConsistID dataset for training, as shown in "./assets/consist-id.txt".
Download the Qwen-Image checkpoints to "./data/qwenimage". We also use HPS-v2.1 to train the model. The reward increases from ~0.25 to ~0.33 with 200 iterations.
# for Qwen-Image, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_qwen_image_rl_embeddings.sh
# for Qwen-Image, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_qwenimage_grpo.sh
Download the Qwen-Image-Edit checkpoints to "./data/qwenimage_edit".
Since there are no specific image edit open-source reward models for Qwen-Image-Edit, we still can use HPS-v2.1, and this implementation just serves as a reference.
Download this dataset to "./data/SEED-Data-Edit-Part2-3", and cd ./data/SEED-Data-Edit-Part2-3/real_editing/images , then run tar -xzf images.tar.gz.
The HPS-v2.1 reward will increase from ~0.23 to ~0.27 with about 150 iterations.
# for Qwen-Image-Edit, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_qwen_image_edit_rl_embeddings.sh
# for Qwen-Image-Edit, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_qwenimage_edit_grpo.sh
Download the Wan-2.1 checkpoints to "./data/Wan2.1-T2V-1.3B". We regard it as an image generation model and also use HPS-v2.1 to train the model. Wan-2.1 needs more iterations to converge.
# for Wan-2.1, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_wan_2_1_rl_embeddings.sh
# for Wan-2.1, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_wan_2_1_grpo.sh
We give the (moving average) reward curves (also the results in reward.txt or hps_reward.txt) of Stable Diffusion (left or upper) and FLUX (right or lower). We can complete the FLUX training (200 iterations) within 12 hours with 16 H800 GPUs.
<img src=assets/rewards/opensource_sd.png width="49%"> <img src=assets/rewards/opensource_flux.png width="49%">
"./assets/flux_visualization"."./scripts/visualization/vis_flux.py" for FLUX. First, run rm -rf ./data/flux/transformer/* to clear the directory, then copy the files from a trained checkpoint (e.g., checkpoint-160-0) into ./data/flux/transformer. After that, you can run the visualization. If it's trained for 160 iterations, the results are already provided in my repo."./fastvideo/README.md".max_grad_norm.)We give the (moving average) reward curves (also the results in vq_reward.txt) of HunyuanVideo with 16/32 H800 GPUs.
With 16 H800 GPUs,
<img src=assets/rewards/opensource_hunyuanvideo_16gpus.png width="49%">
With 32 H800 GPUs,
<img src=assets/rewards/opensource_hunyuanvideo_32gpus.png width="49%">
rm -rf ./data/HunyuanVideo/transformer/* to clear the directory, then copy the files from a trained checkpoint (e.g., checkpoint-100-0) into ./data/HunyuanVideo/transformer. After that, you can run the visualization script "./scripts/visualization/vis_hunyuanvideo.sh".For SkyReels-I2V,
<img src=assets/rewards/opensource_i2v.png width="49%">
The Multi-reward training code and reward curves can be found here.
Thanks for the issue from @Yi-Xuan XU, the results of more reward models and better visualization (how to avoid grid patterns) on FLUX can be found here. We also support the pickscore for FLUX with --use_pickscore.
We support the EMA for FLUX with --ema_decay 0.995 and --use_ema. Enabling EMA helps with better visualization.
preprocess_flux_embedding.py and latent_flux_rl_datasets.py based on your text encoder.fsdp_util.py and communications_flux.py, we prefer FSDP rather than DeepSpeed since FSDP is easier to debug.train_grpo_flux.py.How to debug:
More improvements on diffusion/flow RL can be found here.
We learned and reused code from the following projects:
We thank the authors for their contributions to the community!
We actively maintain a curated list of the latest research papers on visual generation alignment. Explore the collection here.
If you use DanceGRPO for your research, please cite our paper:
@article{xue2025dancegrpo,
title={DanceGRPO: Unleashing GRPO on Visual Generation},
author={Xue, Zeyue and Wu, Jie and Gao, Yu and Kong, Fangyuan and Zhu, Lingting and Chen, Mengzhao and Liu, Zhiheng and Liu, Wei and Guo, Qiushan and Huang, Weilin and others},
journal={arXiv preprint arXiv:2505.07818},
year={2025}
}
Python
97.4%
Shell
2.6%
An official implementation of DanceGRPO: Unleashing GRPO on Visual Generation
1,655
stars
62
commits
Python
primary language
Oct 16, 2025
updated
This is the official implementation for paper, DanceGRPO: Unleashing GRPO on Visual Generation. We develop DanceGRPO based on FastVideo, a scalable and efficient framework for video and image generation.
DanceGRPO has the following features:
We have shared this work at many research labs, and the example slide can be found here. The trained FLUX checkpoints can be found here.
DanceGRPO is also a project dedicated to inspiring the community. If you have any research or engineering inquiries, feel free to open issues or email us directly at xuezeyue@connect.hku.hk.
You should use "mkdir" for these folders first.
For image generation,
"./data/stable-diffusion-v1-4"."./data/flux"."./hps_ckpt"."./hps_ckpt".For video generation,
"./data/HunyuanVideo"."./data/SkyReels-I2V"."./Qwen2-VL-2B-Instruct"."./videoalign_ckpt"../env_setup.sh fastvideo
# for Stable Diffusion, with 8 H800 GPUs
bash scripts/finetune/finetune_sd_grpo.sh
# for FLUX, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_flux_rl_embeddings.sh
# for FLUX, training with 16 H800 GPUs for better convergence,
# or you can use finetune_flux_grpo_8gpus.sh with 8 H800 GPUs, but with relatively slower convergence
# or you can try the LoRA version, which takes ~20GB VRAM per GPU with one node (8 GPUs).
bash scripts/finetune/finetune_flux_grpo.sh
For image generation open-source version, we use the prompts in HPD dataset for training, as shown in "./assets/prompts.txt".
# for HunyuanVideo, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_hunyuan_rl_embeddings.sh
# for HunyuanVideo, using the following script for training with 16/32 H800 GPUs,
bash scripts/finetune/finetune_hunyuan_grpo.sh
For the text-to-video generation open-source version, we filter the prompts from VidProM dataset for training, as shown in "./assets/video_prompts.txt".
# for SkyReels-I2V, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_skyreels_rl_embeddings.sh
# for SkyReels-I2V, using the following script for training with 32 H800 GPUs
# we use FLUX to generate the reference image, please download FLUX checkpoints to "./data/flux"
bash scripts/finetune/finetune_skyreels_i2v.sh
For the image-to-video generation open-source version, we filter the prompts from ConsistID dataset for training, as shown in "./assets/consist-id.txt".
Download the Qwen-Image checkpoints to "./data/qwenimage". We also use HPS-v2.1 to train the model. The reward increases from ~0.25 to ~0.33 with 200 iterations.
# for Qwen-Image, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_qwen_image_rl_embeddings.sh
# for Qwen-Image, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_qwenimage_grpo.sh
Download the Qwen-Image-Edit checkpoints to "./data/qwenimage_edit".
Since there are no specific image edit open-source reward models for Qwen-Image-Edit, we still can use HPS-v2.1, and this implementation just serves as a reference.
Download this dataset to "./data/SEED-Data-Edit-Part2-3", and cd ./data/SEED-Data-Edit-Part2-3/real_editing/images , then run tar -xzf images.tar.gz.
The HPS-v2.1 reward will increase from ~0.23 to ~0.27 with about 150 iterations.
# for Qwen-Image-Edit, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_qwen_image_edit_rl_embeddings.sh
# for Qwen-Image-Edit, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_qwenimage_edit_grpo.sh
Download the Wan-2.1 checkpoints to "./data/Wan2.1-T2V-1.3B". We regard it as an image generation model and also use HPS-v2.1 to train the model. Wan-2.1 needs more iterations to converge.
# for Wan-2.1, preprocessing with 8 H800 GPUs
bash scripts/preprocess/preprocess_wan_2_1_rl_embeddings.sh
# for Wan-2.1, using the following script for training with 8 H800 GPUs,
bash scripts/finetune/finetune_wan_2_1_grpo.sh
We give the (moving average) reward curves (also the results in reward.txt or hps_reward.txt) of Stable Diffusion (left or upper) and FLUX (right or lower). We can complete the FLUX training (200 iterations) within 12 hours with 16 H800 GPUs.
<img src=assets/rewards/opensource_sd.png width="49%"> <img src=assets/rewards/opensource_flux.png width="49%">
"./assets/flux_visualization"."./scripts/visualization/vis_flux.py" for FLUX. First, run rm -rf ./data/flux/transformer/* to clear the directory, then copy the files from a trained checkpoint (e.g., checkpoint-160-0) into ./data/flux/transformer. After that, you can run the visualization. If it's trained for 160 iterations, the results are already provided in my repo."./fastvideo/README.md".max_grad_norm.)We give the (moving average) reward curves (also the results in vq_reward.txt) of HunyuanVideo with 16/32 H800 GPUs.
With 16 H800 GPUs,
<img src=assets/rewards/opensource_hunyuanvideo_16gpus.png width="49%">
With 32 H800 GPUs,
<img src=assets/rewards/opensource_hunyuanvideo_32gpus.png width="49%">
rm -rf ./data/HunyuanVideo/transformer/* to clear the directory, then copy the files from a trained checkpoint (e.g., checkpoint-100-0) into ./data/HunyuanVideo/transformer. After that, you can run the visualization script "./scripts/visualization/vis_hunyuanvideo.sh".For SkyReels-I2V,
<img src=assets/rewards/opensource_i2v.png width="49%">
The Multi-reward training code and reward curves can be found here.
Thanks for the issue from @Yi-Xuan XU, the results of more reward models and better visualization (how to avoid grid patterns) on FLUX can be found here. We also support the pickscore for FLUX with --use_pickscore.
We support the EMA for FLUX with --ema_decay 0.995 and --use_ema. Enabling EMA helps with better visualization.
preprocess_flux_embedding.py and latent_flux_rl_datasets.py based on your text encoder.fsdp_util.py and communications_flux.py, we prefer FSDP rather than DeepSpeed since FSDP is easier to debug.train_grpo_flux.py.How to debug:
More improvements on diffusion/flow RL can be found here.
We learned and reused code from the following projects:
We thank the authors for their contributions to the community!
We actively maintain a curated list of the latest research papers on visual generation alignment. Explore the collection here.
If you use DanceGRPO for your research, please cite our paper:
@article{xue2025dancegrpo,
title={DanceGRPO: Unleashing GRPO on Visual Generation},
author={Xue, Zeyue and Wu, Jie and Gao, Yu and Kong, Fangyuan and Zhu, Lingting and Chen, Mengzhao and Liu, Zhiheng and Liu, Wei and Guo, Qiushan and Huang, Weilin and others},
journal={arXiv preprint arXiv:2505.07818},
year={2025}
}
Python
97.4%
Shell
2.6%