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
a2ce9655
Commit
a2ce9655
authored
Aug 14, 2023
by
comfyanonymous
Browse files
Refactor unclip code.
parent
94fceb87
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
25 deletions
+26
-25
comfy/model_base.py
comfy/model_base.py
+26
-25
No files found.
comfy/model_base.py
View file @
a2ce9655
...
...
@@ -105,17 +105,7 @@ class BaseModel(torch.nn.Module):
return
{
**
unet_state_dict
,
**
vae_state_dict
,
**
clip_state_dict
}
class
SD21UNCLIP
(
BaseModel
):
def
__init__
(
self
,
model_config
,
noise_aug_config
,
model_type
=
ModelType
.
V_PREDICTION
,
device
=
None
):
super
().
__init__
(
model_config
,
model_type
,
device
=
device
)
self
.
noise_augmentor
=
CLIPEmbeddingNoiseAugmentation
(
**
noise_aug_config
)
def
encode_adm
(
self
,
**
kwargs
):
unclip_conditioning
=
kwargs
.
get
(
"unclip_conditioning"
,
None
)
device
=
kwargs
[
"device"
]
if
unclip_conditioning
is
not
None
:
def
unclip_adm
(
unclip_conditioning
,
device
,
noise_augmentor
,
noise_augment_merge
=
0.0
):
adm_inputs
=
[]
weights
=
[]
noise_aug
=
[]
...
...
@@ -123,8 +113,8 @@ class SD21UNCLIP(BaseModel):
for
adm_cond
in
unclip_cond
[
"clip_vision_output"
].
image_embeds
:
weight
=
unclip_cond
[
"strength"
]
noise_augment
=
unclip_cond
[
"noise_augmentation"
]
noise_level
=
round
((
self
.
noise_augmentor
.
max_noise_level
-
1
)
*
noise_augment
)
c_adm
,
noise_level_emb
=
self
.
noise_augmentor
(
adm_cond
.
to
(
device
),
noise_level
=
torch
.
tensor
([
noise_level
],
device
=
device
))
noise_level
=
round
((
noise_augmentor
.
max_noise_level
-
1
)
*
noise_augment
)
c_adm
,
noise_level_emb
=
noise_augmentor
(
adm_cond
.
to
(
device
),
noise_level
=
torch
.
tensor
([
noise_level
],
device
=
device
))
adm_out
=
torch
.
cat
((
c_adm
,
noise_level_emb
),
1
)
*
weight
weights
.
append
(
weight
)
noise_aug
.
append
(
noise_augment
)
...
...
@@ -132,16 +122,27 @@ class SD21UNCLIP(BaseModel):
if
len
(
noise_aug
)
>
1
:
adm_out
=
torch
.
stack
(
adm_inputs
).
sum
(
0
)
#TODO: add a way to control this
noise_augment
=
0.05
noise_level
=
round
((
self
.
noise_augmentor
.
max_noise_level
-
1
)
*
noise_augment
)
c_adm
,
noise_level_emb
=
self
.
noise_augmentor
(
adm_out
[:,
:
self
.
noise_augmentor
.
time_embed
.
dim
],
noise_level
=
torch
.
tensor
([
noise_level
],
device
=
device
))
noise_augment
=
noise_augment_merge
noise_level
=
round
((
noise_augmentor
.
max_noise_level
-
1
)
*
noise_augment
)
c_adm
,
noise_level_emb
=
noise_augmentor
(
adm_out
[:,
:
noise_augmentor
.
time_embed
.
dim
],
noise_level
=
torch
.
tensor
([
noise_level
],
device
=
device
))
adm_out
=
torch
.
cat
((
c_adm
,
noise_level_emb
),
1
)
else
:
adm_out
=
torch
.
zeros
((
1
,
self
.
adm_channels
))
return
adm_out
class
SD21UNCLIP
(
BaseModel
):
def
__init__
(
self
,
model_config
,
noise_aug_config
,
model_type
=
ModelType
.
V_PREDICTION
,
device
=
None
):
super
().
__init__
(
model_config
,
model_type
,
device
=
device
)
self
.
noise_augmentor
=
CLIPEmbeddingNoiseAugmentation
(
**
noise_aug_config
)
def
encode_adm
(
self
,
**
kwargs
):
unclip_conditioning
=
kwargs
.
get
(
"unclip_conditioning"
,
None
)
device
=
kwargs
[
"device"
]
if
unclip_conditioning
is
None
:
return
torch
.
zeros
((
1
,
self
.
adm_channels
))
else
:
return
unclip_adm
(
unclip_conditioning
,
device
,
self
.
noise_augmentor
,
kwargs
.
get
(
"unclip_noise_augment_merge"
,
0.05
))
class
SDInpaint
(
BaseModel
):
def
__init__
(
self
,
model_config
,
model_type
=
ModelType
.
EPS
,
device
=
None
):
super
().
__init__
(
model_config
,
model_type
,
device
=
device
)
...
...
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