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
66c8aa5c
Commit
66c8aa5c
authored
May 02, 2023
by
comfyanonymous
Browse files
Make unet work with any input shape.
parent
a307c3f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
+21
-7
comfy/ldm/modules/diffusionmodules/openaimodel.py
comfy/ldm/modules/diffusionmodules/openaimodel.py
+21
-7
No files found.
comfy/ldm/modules/diffusionmodules/openaimodel.py
View file @
66c8aa5c
...
...
@@ -76,12 +76,14 @@ class TimestepEmbedSequential(nn.Sequential, TimestepBlock):
support it as an extra input.
"""
def
forward
(
self
,
x
,
emb
,
context
=
None
,
transformer_options
=
{}):
def
forward
(
self
,
x
,
emb
,
context
=
None
,
transformer_options
=
{}
,
output_shape
=
None
):
for
layer
in
self
:
if
isinstance
(
layer
,
TimestepBlock
):
x
=
layer
(
x
,
emb
)
elif
isinstance
(
layer
,
SpatialTransformer
):
x
=
layer
(
x
,
context
,
transformer_options
)
elif
isinstance
(
layer
,
Upsample
):
x
=
layer
(
x
,
output_shape
=
output_shape
)
else
:
x
=
layer
(
x
)
return
x
...
...
@@ -105,14 +107,21 @@ class Upsample(nn.Module):
if
use_conv
:
self
.
conv
=
conv_nd
(
dims
,
self
.
channels
,
self
.
out_channels
,
3
,
padding
=
padding
)
def
forward
(
self
,
x
):
def
forward
(
self
,
x
,
output_shape
=
None
):
print
(
"upsample"
,
output_shape
)
assert
x
.
shape
[
1
]
==
self
.
channels
if
self
.
dims
==
3
:
x
=
F
.
interpolate
(
x
,
(
x
.
shape
[
2
],
x
.
shape
[
3
]
*
2
,
x
.
shape
[
4
]
*
2
),
mode
=
"nearest"
)
shape
=
[
x
.
shape
[
2
],
x
.
shape
[
3
]
*
2
,
x
.
shape
[
4
]
*
2
]
if
output_shape
is
not
None
:
shape
[
1
]
=
output_shape
[
3
]
shape
[
2
]
=
output_shape
[
4
]
else
:
x
=
F
.
interpolate
(
x
,
scale_factor
=
2
,
mode
=
"nearest"
)
shape
=
[
x
.
shape
[
2
]
*
2
,
x
.
shape
[
3
]
*
2
]
if
output_shape
is
not
None
:
shape
[
0
]
=
output_shape
[
2
]
shape
[
1
]
=
output_shape
[
3
]
x
=
F
.
interpolate
(
x
,
size
=
shape
,
mode
=
"nearest"
)
if
self
.
use_conv
:
x
=
self
.
conv
(
x
)
return
x
...
...
@@ -813,9 +822,14 @@ class UNetModel(nn.Module):
ctrl
=
control
[
'output'
].
pop
()
if
ctrl
is
not
None
:
hsp
+=
ctrl
h
=
th
.
cat
([
h
,
hsp
],
dim
=
1
)
del
hsp
h
=
module
(
h
,
emb
,
context
,
transformer_options
)
if
len
(
hs
)
>
0
:
output_shape
=
hs
[
-
1
].
shape
else
:
output_shape
=
None
h
=
module
(
h
,
emb
,
context
,
transformer_options
,
output_shape
)
h
=
h
.
type
(
x
.
dtype
)
if
self
.
predict_codebook_ids
:
return
self
.
id_predictor
(
h
)
...
...
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