1import torch
2from PIL import Image
3from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig
4
5pipe = QwenImagePipeline.from_pretrained(
6 torch_dtype=torch.bfloat16, device="cuda",
7 model_configs=[
8 ModelConfig(model_id="Qwen/Qwen-Image-Edit-2511", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
9 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),
10 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
11 ],
12 tokenizer_config=None,
13 processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Edit", origin_file_pattern="processor/"),
14)
15pipe.load_lora(pipe.dit, "checkpoints/epoch-4.safetensors")
16scene = Image.open("scene.jpeg")
17img = pipe("Using Image 1, create a clean character reference of the character in it: "
18 "the character standing in a neutral, relaxed pose on a plain light-gray "
19 "studio background at eye level, preserving their exact identity, art style, "
20 "outfit and the same head and body orientation and framing. Remove the original scene and background.",
21 edit_image=[scene], seed=0, num_inference_steps=40,
22 height=1536, width=1024, zero_cond_t=True) # zero_cond_t REQUIRED for 2511
8 held-out scenes x 5 checkpoints in
val_samples/ -
scenes not seen in training; each generates the extracted reference. Examples (epoch-4):
One reverse pair in
dataset_example/: input scene, target
reference, and the prompt (
pair.json).