diffusers-Load adapters

这篇具有很好参考价值的文章主要介绍了diffusers-Load adapters。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adaptershttps://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters

有几种训练技术可以个性化扩散模型,生成特定主题的图像或某些风格的图像。每种训练方法都会产生不同类型的适配器。一些适配器会生成全新的模型,而其他适配器只修改较小的一组嵌入或权重。这意味着每个适配器的加载过程也是不同的。

1.Dreambooth

DreamBooth针对一个主题的几张图像微调整个扩散模型,以生成该主题的具有新风格和设置的图像。这种方法是通过在提示中使用一个特殊单词来触发模型学习与主题图像相关联。在所有的训练方法中,DreamBooth生成的文件大小最大(通常为几GB),因为它是一个完整的模型。

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained("sd-dreambooth-library/herge-style", torch_dtype=torch.float16).to("cuda")
prompt = "A cute herge_style brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration"
image = pipeline(prompt).images[0]

2.Textual inversion

Textual inversion与DreamBooth非常相似,也可以个性化扩散模型,从仅有的几张图像中生成特定的概念(风格、物体)。这种方法通过训练和寻找新的嵌入来表示在提示中使用特殊单词提供的图像。因此,扩散模型的权重保持不变,而训练过程会生成一个相对较小(几KB)的文件。由于文本反演会创建嵌入,它不能像DreamBooth一样单独使用,需要另一个模型。

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")

pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, <gta5-artwork> style"
image = pipeline(prompt).images[0]

文本反演还可以训练不受欢迎的内容,以创建负向嵌入,防止模型生成具有这些不受欢迎的内容的图像,例如模糊的图像或手上额外的手指。这是一个快速改进提示的简单方法。您也可以使用load_textual_inversion()来加载嵌入,但这次需要两个参数:

weight_name:如果文件以特定名称保存在Diffusers格式中,或者文件存储在A1111格式中,则指定要加载的权重文件。 token:指定在提示中使用的特殊单词,以触发嵌入。

pipeline.load_textual_inversion(
    "sayakpaul/EasyNegative-test", weight_name="EasyNegative.safetensors", token="EasyNegative"
)

prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, EasyNegative"
negative_prompt = "EasyNegative"

image = pipeline(prompt, negative_prompt=negative_prompt, num_inference_steps=50).images[0]

3.lora

LoRA是一种流行的训练技术,因为它速度快且生成较小的文件大小(几百MB),可以训练模型从仅有的几张图像中学习新的风格。它通过向扩散模型中插入新的权重,然后仅对新的权重进行训练,而不是整个模型。LoRA是一种非常通用的训练技术,可与其他训练方法一起使用。例如,通常使用DreamBooth和LoRA共同训练模型。

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")

pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors")
prompt = "bears, pizza bites"
image = pipeline(prompt).images[0]

load_lora_weights()方法会将LoRA的权重加载到UNet和文本编码器中。这是加载LoRA首选的方式,因为它可以处理以下情况:1.LoRA的权重没有分别给UNet和文本编码器的单独标识符;2.LoRA的权重有单独给UNet和文本编码器的标识符。但是,如果只需要将LoRA的权重加载到UNet中,那么可以使用load_attn_procs()方法。加载jbilcke-hf/sdxl-cinematic-1的LoRA权重:

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
pipeline.unet.load_attn_procs("jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors")

# use cnmt in the prompt to trigger the LoRA
prompt = "A cute cnmt eating a slice of pizza, stunning color scheme, masterpiece, illustration"
image = pipeline(prompt).images[0]

可以传递cross_attention_kwargs={"scale":0.5}来调节lora的权重。

4. load multiple lora

融合权重可以加快推理延迟,因为不需要单独加载基础模型和LoRA!可以使用save_pretrained()保存融合后的管道,以避免每次使用模型时都需要加载和融合权重。

from diffusers import StableDiffusionXLPipeline, AutoencoderKL
import torch

vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipeline = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    vae=vae,
    torch_dtype=torch.float16,
).to("cuda")

pipeline.load_lora_weights("ostris/ikea-instructions-lora-sdxl")
pipeline.fuse_lora(lora_scale=0.7)

# to unfuse the LoRA weights
pipeline.unfuse_lora()

pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora")
pipeline.fuse_lora(lora_scale=0.7)

prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration"
image = pipeline(prompt).images[0]

5.PEFT

from diffusers import DiffusionPipeline
import torch

pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
pipeline.load_lora_weights("ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", adapter_name="ikea")
pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors", adapter_name="cereal")

pipeline.set_adapters(["ikea", "cereal"], adapter_weights=[0.7, 0.5])

prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration"
image = pipeline(prompt, num_inference_steps=30, cross_attention_kwargs={"scale": 1.0}).images[0]

kohya and TheLastBen

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0").to("cuda")
pipeline.load_lora_weights("path/to/weights", weight_name="blueprintify-sd-xl-10.safetensors")

# use bl3uprint in the prompt to trigger the LoRA
prompt = "bl3uprint, a highly detailed blueprint of the eiffel tower, explaining how to build all parts, many txt, blueprint grid backdrop"
image = pipeline(prompt).images[0]

无法加载LyCORIS文章来源地址https://www.toymoban.com/news/detail-739517.html

到了这里,关于diffusers-Load adapters的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Stable-diffusion安装时Can‘t load tokenizer for ‘openai/clip-vit-large-patch14‘2种解决方案

    在安装Stable-diffusion WebuUI时,运行python launch.py出现Can‘t load tokenizer for ‘openai/clip-vit-large-patch14问题,这是因为安装过程中需要去huggingface网站下载一些文件,但该网站被墙,所以报错。 所以可以自己去网站下载好对应文件:https://huggingface.co/openai/clip-vit-large-patch14/tree/main。下

    2024年02月02日
    浏览(23)
  • Apache Doris 数据导入:Insert Into语句;Binlog Load;Broker Load;HDFS Load;Spark Load;例行导入(Routine Load)

    Doris 提供多种数据导入方案,可以针对不同的数据源进行选择不同的数据导入方式。Doris支持各种各样的数据导入方式:Insert Into、json格式数据导入、Binlog Load、Broker Load、Routine Load、Spark Load、Stream Load、S3 Load,下面分别进行介绍。 注意: Doris 中的所有导入操作都有原子性保

    2024年02月21日
    浏览(44)
  • Doris(7):数据导入(Load)之Routine Load

    例行导入功能为用户提供了义中自动从指定数据源进行数据导入的功能 1 适用场景 当前仅支持kafka系统进行例行导入。 2 使用限制 支持无认证的 Kafka 访问,以及通过 SSL 方式认证的 Kafka 集群。 支持的消息格式为 csv 文本格式。每一个 message 为一行,且行尾不包含换行符。 仅

    2023年04月24日
    浏览(36)
  • Doris(6):数据导入(Load)之Stream Load

    Broker load是一个同步的导入方式,用户通过发送HTTP协议将本地文件或者数据流导入到Doris中,Stream Load同步执行导入并返回结果,用户可以通过返回判断导入是否成功。 1 适用场景 Stream load 主要适用于导入本地文件,或通过程序导入数据流中的数据。 2 基本原理 下图展示了

    2023年04月19日
    浏览(38)
  • MetalLB Load Balancer

    MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type  LoadBalancer  in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load balancers. There are multiple ways to install MetalLB, for example Thro

    2024年02月04日
    浏览(29)
  • hive数据load到redis

    使用shell脚本来实现,脚本如下: 在原文基础上做了优化,怕忘了,所以写个文章记录下,原文链接如下:  两种方式用Shell实现把Hive表数据导入到redis_shell脚本 hive加载到doris_刘先生我在呀的博客-CSDN博客

    2024年02月05日
    浏览(29)
  • 如何解决“library load load opencv_core_parallel_tbb460_64d.dll =>FAILED”类的信息

    如何解决“library load load opencv_core_parallel_tbb460_64d.dll =FAILED”类的信息 对于这类信息不会影响release的发布版结果,但是debug会有错误信息输出,如果是强迫症患者可以考虑以下的两种方法: 1、直接将opencv的Log日志等级修改,比如:OPENCV_LOG_LEVEL=e,这样可以避免输出此类信息,

    2024年02月16日
    浏览(36)
  • 关于load过高的几种情况

    Linux 中 load啥意思 \\\"Load\\\" 在 Linux 系统中通常是指系统的负载情况,也称为系统负荷。它指的是系统正在运行的进程数量以及这些进程对系统资源的使用情况,例如 CPU、内存、磁盘 I/O 等。Linux 系统的负载通常由三个数字表示,分别对应于过去 1 分钟、5 分钟和 15 分钟内的平均

    2024年02月10日
    浏览(32)
  • CPU 使用率和负载Load

    优质博文:IT-BLOG-CN CPU 使用率是 CPU 处理非空闲任务所花费的时间百分比 。例如单核 CPU 1s 内非空闲态运行时间为 0.8s ,那么它的 CPU 使用率就是 80% ;双核 CPU 1s 内非空闲态运行时间分别为 0.4s 和 0.6s ,那么,总体 CPU 使用率就是 (0.4s + 0.6s) / (1s * 2) = 50% ,其中 2 表示 CPU 核数

    2024年02月03日
    浏览(40)
  • nginx实现负载均衡load balance

    准备:3台服务器,一台做负载均衡器,另外两台做web服务器,建议编译安装nginx 服务器 IP LB 192.168.232.161 web1 192.168.232.162 web2 192.168.232.163 1、修改LB的配置文件 用于cpu的核心是两个,所以可以修改配置文件中的进程数为2,并将应该worker的并发数修改为2048 2、负载均衡器的配置

    2024年02月09日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包