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
f8c59310
Commit
f8c59310
authored
Jun 12, 2023
by
comfyanonymous
Browse files
Split the batch in VAEEncode if there's not enough memory.
parent
c069fc07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
1 deletion
+4
-1
comfy/sd.py
comfy/sd.py
+4
-1
No files found.
comfy/sd.py
View file @
f8c59310
...
...
@@ -589,11 +589,14 @@ class VAE:
self
.
first_stage_model
=
self
.
first_stage_model
.
to
(
self
.
device
)
pixel_samples
=
pixel_samples
.
movedim
(
-
1
,
1
)
try
:
batch_number
=
1
free_memory
=
model_management
.
get_free_memory
(
self
.
device
)
batch_number
=
int
((
free_memory
*
0.7
)
/
(
2078
*
pixel_samples
.
shape
[
2
]
*
pixel_samples
.
shape
[
3
]))
#NOTE: this constant along with the one in the decode above are estimated from the mem usage for the VAE and could change.
batch_number
=
max
(
1
,
batch_number
)
samples
=
torch
.
empty
((
pixel_samples
.
shape
[
0
],
4
,
round
(
pixel_samples
.
shape
[
2
]
//
8
),
round
(
pixel_samples
.
shape
[
3
]
//
8
)),
device
=
"cpu"
)
for
x
in
range
(
0
,
pixel_samples
.
shape
[
0
],
batch_number
):
pixels_in
=
(
2.
*
pixel_samples
[
x
:
x
+
batch_number
]
-
1.
).
to
(
self
.
device
)
samples
[
x
:
x
+
batch_number
]
=
self
.
first_stage_model
.
encode
(
pixels_in
).
sample
().
cpu
()
*
self
.
scale_factor
except
model_management
.
OOM_EXCEPTION
as
e
:
print
(
"Warning: Ran out of memory when regular VAE encoding, retrying with tiled VAE encoding."
)
samples
=
self
.
encode_tiled_
(
pixel_samples
)
...
...
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