Views
No views yet
Yuxuan Zhang, Yirui Yuan, Yiren Song, Haofan Wang, Jiaming Liu
Tiamat AI, ShanghaiTech University, National University of Singapore, Liblib AI


1from huggingface_hub import hf_hub_download
2hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/canny.safetensors", local_dir="./models")
3hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/depth.safetensors", local_dir="./models")
4hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/hedsketch.safetensors", local_dir="./models")
5hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/inpainting.safetensors", local_dir="./models")
6hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/pose.safetensors", local_dir="./models")
7hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/seg.safetensors", local_dir="./models")
8hf_hub_download(repo_id="Xiaojiu-Z/EasyControl", filename="models/subject.safetensors", local_dir="./models")1export HF_ENDPOINT=https://hf-mirror.com
2huggingface-cli download --resume-download Xiaojiu-Z/EasyControl --local-dir checkpoints --local-dir-use-symlinks False1import torch
2from PIL import Image
3from src.pipeline import FluxPipeline
4from src.transformer_flux import FluxTransformer2DModel
5from src.lora_helper import set_single_lora, set_multi_lora
6
7def clear_cache(transformer):
8 for name, attn_processor in transformer.attn_processors.items():
9 attn_processor.bank_kv.clear()
10
11# Initialize model
12device = "cuda"
13base_path = "FLUX.1-dev" # Path to your base model
14pipe = FluxPipeline.from_pretrained(base_path, torch_dtype=torch.bfloat16, device=device)
15transformer = FluxTransformer2DModel.from_pretrained(
16 base_path,
17 subfolder="transformer",
18 torch_dtype=torch.bfloat16,
19 device=device
20)
21pipe.transformer = transformer
22pipe.to(device)
23
24# Load control models
25lora_path = "./models"
26control_models = {
27 "canny": f"{lora_path}/canny.safetensors",
28 "depth": f"{lora_path}/depth.safetensors",
29 "hedsketch": f"{lora_path}/hedsketch.safetensors",
30 "pose": f"{lora_path}/pose.safetensors",
31 "seg": f"{lora_path}/seg.safetensors",
32 "inpainting": f"{lora_path}/inpainting.safetensors",
33 "subject": f"{lora_path}/subject.safetensors",
34 "Ghibli": f"{lora_path}/Ghibli.safetensors"
35}1# Single spatial condition control example
2path = control_models["canny"]
3set_single_lora(pipe.transformer, path, lora_weights=[1], cond_size=512)
4
5# Generate image
6prompt = "A nice car on the beach"
7spatial_image = Image.open("./test_imgs/canny.png")
8
9image = pipe(
10 prompt,
11 height=720,
12 width=992,
13 guidance_scale=3.5,
14 num_inference_steps=25,
15 max_sequence_length=512,
16 generator=torch.Generator("cpu").manual_seed(5),
17 spatial_images=[spatial_image],
18 cond_size=512,
19).images[0]
20
21# Clear cache after generation
22clear_cache(pipe.transformer)1# Multi-condition control example
2paths = [control_models["subject"], control_models["inpainting"]]
3set_multi_lora(pipe.transformer, paths, lora_weights=[[1], [1]], cond_size=512)
4
5prompt = "A SKS on the car"
6subject_images = [Image.open("./test_imgs/subject_1.png")]
7spatial_images = [Image.open("./test_imgs/inpainting.png")]
8
9image = pipe(
10 prompt,
11 height=1024,
12 width=1024,
13 guidance_scale=3.5,
14 num_inference_steps=25,
15 max_sequence_length=512,
16 generator=torch.Generator("cpu").manual_seed(42),
17 subject_images=subject_images,
18 spatial_images=spatial_images,
19 cond_size=512,
20).images[0]
21
22# Clear cache after generation
23clear_cache(pipe.transformer)clear_cache(pipe.transformer)guidance_scale=3.5 and adjust based on resultsnum_inference_steps=25 for a good balance of quality and speed8 complete transformation sets available in/assets/test_imgs/directory
All outputs generated with identical prompt weights with same prompt:"Ghibli Studio style, Charming hand-drawn anime-style illustration"
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() |
@misc{zhang2025easycontroladdingefficientflexible,
title={EasyControl: Adding Efficient and Flexible Control for Diffusion Transformer},
author={Yuxuan Zhang and Yirui Yuan and Yiren Song and Haofan Wang and Jiaming Liu},
year={2025},
eprint={2503.07027},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2503.07027},
}