Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
6fc49176
Commit
6fc49176
authored
May 06, 2023
by
comfyanonymous
Browse files
Make maximum_batch_area take into account python2.0 attention function.
More conservative xformers maximum_batch_area.
parent
678f933d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
comfy/model_management.py
comfy/model_management.py
+11
-2
No files found.
comfy/model_management.py
View file @
6fc49176
...
@@ -275,8 +275,17 @@ def xformers_enabled_vae():
...
@@ -275,8 +275,17 @@ def xformers_enabled_vae():
return
XFORMERS_ENABLED_VAE
return
XFORMERS_ENABLED_VAE
def
pytorch_attention_enabled
():
def
pytorch_attention_enabled
():
global
ENABLE_PYTORCH_ATTENTION
return
ENABLE_PYTORCH_ATTENTION
return
ENABLE_PYTORCH_ATTENTION
def
pytorch_attention_flash_attention
():
global
ENABLE_PYTORCH_ATTENTION
if
ENABLE_PYTORCH_ATTENTION
:
#TODO: more reliable way of checking for flash attention?
if
torch
.
version
.
cuda
:
#pytorch flash attention only works on Nvidia
return
True
return
False
def
get_free_memory
(
dev
=
None
,
torch_free_too
=
False
):
def
get_free_memory
(
dev
=
None
,
torch_free_too
=
False
):
global
xpu_available
global
xpu_available
global
directml_enabled
global
directml_enabled
...
@@ -312,9 +321,9 @@ def maximum_batch_area():
...
@@ -312,9 +321,9 @@ def maximum_batch_area():
return
0
return
0
memory_free
=
get_free_memory
()
/
(
1024
*
1024
)
memory_free
=
get_free_memory
()
/
(
1024
*
1024
)
if
xformers_enabled
():
if
xformers_enabled
()
or
pytorch_attention_flash_attention
()
:
#TODO: this needs to be tweaked
#TODO: this needs to be tweaked
area
=
5
0
*
memory_free
area
=
2
0
*
memory_free
else
:
else
:
#TODO: this formula is because AMD sucks and has memory management issues which might be fixed in the future
#TODO: this formula is because AMD sucks and has memory management issues which might be fixed in the future
area
=
((
memory_free
-
1024
)
*
0.9
)
/
(
0.6
)
area
=
((
memory_free
-
1024
)
*
0.9
)
/
(
0.6
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment