diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors

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

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注大数据)
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言

正文


也可以使用特定的pipeline



from diffusers import StableDiffusionPipeline

repo_id = “runwayml/stable-diffusion-v1-5”
pipe = StableDiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)


Community pipelines是原始实现不同于DiffusionPipeline,例如StableDiffusionControlNetPipeline.


**1.1 local pipeline**



from diffusers import DiffusionPipeline

repo_id = “./stable-diffusion-v1-5” # local path
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)


from\_pretrained()方法在检测到本地路径时不会下载。


**1.2 swap components in a pipeline**


可以使用另一个兼容的组件来自定义任何流程的默认组件。定制非常重要,因为:


1. 更改调度器对于探索生成速度和质量之间的权衡是重要的。
2. 模型的不同组件通常是独立训练的,您可以用性能更好的组件替换掉现有组件。
3. 在微调过程中,通常只有一些组件(如UNet或文本编码器)进行训练。



from diffusers import DiffusionPipeline

repo_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)
stable_diffusion.scheduler.compatibles



from diffusers import DiffusionPipeline, EulerDiscreteScheduler, DPMSolverMultistepScheduler

repo_id = “runwayml/stable-diffusion-v1-5”
scheduler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder=“scheduler”)
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, scheduler=scheduler, use_safetensors=True)


可以将PNDMScheduler更换为EulerDiscreteScheduler,在回传到DiffusionPipeline中。


**1.3 safety checker**


safety checker可以根据已知的NSFW内容检查生成的输出, 



from diffusers import DiffusionPipeline

repo_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, safety_checker=None, use_safetensors=True)


**1.4 reuse components across pipelines**


可以在多个pipeline中可以重复使用相同的组件,以避免将权重加载到RAM中2次



from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline

model_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id, use_safetensors=True)

components = stable_diffusion_txt2img.components


可以将components传递到另一个pipeline中,无需将权重重新加载到RAM中:



stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(**components)


下面的方式更加灵活:



from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline

model_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(
vae=stable_diffusion_txt2img.vae,
text_encoder=stable_diffusion_txt2img.text_encoder,
tokenizer=stable_diffusion_txt2img.tokenizer,
unet=stable_diffusion_txt2img.unet,
scheduler=stable_diffusion_txt2img.scheduler,
safety_checker=None,
feature_extractor=None,
requires_safety_checker=False,
)


**1.5 checkpoint variants**


以torch.float16保存,节省一半的内存,但是无法训练,EMA不用于推理,用于微调模型。


**2. models**



from diffusers import UNet2DConditionModel

repo_id = “runwayml/stable-diffusion-v1-5”
model = UNet2DConditionModel.from_pretrained(repo_id, subfolder=“unet”, use_safetensors=True)


所有的权重都存储在一个safetensors中, 可以用.from\_single\_file()来加载模型。safetensors安全且加载速度快。


**2.1 load different stable diffusion formats**


.ckpt也可以用from\_single\_file(),但最好转成hf格式,可以使用diffusers官方提供的服务转:[https://huggingface.co/spaces/diffusers/sd-to-diffusers]( )


也可以使用脚本转:[https://github.com/huggingface/diffusers/blob/main/scripts/convert\_original\_stable\_diffusion\_to\_diffusers.py]( )



python …/diffusers/scripts/convert_original_stable_diffusion_to_diffusers.py --checkpoint_path temporalnetv3.ckpt --original_config_file cldm_v15.yaml --dump_path ./ --controlnet


 A1111 Lora文件,diffusers可以使用[load\_lora\_weights()]( )")加载lora模型:



from diffusers import DiffusionPipeline, UniPCMultistepScheduler
import torch

pipeline = DiffusionPipeline.from_pretrained(
“andite/anything-v4.0”, torch_dtype=torch.float16, safety_checker=None
).to(“cuda”)
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config)

uncomment to download the safetensor weights

#!wget https://civitai.com/api/download/models/19998 -O howls_moving_castle.safetensors

pipeline.load_lora_weights(“.”, weight_name=“howls_moving_castle.safetensors”)

prompt = “masterpiece, illustration, ultra-detailed, cityscape, san francisco, golden gate bridge, california, bay area, in the snow, beautiful detailed starry sky”
negative_prompt = “lowres, cropped, worst quality, low quality, normal quality, artifacts, signature, watermark, username, blurry, more than one bridge, bad architecture”

images = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
width=512,
height=512,
num_inference_steps=25,
num_images_per_prompt=4,
generator=torch.manual_seed(0),
).images

from diffusers.utils import make_image_grid

make_image_grid(images, 2, 2)


**3.scheduler**


scheduler没有参数化或训练;由配置文件定义。加载scheduler不会消耗大的内存,并且相同的配置文件可以用于各种不同的scheduler,比如下面的scheduler均可与StableDiffusionPipline兼容。


Diffusion流程本质上是由扩散模型和scheduler组成的集合,它们在一定程度上彼此独立。这意味着可以替换流程的某些部分,其中最好的例子就是scheduler。扩散模型通常只定义从噪声到较少噪声样本的前向传递过程,而调度器定义了整个去噪过程,包括:


去噪步骤是多少?随机的还是确定性的?用什么算法找到去噪样本? 调度器可以非常复杂,并且经常在去噪速度和去噪质量之间进行权衡。



from diffusers import StableDiffusionPipeline
from diffusers import (
DDPMScheduler,
DDIMScheduler,
PNDMScheduler,

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)
diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors,2024年程序员学习,java,开发语言

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!文章来源地址https://www.toymoban.com/news/detail-859917.html

知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)
[外链图片转存中…(img-P82PmwJ4-1713279392977)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

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

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

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

相关文章

  • 运行StableDiffusionInpaintPipeline的Example时报错:OSError: Cannot load model runwayml/stable-diffusion-...

    项目地址: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint 在云服务器端运行下面给出的Example的时候出现报错: 原因是:国内无法服务器无法直接连接上huggingface。 解决办法是:开代理把模型下载到本地再

    2024年03月09日
    浏览(26)
  • 2 Data Streaming Pipelines With Flink and Kafka

    作者:禅与计算机程序设计艺术 数据流是一个连续不断的、产生、存储和处理数据的过程。传统上,数据流编程都是基于特定平台(比如:消息队列,数据仓库,事件溯源)的SDK或者API进行开发,但随着云计算和容器技术的发展,越来越多的企业选择使用开源工具实现自己的

    2024年02月08日
    浏览(44)
  • Streamlining Your Data Pipeline with Databricks and Apache Flink

    大数据技术在过去的几年里发展迅速,成为了企业和组织中不可或缺的一部分。随着数据的规模和复杂性的增加,传统的数据处理技术已经无法满足需求。为了解决这个问题,我们需要一种更高效、可扩展的数据处理框架。 Databricks 和 Apache Flink 是两个非常受欢迎的开源项目

    2024年02月22日
    浏览(46)
  • Stable Diffusion with Diffusers 学习笔记: 原理+完整pipeline代码

    参考链接: https://huggingface.co/blog/stable_diffusion#how-does-stable-diffusion-work 在这篇文章中,我们想展示如何使用Stable Diffusion with the 🧨 Diffusers library,,解释模型是如何工作的,最后深入探讨扩散器是如何允许自定义图像生成pipeline的。 如果你对扩散模型完全陌生,我们建议你阅读

    2024年02月05日
    浏览(42)
  • 扩散模型Diffusers Pipeline API使用介绍

    大部分扩散模型包含多个独立训练的子模型和组件模块组合而成,例如StableDiffusion 有: 3个独立训练的子模型:Autoencoder、 Conditional Unet、CLIP text encoder 调度器组件scheduler, CLIPImageProcessor, safety checker. 为了让开发者以最简单的方式使用最新最先进的扩散模型, diffusers 开发了

    2024年02月08日
    浏览(53)
  • Hugging Face使用Stable diffusion Diffusers Transformers Accelerate Pipelines VAE

    A library that offers an implementation of various diffusion models, including text-to-image models. 提供不同扩散模型的实现的库,代码上最简洁,国内的问题是 huggingface 需要翻墙。 A Hugging Face library that provides pre-trained deep learning models for natural language processing tasks. 提供了预训练深度学习模型,

    2024年02月07日
    浏览(40)
  • docker load and build过程的一些步骤理解

    “docker load” command, the following steps are followed to load an image from a specified tar file to the local image repository: Parsing the tar file: Docker first parses the tar file to check its integrity and verify the format. Extracting the files: If the parsing is successful, Docker will extract the layers of the image and its metadata to a local t

    2024年02月07日
    浏览(27)
  • 论文笔记:RAG VS FINE-TUNING: PIPELINES, TRADEOFFS, AND A CASESTUDY ON AGRICULTURE

    微软24年1月的paper AI在如农业等特定领域的应用仍然有限,这是由于缺乏专门的训练数据 虽然AI已被用来从农业的卫星图像和传感器数据中派生见解,但技术在农民中的采用仍然缓慢 尽管GPT-4和Bing是寻找信息的强大工具,但它们可能不会为有关其作物和家畜的非常具体问题的

    2024年04月09日
    浏览(23)
  • ModuleNotFoundError: No module named ‘models‘解决torch.load问题【天坑】

    当使用torch.load时,报错No module named ‘models’ 在网上查了很多资料说目录结构得和保存时一模一样,话虽如此,但一直没理解要如何一样 最后调试发现,No module named \\\'models’报错说没有models,确实是因为没有. 比如下面: 我训练的用torch.save(model, checkpoint_path)保存的模型文件,那

    2024年02月14日
    浏览(46)
  • ARM汇编【3】:LOAD/STORE MULTIPLE PUSH AND POP

          有时一次加载(或存储)多个值更有效。为此,我们使用LDM(加载多个)和STM(存储多个)。这些指令有一些变化,基本上只在访问初始地址的方式上有所不同。这是我们将在本节中使用的代码。我们将一步一步地研究每一条指令。         在开始之前,请记住.字指

    2024年02月11日
    浏览(25)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包