Views
No views yet
Improved Distribution Matching Distillation for Fast Image Synthesis,
Tianwei Yin, Michaël Gharbi, Taesung Park, Richard Zhang, Eli Shechtman, Frédo Durand, William T. Freeman
1import torch
2from diffusers import DiffusionPipeline, UNet2DConditionModel, LCMScheduler
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
6repo_name = "tianweiy/DMD2"
7ckpt_name = "dmd2_sdxl_4step_unet_fp16.bin"
8# Load model.
9unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
10unet.load_state_dict(torch.load(hf_hub_download(repo_name, ckpt_name), map_location="cuda"))
11pipe = DiffusionPipeline.from_pretrained(base_model_id, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
12pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
13prompt="a photo of a cat"
14
15# LCMScheduler's default timesteps are different from the one we used for training
16image=pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0, timesteps=[999, 749, 499, 249]).images[0]1import torch
2from diffusers import DiffusionPipeline, UNet2DConditionModel, LCMScheduler
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
6repo_name = "tianweiy/DMD2"
7ckpt_name = "dmd2_sdxl_4step_lora_fp16.safetensors"
8# Load model.
9pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to("cuda")
10pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
11pipe.fuse_lora(lora_scale=1.0) # we might want to make the scale smaller for community models
12
13pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
14prompt="a photo of a cat"
15
16# LCMScheduler's default timesteps are different from the one we used for training
17image=pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0, timesteps=[999, 749, 499, 249]).images[0]1import torch
2from diffusers import DiffusionPipeline, UNet2DConditionModel, LCMScheduler
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
6repo_name = "tianweiy/DMD2"
7ckpt_name = "dmd2_sdxl_1step_unet_fp16.bin"
8# Load model.
9unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
10unet.load_state_dict(torch.load(hf_hub_download(repo_name, ckpt_name), map_location="cuda"))
11pipe = DiffusionPipeline.from_pretrained(base_model_id, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
12pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
13prompt="a photo of a cat"
14image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[399]).images[0]1from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, AutoencoderKL, UNet2DConditionModel, LCMScheduler
2from diffusers.utils import load_image, make_image_grid
3from controlnet_aux.canny import CannyDetector
4from huggingface_hub import hf_hub_download
5import torch
6
7# load adapter
8adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", torch_dtype=torch.float16, varient="fp16").to("cuda")
9
10vae=AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
11
12base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
13repo_name = "tianweiy/DMD2"
14ckpt_name = "dmd2_sdxl_4step_unet_fp16.bin"
15# Load model.
16unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
17unet.load_state_dict(torch.load(hf_hub_download(repo_name, ckpt_name), map_location="cuda"))
18
19pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
20 base_model_id, unet=unet, vae=vae, adapter=adapter, torch_dtype=torch.float16, variant="fp16",
21).to("cuda")
22pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
23pipe.enable_xformers_memory_efficient_attention()
24
25canny_detector = CannyDetector()
26
27url = "https://huggingface.co/Adapter/t2iadapter/resolve/main/figs_SDXLV1.0/org_canny.jpg"
28image = load_image(url)
29
30# Detect the canny map in low resolution to avoid high-frequency details
31image = canny_detector(image, detect_resolution=384, image_resolution=1024)#.resize((1024, 1024))
32
33prompt = "Mystical fairy in real, magic, 4k picture, high quality"
34
35gen_images = pipe(
36 prompt=prompt,
37 image=image,
38 num_inference_steps=4,
39 guidance_scale=0,
40 adapter_conditioning_scale=0.8,
41 adapter_conditioning_factor=0.5,
42 timesteps=[999, 749, 499, 249]
43).images[0]
44gen_images.save('out_canny.png')1@article{yin2024improved,
2 title={Improved Distribution Matching Distillation for Fast Image Synthesis},
3 author={Yin, Tianwei and Gharbi, Micha{\"e}l and Park, Taesung and Zhang, Richard and Shechtman, Eli and Durand, Fredo and Freeman, William T},
4 journal={arXiv:2405.14867},
5 year={2024}
6}
7
8@inproceedings{yin2024onestep,
9 title={One-step Diffusion with Distribution Matching Distillation},
10 author={Yin, Tianwei and Gharbi, Micha{\"e}l and Zhang, Richard and Shechtman, Eli and Durand, Fr{\'e}do and Freeman, William T and Park, Taesung},
11 booktitle={CVPR},
12 year={2024}
13}