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

相关文章

Java图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

SpringBoot首笔交易慢问题排查与优化方案

《SpringBoot首笔交易慢问题排查与优化方案》在我们的微服务项目中,遇到这样的问题:应用启动后,第一笔交易响应耗时高达4、5秒,而后续请求均能在毫秒级完成,这不仅触发监控告警,也极大影响了用户体... 目录问题背景排查步骤1. 日志分析2. 性能工具定位优化方案:提前预热各种资源1. Flowable

SpringCloud动态配置注解@RefreshScope与@Component的深度解析

《SpringCloud动态配置注解@RefreshScope与@Component的深度解析》在现代微服务架构中,动态配置管理是一个关键需求,本文将为大家介绍SpringCloud中相关的注解@Re... 目录引言1. @RefreshScope 的作用与原理1.1 什么是 @RefreshScope1.

Java进行文件格式校验的方案详解

《Java进行文件格式校验的方案详解》这篇文章主要为大家详细介绍了Java中进行文件格式校验的相关方案,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、背景异常现象原因排查用户的无心之过二、解决方案Magandroidic Number判断主流检测库对比Tika的使用区分zip

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Python实现Microsoft Office自动化的几种方式及对比详解

《Python实现MicrosoftOffice自动化的几种方式及对比详解》办公自动化是指利用现代化设备和技术,代替办公人员的部分手动或重复性业务活动,优质而高效地处理办公事务,实现对信息的高效利用... 目录一、基于COM接口的自动化(pywin32)二、独立文件操作库1. Word处理(python-d

IDEA中Git版本回退的两种实现方案

《IDEA中Git版本回退的两种实现方案》作为开发者,代码版本回退是日常高频操作,IntelliJIDEA集成了强大的Git工具链,但面对reset和revert两种核心回退方案,许多开发者仍存在选择... 目录一、版本回退前置知识二、Reset方案:整体改写历史1、IDEA图形化操作(推荐)1.1、查看提

Java常用注解扩展对比举例详解

《Java常用注解扩展对比举例详解》:本文主要介绍Java常用注解扩展对比的相关资料,提供了丰富的代码示例,并总结了最佳实践建议,帮助开发者更好地理解和应用这些注解,需要的朋友可以参考下... 目录一、@Controller 与 @RestController 对比二、使用 @Data 与 不使用 @Dat

python中字符串拼接的几种方法及优缺点对比详解

《python中字符串拼接的几种方法及优缺点对比详解》在Python中,字符串拼接是常见的操作,Python提供了多种方法来拼接字符串,每种方法有其优缺点和适用场景,以下是几种常见的字符串拼接方法,需... 目录1. 使用 + 运算符示例:优缺点:2. 使用&nbsjsp;join() 方法示例:优缺点:3

Redis中高并发读写性能的深度解析与优化

《Redis中高并发读写性能的深度解析与优化》Redis作为一款高性能的内存数据库,广泛应用于缓存、消息队列、实时统计等场景,本文将深入探讨Redis的读写并发能力,感兴趣的小伙伴可以了解下... 目录引言一、Redis 并发能力概述1.1 Redis 的读写性能1.2 影响 Redis 并发能力的因素二、