UniDG is a universal defect generation foundation model that transfers defects from a reference image to a target region via Defect-Context Editing and MM-DiT multimodal attention, without per-category fine-tuning. This checkpoint is the Consistency-RFT variant, further refined from UniDG-SFT using Flow-GRPO with dual reward models (Defect-Und-Reward & Defect-Recog-Reward) for improved defect fidelity and consistency.
First, you need a base FLUX.1-Fill-dev model with UniDG-SFT-LoRA weights already merged in. If you haven't done this, you can prepare it by loading the SFT model and saving the merged weights:
1from diffusers import FluxFillPipeline
2import torch
3
4# Load base FLUX.1-Fill-dev
5pipe = FluxFillPipeline.from_pretrained(
6 "path/to/FLUX.1-Fill-dev",
7 torch_dtype=torch.bfloat16,
8)
9
10# Load SFT LoRA weights
11pipe.load_lora_weights("path/to/UniDG-SFT-LoRA-Release/pytorch_lora_weights.safetensors")
12
13# Save the merged SFT model as the base for RFT merging
14pipe.save_pretrained("path/to/FLUX.1-Fill-dev-UDG-SFT", safe_serialization=True, max_shard_size="5GB")
1python combine_peft_weights.py \
2 --base_model_path path/to/FLUX.1-Fill-dev-UDG-SFT \
3 --lora_weights_path path/to/UniDG-RFT-LoRA-Release \
4 --output_path path/to/FLUX.1-Fill-dev-UDG-RFT \
5 --save_full_pipeline
1from unidg import ImageUniDG
2from PIL import Image
3import torch
4
5# Load the merged RFT model — set lora_weights_path="" since LoRA is already merged
6model = ImageUniDG(
7 flux_model_path="path/to/FLUX.1-Fill-dev-UDG-RFT",
8 redux_model_path="path/to/FLUX.1-Redux-dev",
9 lora_weights_path="", # No additional LoRA needed!
10 device="cuda:0",
11 dtype=torch.bfloat16,
12)
13
14result, mask = model.process_images(
15 target_image=Image.open("target.jpg"),
16 reference_image=Image.open("reference.jpg"),
17 reference_mask=Image.open("reference_mask.png"),
18 target_mask=Image.open("target_mask.png"),
19 num_inference_steps=28,
20 guidance_scale=3.5,
21 seed=42,
22)
23result.save("result.png")
1@article{fan2026unidg,
2 title={Large-Scale Universal Defect Generation: Foundation Models and Datasets},
3 author={Fan, Yuanting and Liu, Jun and Gao, Bin-Bin and Chen, Xiaochen and Lin, Yuhuan and Dai, Zhewei and Zhan, Jiawei and Wang, Chengjie},
4 journal={arXiv preprint arXiv:2604.08915},
5 year={2026}
6}