【深度学习】sdwebui A1111 加速方案对比,xformers vs Flash Attention 2

本文主要是介绍【深度学习】sdwebui A1111 加速方案对比,xformers vs Flash Attention 2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 资料支撑
  • 资料结论
  • sdwebui A1111 速度对比测试
  • sdxl
    • xformers 用contorlnet sdxl
    • sdpa(--opt-sdp-no-mem-attention) 用contorlnet sdxl
    • sdpa(--opt-sdp-attention) 用contorlnet sdxl
    • 不用xformers或者sdpa ,用contorlnet sdxl
    • 不用xformers或者sdpa 纯生图 sdxl
    • 用sdpa 纯生图 不用contorlnet 生图时间
  • sd1.5
    • 不用xformers或者sdpa sd1.5+hirefix2倍 纯生图512
    • 用sdpa sd1.5+hirefix2倍 纯生图512
    • 不用xformers或者sdpa sd1.5 纯生图512
    • 用sdpa sd1.5 纯生图512
    • 其他速度
  • 结论

资料支撑

xformers中可以使用Flashv2
https://github.com/facebookresearch/xformers/issues/795
https://github.com/vllm-project/vllm/issues/485
https://github.com/facebookresearch/xformers/issues/832

PyTorch 支持 Flash Attention 2。
Flash Attention 2 是 Flash Attention 的改进版本,它提供了更高的性能和更好的并行性。它于 2023 年 11 月发布,并被集成到 PyTorch 2.2 中。
PyTorch 2.2 于 2024 年 2 月发布,它包含以下与 Flash Attention 2 相关的更新:

  • 将 Flash Attention 内核更新到 v2 版本
  • 支持 aarch64 平台上的 Flash Attention 2
  • 修复了 Flash Attention 2 中的一些已知问题
    要使用 Flash Attention 2,您需要安装 PyTorch 2.2 或更高版本。您还可以使用 torch.nn.functional.flash_attn() 函数显式调用 Flash Attention 2。
    以下是一些有关如何使用 Flash Attention 2 的资源:
  • PyTorch 文档:https://discuss.pytorch.org/t/flash-attention/174955
  • Flash Attention 2 论文:https://arxiv.org/abs/2307.08691
  • Flash Attention 2 GitHub 存储库:https://github.com/Dao-AILab/flash-attention
    https://github.com/pytorch/pytorch/pull/105602
    更新日志:https://pytorch.org/blog/pytorch2-2/
    https://pytorch.org/docs/2.2/generated/torch.nn.functional.scaled_dot_product_attention.html
    Triton 内核
    https://pytorch.org/blog/pytorch2-3/

SDPA vs. xformers
https://github.com/huggingface/diffusers/issues/3793
F.scaled_dot_product_attention() 是pytorch的SDPA
xformers.ops.memory_efficient_attention是xformer的对应算子
https://github.com/lucidrains/memory-efficient-attention-pytorch/blob/main/memory_efficient_attention_pytorch/memory_efficient_attention.py

https://github.com/facebookresearch/xformers/issues/950
在这里插入图片描述

sdwebui支持SDP:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/8367
https://qq742971636.blog.csdn.net/article/details/139772822
sdp 注意力机制与 xformers 相当,甚至略胜一筹:
[图片]

pytorch 2.0的注意力是Flash Attention 1
https://pytorch.org/docs/2.0/generated/torch.nn.functional.scaled_dot_product_attention.html
pytorch 2.2的注意力是Flash Attention 2
https://pytorch.org/docs/2.2/generated/torch.nn.functional.scaled_dot_product_attention.html

资料结论

pytorch2.2版本的 F.scaled_dot_product_attention() 即是Flash Attention 2

xformers 中新版本已经有类似实现。

sdwebui A1111 速度对比测试

参数含义看这里:
https://qq742971636.blog.csdn.net/article/details/139772822

使用ipadapter contorlnet

pytorch2.3+xformers 0.25

25轮

In a snowy mountain range, the young man is dressed in winter attire, facing the camera with a determined gaze. He sports a thick wool coat, knit hat, and gloves to keep warm in the frigid temperatures. His eyes, piercing and resolute, reflect the strength and resolve needed to conquer the elements and the challenging terrain.

paintings, sketches, worst quality, low quality, normal quality, lowres, blurry, text, logo, monochrome, grayscale, skin spots, acnes, skin blemishes, age spot, strabismus, wrong finger, bad anatomy, bad hands, error, missing fingers, cropped, jpeg artifacts, signature, watermark, username, dark skin, fused girls, fushion, bad feet, ugly, pregnant, vore, duplicate, morbid, mutilated, transexual, hermaphrodite, long neck, mutated hands, poorly drawn face, mutation, deformed, bad proportions, malformed limbs, extra limbs, cloned face, disfigured, gross proportions, missing arms, missing legs, extra arms, extra legs, plump, open mouth, tooth, teeth, nsfw,

sdxl

xformers 用contorlnet sdxl

xformers:

./webui.sh --enable-insecure-extension-access --skip-python-version-check --skip-torch-cuda-test  --listen --port 7860 --no-download-sd-model --api --no-half-vae --xformers

速度:

Time taken: 11.5 sec.

A: 13.29 GB, R: 16.77 GB, Sys: 18.5/39.3945 GB (47.0%)

sdpa(–opt-sdp-no-mem-attention) 用contorlnet sdxl

sdpa

./webui.sh --enable-insecure-extension-access --skip-python-version-check --skip-torch-cuda-test  --listen --port 7860 --no-download-sd-model --api --no-half-vae --opt-sdp-no-mem-attention

Time taken: 11.1 sec.

A: 13.29 GB, R: 14.81 GB, Sys: 16.6/39.3945 GB (42.1%)

sdpa(–opt-sdp-attention) 用contorlnet sdxl

sdpa

./webui.sh --enable-insecure-extension-access --skip-python-version-check --skip-torch-cuda-test  --listen --port 7860 --no-download-sd-model --api --no-half-vae --opt-sdp-attention

Time taken: 11.4 sec.

A: 13.29 GB, R: 14.81 GB, Sys: 16.6/39.3945 GB (42.1%)

不用xformers或者sdpa ,用contorlnet sdxl

Time taken: 13.3 sec.

A: 13.28 GB, R: 15.39 GB, Sys: 17.1/39.3945 GB (43.5%)

不用xformers或者sdpa 纯生图 sdxl

Time taken: 10.1 sec.

A: 10.27 GB, R: 12.45 GB, Sys: 13.0/39.3945 GB (33.0%)

用sdpa 纯生图 不用contorlnet 生图时间

Time taken: 6.7 sec.

A: 10.29 GB, R: 11.89 GB, Sys: 12.5/39.3945 GB (31.7%)

sd1.5

不用xformers或者sdpa sd1.5+hirefix2倍 纯生图512

Time taken: 10.7 sec.

A: 10.37 GB, R: 10.49 GB, Sys: 11.1/39.3945 GB (28.1%)

用sdpa sd1.5+hirefix2倍 纯生图512

Time taken: 6.2 sec.

A: 5.75 GB, R: 7.05 GB, Sys: 7.7/39.3945 GB (19.4%)

不用xformers或者sdpa sd1.5 纯生图512

Time taken: 3.1 sec.

A: 3.11 GB, R: 3.46 GB, Sys: 3.4/39.3945 GB (8.6%)

用sdpa sd1.5 纯生图512

Time taken: 2.3 sec.

A: 3.13 GB, R: 4.07 GB, Sys: 3.7/39.3945 GB (9.3%)

其他速度

写真四张图A100:时间: 50.00366139411926

写真,A10,1张图,生图换脸一套时间,25秒
写真,A10,2张图,生图换脸一套时间,46秒

aicy生图,不计算llm时间为,3.3秒
aicy生图,计算llm时间为,5.2秒

结论

新版的xformers 、Flash Attention 2、Pytorch 的速度都差不多。安装pytorch 2.2以上,启用sdpa(–opt-sdp-no-mem-attention,就可以不用安装xformers 了。

这篇关于【深度学习】sdwebui A1111 加速方案对比,xformers vs Flash Attention 2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1077067

相关文章

51单片机学习记录———定时器

文章目录 前言一、定时器介绍二、STC89C52定时器资源三、定时器框图四、定时器模式五、定时器相关寄存器六、定时器练习 前言 一个学习嵌入式的小白~ 有问题评论区或私信指出~ 提示:以下是本篇文章正文内容,下面案例可供参考 一、定时器介绍 定时器介绍:51单片机的定时器属于单片机的内部资源,其电路的连接和运转均在单片机内部完成。 定时器作用: 1.用于计数系统,可

问题:第一次世界大战的起止时间是 #其他#学习方法#微信

问题:第一次世界大战的起止时间是 A.1913 ~1918 年 B.1913 ~1918 年 C.1914 ~1918 年 D.1914 ~1919 年 参考答案如图所示

[word] word设置上标快捷键 #学习方法#其他#媒体

word设置上标快捷键 办公中,少不了使用word,这个是大家必备的软件,今天给大家分享word设置上标快捷键,希望在办公中能帮到您! 1、添加上标 在录入一些公式,或者是化学产品时,需要添加上标内容,按下快捷键Ctrl+shift++就能将需要的内容设置为上标符号。 word设置上标快捷键的方法就是以上内容了,需要的小伙伴都可以试一试呢!

AssetBundle学习笔记

AssetBundle是unity自定义的资源格式,通过调用引擎的资源打包接口对资源进行打包成.assetbundle格式的资源包。本文介绍了AssetBundle的生成,使用,加载,卸载以及Unity资源更新的一个基本步骤。 目录 1.定义: 2.AssetBundle的生成: 1)设置AssetBundle包的属性——通过编辑器界面 补充:分组策略 2)调用引擎接口API

Javascript高级程序设计(第四版)--学习记录之变量、内存

原始值与引用值 原始值:简单的数据即基础数据类型,按值访问。 引用值:由多个值构成的对象即复杂数据类型,按引用访问。 动态属性 对于引用值而言,可以随时添加、修改和删除其属性和方法。 let person = new Object();person.name = 'Jason';person.age = 42;console.log(person.name,person.age);//'J

大学湖北中医药大学法医学试题及答案,分享几个实用搜题和学习工具 #微信#学习方法#职场发展

今天分享拥有拍照搜题、文字搜题、语音搜题、多重搜题等搜题模式,可以快速查找问题解析,加深对题目答案的理解。 1.快练题 这是一个网站 找题的网站海量题库,在线搜题,快速刷题~为您提供百万优质题库,直接搜索题库名称,支持多种刷题模式:顺序练习、语音听题、本地搜题、顺序阅读、模拟考试、组卷考试、赶快下载吧! 2.彩虹搜题 这是个老公众号了 支持手写输入,截图搜题,详细步骤,解题必备

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

《offer来了》第二章学习笔记

1.集合 Java四种集合:List、Queue、Set和Map 1.1.List:可重复 有序的Collection ArrayList: 基于数组实现,增删慢,查询快,线程不安全 Vector: 基于数组实现,增删慢,查询快,线程安全 LinkedList: 基于双向链实现,增删快,查询慢,线程不安全 1.2.Queue:队列 ArrayBlockingQueue:

十五.各设计模式总结与对比

1.各设计模式总结与对比 1.1.课程目标 1、 简要分析GoF 23种设计模式和设计原则,做整体认知。 2、 剖析Spirng的编程思想,启发思维,为之后深入学习Spring做铺垫。 3、 了解各设计模式之间的关联,解决设计模式混淆的问题。 1.2.内容定位 1、 掌握设计模式的"道" ,而不只是"术" 2、 道可道非常道,滴水石穿非一日之功,做好长期修炼的准备。 3、 不要为了

Windwos +vs 2022 编译openssl 1.0.2 库

一 前言 先说 结论,编译64位报错,查了一圈没找到解决方案,最后换了32位的。 使用qt访问web接口,因为是https,没有openssl库会报错 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());if (reply){if (reply->error() == QNetworkReply::NoError