搜索
您的当前位置:首页正文

Diffusers代码学习:TCD 使用不同风格Lora

来源:欧得旅游网

TCD LoRA还支持其他接受不同风格训练的LoRA。例如,加载TheLastBen/Papercut_SDXL LoRA,并使用[~loader.UNet2DConditionLoadersMixin.set_apters]方法将其与TCD LoRA融合。

import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
mport torch
from diffusers import StableDiffusionXLPipeline
from scheduling_tcd import TCDScheduler

device = "cuda"
base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
styled_lora_id = "TheLastBen/Papercut_SDXL"

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, adapter_name="tcd")
pipe.load_lora_weights(styled_lora_id, adapter_name="style")
pipe.set_adapters(["tcd", "style"], adapter_weights=[1.0, 1.0])

prompt = "papercut of a winter mountain, snow"

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("infer.jpg")

因篇幅问题不能全部显示,请点此查看更多更全内容

Top