Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
C
ComfyUI
管理
动态
成员
代码
仓库
分支
提交
标签
仓库图
比较修订版本
锁定的文件
部署
模型注册表
分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
Show more breadcrumbs
hanamizuki
ComfyUI
提交
c1f5855a
提交
c1f5855a
编辑于
2年前
作者:
comfyanonymous
浏览文件
操作
下载
补丁
差异文件
Make some cross attention functions work on the CPU.
上级
1a612e1c
No related branches found
分支 包含提交
No related tags found
标签 包含提交
加载中
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
comfy/ldm/modules/attention.py
+5
-12
5 个添加, 12 个删除
comfy/ldm/modules/attention.py
comfy/model_management.py
+19
-8
19 个添加, 8 个删除
comfy/model_management.py
有
24 个添加
和
20 个删除
comfy/ldm/modules/attention.py
+
5
−
12
浏览文件 @
c1f5855a
...
...
@@ -9,6 +9,8 @@ from typing import Optional, Any
from
ldm.modules.diffusionmodules.util
import
checkpoint
from
.sub_quadratic_attention
import
efficient_dot_product_attention
import
model_management
try
:
import
xformers
import
xformers.ops
...
...
@@ -189,12 +191,8 @@ class CrossAttentionBirchSan(nn.Module):
_
,
_
,
k_tokens
=
key_t
.
shape
qk_matmul_size_bytes
=
batch_x_heads
*
bytes_per_token
*
q_tokens
*
k_tokens
stats
=
torch
.
cuda
.
memory_stats
(
query
.
device
)
mem_active
=
stats
[
'
active_bytes.all.current
'
]
mem_reserved
=
stats
[
'
reserved_bytes.all.current
'
]
mem_free_cuda
,
_
=
torch
.
cuda
.
mem_get_info
(
torch
.
cuda
.
current_device
())
mem_free_torch
=
mem_reserved
-
mem_active
mem_free_total
=
mem_free_cuda
+
mem_free_torch
mem_free_total
,
mem_free_torch
=
model_management
.
get_free_memory
(
query
.
device
,
True
)
chunk_threshold_bytes
=
mem_free_torch
*
0.5
#Using only this seems to work better on AMD
kv_chunk_size_min
=
None
...
...
@@ -276,12 +274,7 @@ class CrossAttentionDoggettx(nn.Module):
r1
=
torch
.
zeros
(
q
.
shape
[
0
],
q
.
shape
[
1
],
v
.
shape
[
2
],
device
=
q
.
device
)
stats
=
torch
.
cuda
.
memory_stats
(
q
.
device
)
mem_active
=
stats
[
'
active_bytes.all.current
'
]
mem_reserved
=
stats
[
'
reserved_bytes.all.current
'
]
mem_free_cuda
,
_
=
torch
.
cuda
.
mem_get_info
(
torch
.
cuda
.
current_device
())
mem_free_torch
=
mem_reserved
-
mem_active
mem_free_total
=
mem_free_cuda
+
mem_free_torch
mem_free_total
=
model_management
.
get_free_memory
(
q
.
device
)
gb
=
1024
**
3
tensor_size
=
q
.
shape
[
0
]
*
q
.
shape
[
1
]
*
k
.
shape
[
1
]
*
q
.
element_size
()
...
...
This diff is collapsed.
点击以展开。
comfy/model_management.py
+
19
−
8
浏览文件 @
c1f5855a
...
...
@@ -145,14 +145,25 @@ def unload_if_low_vram(model):
return
model
def
get_free_memory
():
dev
=
torch
.
cuda
.
current_device
()
stats
=
torch
.
cuda
.
memory_stats
(
dev
)
mem_active
=
stats
[
'
active_bytes.all.current
'
]
mem_reserved
=
stats
[
'
reserved_bytes.all.current
'
]
mem_free_cuda
,
_
=
torch
.
cuda
.
mem_get_info
(
dev
)
mem_free_torch
=
mem_reserved
-
mem_active
return
mem_free_cuda
+
mem_free_torch
def
get_free_memory
(
dev
=
None
,
torch_free_too
=
False
):
if
dev
is
None
:
dev
=
torch
.
cuda
.
current_device
()
if
hasattr
(
dev
,
'
type
'
)
and
dev
.
type
==
'
cpu
'
:
mem_free_total
=
psutil
.
virtual_memory
().
available
mem_free_torch
=
mem_free_total
else
:
stats
=
torch
.
cuda
.
memory_stats
(
dev
)
mem_active
=
stats
[
'
active_bytes.all.current
'
]
mem_reserved
=
stats
[
'
reserved_bytes.all.current
'
]
mem_free_cuda
,
_
=
torch
.
cuda
.
mem_get_info
(
dev
)
mem_free_torch
=
mem_reserved
-
mem_active
mem_free_total
=
mem_free_cuda
+
mem_free_torch
if
torch_free_too
:
return
(
mem_free_total
,
mem_free_torch
)
else
:
return
mem_free_total
def
maximum_batch_area
():
global
vram_state
...
...
This diff is collapsed.
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录