Trajectory Consistency Distillation(TCD)使模型能够用更少的步骤生成更高质量、更详细的图像。此外,由于在过程中有效地减少了误差,即使在大推理步骤的条件下,TCD也表现出优异的性能。
对于像SDXL这样的大型模型,TCD使用LoRA进行训练,以减少内存使用。这也很有用,因为可以在不同的微调模型之间重用LoRA,只要它们共享相同的基本模型,而无需进一步训练。
下面展示如何使用TCD-LoRA对文本到图像和修复等各种任务进行推理,以及如何将TCD-LoRAs与其他适配器轻松组合。
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" mport torch from diffusers import StableDiffusionXLPipeline, TCDScheduler device = "cuda" base_model_id = "stabilityai/stable-diffusion-xl-base-1.0" tcd_lora_id = "h1t/TCD-SDXL-LoRA" pipe = StableDiffusionXLPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to(device) pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights(tcd_lora_id) pipe.fuse_lora() prompt = "Painting of the orange cat Otto von Garfield, Count of Bismarck-Schönhausen, Duke of Lauenburg, Minister-President of Prussia. Depicted wearing a Prussian Pickelhaube and eating his favorite meal - lasagna." image = pipe( prompt=prompt, num_inference_steps=4, guidance_scale=0, eta=0.3, generator=torch.Generator(device=device).manual_seed(0), ).images[0] image.save("infer01.jpg")