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
2395ae74
Commit
2395ae74
authored
Jan 14, 2024
by
comfyanonymous
Browse files
Make unclip more deterministic.
Pass a seed argument note that this might make old unclip images different.
parent
270daa02
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
comfy/ldm/modules/encoders/noise_aug_modules.py
comfy/ldm/modules/encoders/noise_aug_modules.py
+2
-2
comfy/model_base.py
comfy/model_base.py
+4
-4
No files found.
comfy/ldm/modules/encoders/noise_aug_modules.py
View file @
2395ae74
...
@@ -23,13 +23,13 @@ class CLIPEmbeddingNoiseAugmentation(ImageConcatWithNoiseAugmentation):
...
@@ -23,13 +23,13 @@ class CLIPEmbeddingNoiseAugmentation(ImageConcatWithNoiseAugmentation):
x
=
(
x
*
self
.
data_std
.
to
(
x
.
device
))
+
self
.
data_mean
.
to
(
x
.
device
)
x
=
(
x
*
self
.
data_std
.
to
(
x
.
device
))
+
self
.
data_mean
.
to
(
x
.
device
)
return
x
return
x
def
forward
(
self
,
x
,
noise_level
=
None
):
def
forward
(
self
,
x
,
noise_level
=
None
,
seed
=
None
):
if
noise_level
is
None
:
if
noise_level
is
None
:
noise_level
=
torch
.
randint
(
0
,
self
.
max_noise_level
,
(
x
.
shape
[
0
],),
device
=
x
.
device
).
long
()
noise_level
=
torch
.
randint
(
0
,
self
.
max_noise_level
,
(
x
.
shape
[
0
],),
device
=
x
.
device
).
long
()
else
:
else
:
assert
isinstance
(
noise_level
,
torch
.
Tensor
)
assert
isinstance
(
noise_level
,
torch
.
Tensor
)
x
=
self
.
scale
(
x
)
x
=
self
.
scale
(
x
)
z
=
self
.
q_sample
(
x
,
noise_level
)
z
=
self
.
q_sample
(
x
,
noise_level
,
seed
=
seed
)
z
=
self
.
unscale
(
z
)
z
=
self
.
unscale
(
z
)
noise_level
=
self
.
time_embed
(
noise_level
)
noise_level
=
self
.
time_embed
(
noise_level
)
return
z
,
noise_level
return
z
,
noise_level
comfy/model_base.py
View file @
2395ae74
...
@@ -210,7 +210,7 @@ class BaseModel(torch.nn.Module):
...
@@ -210,7 +210,7 @@ class BaseModel(torch.nn.Module):
return
(((
area
*
0.6
)
/
0.9
)
+
1024
)
*
(
1024
*
1024
)
return
(((
area
*
0.6
)
/
0.9
)
+
1024
)
*
(
1024
*
1024
)
def
unclip_adm
(
unclip_conditioning
,
device
,
noise_augmentor
,
noise_augment_merge
=
0.0
):
def
unclip_adm
(
unclip_conditioning
,
device
,
noise_augmentor
,
noise_augment_merge
=
0.0
,
seed
=
None
):
adm_inputs
=
[]
adm_inputs
=
[]
weights
=
[]
weights
=
[]
noise_aug
=
[]
noise_aug
=
[]
...
@@ -219,7 +219,7 @@ def unclip_adm(unclip_conditioning, device, noise_augmentor, noise_augment_merge
...
@@ -219,7 +219,7 @@ def unclip_adm(unclip_conditioning, device, noise_augmentor, noise_augment_merge
weight
=
unclip_cond
[
"strength"
]
weight
=
unclip_cond
[
"strength"
]
noise_augment
=
unclip_cond
[
"noise_augmentation"
]
noise_augment
=
unclip_cond
[
"noise_augmentation"
]
noise_level
=
round
((
noise_augmentor
.
max_noise_level
-
1
)
*
noise_augment
)
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
))
c_adm
,
noise_level_emb
=
noise_augmentor
(
adm_cond
.
to
(
device
),
noise_level
=
torch
.
tensor
([
noise_level
],
device
=
device
)
,
seed
=
seed
)
adm_out
=
torch
.
cat
((
c_adm
,
noise_level_emb
),
1
)
*
weight
adm_out
=
torch
.
cat
((
c_adm
,
noise_level_emb
),
1
)
*
weight
weights
.
append
(
weight
)
weights
.
append
(
weight
)
noise_aug
.
append
(
noise_augment
)
noise_aug
.
append
(
noise_augment
)
...
@@ -245,11 +245,11 @@ class SD21UNCLIP(BaseModel):
...
@@ -245,11 +245,11 @@ class SD21UNCLIP(BaseModel):
if
unclip_conditioning
is
None
:
if
unclip_conditioning
is
None
:
return
torch
.
zeros
((
1
,
self
.
adm_channels
))
return
torch
.
zeros
((
1
,
self
.
adm_channels
))
else
:
else
:
return
unclip_adm
(
unclip_conditioning
,
device
,
self
.
noise_augmentor
,
kwargs
.
get
(
"unclip_noise_augment_merge"
,
0.05
))
return
unclip_adm
(
unclip_conditioning
,
device
,
self
.
noise_augmentor
,
kwargs
.
get
(
"unclip_noise_augment_merge"
,
0.05
)
,
kwargs
.
get
(
"seed"
,
0
)
-
10
)
def
sdxl_pooled
(
args
,
noise_augmentor
):
def
sdxl_pooled
(
args
,
noise_augmentor
):
if
"unclip_conditioning"
in
args
:
if
"unclip_conditioning"
in
args
:
return
unclip_adm
(
args
.
get
(
"unclip_conditioning"
,
None
),
args
[
"device"
],
noise_augmentor
)[:,:
1280
]
return
unclip_adm
(
args
.
get
(
"unclip_conditioning"
,
None
),
args
[
"device"
],
noise_augmentor
,
seed
=
args
.
get
(
"seed"
,
0
)
-
10
)[:,:
1280
]
else
:
else
:
return
args
[
"pooled_output"
]
return
args
[
"pooled_output"
]
...
...
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