赞
踩
在Diffusers的0.17.0版本之后支持直接调用来自CivitAI的Lora
import differs
import torch
# 创建PipeLine
safetensors_path = "model.safetensors"
pipeline = differs.StableDiffusionPipeline.from_single_file(
safetensors_path,
torch_dtype = torch.float16, # 对于 CUDA。
)
lora_safetensors_path = "test.safetensors"
pipeline.load_lora_weights(lora_safetensors_path)
使用 pipeline.fuse_lora(lora_scale = 0.7)
若要导入多个LoRA设置多个权重则可以
lora_dirs = [ "lora1.safetensors" , "lora2.safetensors" , ...]
lora_scales = [ 0.5 , 0.75 , ...]
ldir, lsc in zip (lora_dirs, lora_scales):
# 迭代添加新的 LoRA。
pipeline.load_lora_weights(ldir)
# 并相应地缩放它们。
pipeline.fuse_lora(lora_scale = lsc)
1.unload_lora_weights()
2.disable_lora()
但是实测下来发现会有问题,建议是卸载LoRA之后新建一个pipeline
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。