【深度学习】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

相关文章

Python中文件读取操作漏洞深度解析与防护指南

《Python中文件读取操作漏洞深度解析与防护指南》在Web应用开发中,文件操作是最基础也最危险的功能之一,这篇文章将全面剖析Python环境中常见的文件读取漏洞类型,成因及防护方案,感兴趣的小伙伴可... 目录引言一、静态资源处理中的路径穿越漏洞1.1 典型漏洞场景1.2 os.path.join()的陷

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Java实现本地缓存的常用方案介绍

《Java实现本地缓存的常用方案介绍》本地缓存的代表技术主要有HashMap,GuavaCache,Caffeine和Encahche,这篇文章主要来和大家聊聊java利用这些技术分别实现本地缓存的方... 目录本地缓存实现方式HashMapConcurrentHashMapGuava CacheCaffe

Linux中的more 和 less区别对比分析

《Linux中的more和less区别对比分析》在Linux/Unix系统中,more和less都是用于分页查看文本文件的命令,但less是more的增强版,功能更强大,:本文主要介绍Linu... 目录1. 基础功能对比2. 常用操作对比less 的操作3. 实际使用示例4. 为什么推荐 less?5.

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

Spring Boot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)

《SpringBoot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)》:本文主要介绍SpringBoot拦截器Interceptor与过滤器Filter深度解析... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实

利用Python实现可回滚方案的示例代码

《利用Python实现可回滚方案的示例代码》很多项目翻车不是因为不会做,而是走错了方向却没法回头,技术选型失败的风险我们都清楚,但真正能提前规划“回滚方案”的人不多,本文从实际项目出发,教你如何用Py... 目录描述题解答案(核心思路)题解代码分析第一步:抽象缓存接口第二步:实现两个版本第三步:根据 Fea

MyBatis分页插件PageHelper深度解析与实践指南

《MyBatis分页插件PageHelper深度解析与实践指南》在数据库操作中,分页查询是最常见的需求之一,传统的分页方式通常有两种内存分页和SQL分页,MyBatis作为优秀的ORM框架,本身并未提... 目录1. 为什么需要分页插件?2. PageHelper简介3. PageHelper集成与配置3.

SpringBoot实现接口数据加解密的三种实战方案

《SpringBoot实现接口数据加解密的三种实战方案》在金融支付、用户隐私信息传输等场景中,接口数据若以明文传输,极易被中间人攻击窃取,SpringBoot提供了多种优雅的加解密实现方案,本文将从原... 目录一、为什么需要接口数据加解密?二、核心加解密算法选择1. 对称加密(AES)2. 非对称加密(R