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
a45df695
Commit
a45df695
authored
Jun 17, 2024
by
comfyanonymous
Browse files
Basic tiled decoding for audio VAE.
parent
379ff92e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
comfy/sd.py
comfy/sd.py
+15
-1
No files found.
comfy/sd.py
View file @
a45df695
...
...
@@ -298,6 +298,17 @@ class VAE:
/
3.0
)
return
output
def
decode_tiled_1d
(
self
,
samples
,
tile_x
=
128
,
overlap
=
64
):
output
=
torch
.
empty
((
samples
.
shape
[
0
],
self
.
output_channels
)
+
tuple
(
map
(
lambda
a
:
a
*
self
.
upscale_ratio
,
samples
.
shape
[
2
:])),
device
=
self
.
output_device
)
for
j
in
range
(
samples
.
shape
[
0
]):
for
i
in
range
(
0
,
samples
.
shape
[
-
1
],
tile_x
-
overlap
):
f
=
i
t
=
i
+
tile_x
output
[
j
:
j
+
1
,:,
f
*
self
.
upscale_ratio
:
t
*
self
.
upscale_ratio
]
=
self
.
first_stage_model
.
decode
(
samples
[
j
:
j
+
1
,:,
f
:
t
].
to
(
self
.
vae_dtype
).
to
(
self
.
device
)).
float
()
return
output
def
encode_tiled_
(
self
,
pixel_samples
,
tile_x
=
512
,
tile_y
=
512
,
overlap
=
64
):
steps
=
pixel_samples
.
shape
[
0
]
*
comfy
.
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
,
tile_y
,
overlap
)
steps
+=
pixel_samples
.
shape
[
0
]
*
comfy
.
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
//
2
,
tile_y
*
2
,
overlap
)
...
...
@@ -325,6 +336,9 @@ class VAE:
pixel_samples
[
x
:
x
+
batch_number
]
=
self
.
process_output
(
self
.
first_stage_model
.
decode
(
samples
).
to
(
self
.
output_device
).
float
())
except
model_management
.
OOM_EXCEPTION
as
e
:
logging
.
warning
(
"Warning: Ran out of memory when regular VAE decoding, retrying with tiled VAE decoding."
)
if
len
(
samples_in
.
shape
)
==
3
:
pixel_samples
=
self
.
decode_tiled_1d
(
samples_in
)
else
:
pixel_samples
=
self
.
decode_tiled_
(
samples_in
)
pixel_samples
=
pixel_samples
.
to
(
self
.
output_device
).
movedim
(
1
,
-
1
)
...
...
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