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
9cad2f06
Commit
9cad2f06
authored
Dec 15, 2023
by
comfyanonymous
Browse files
Make perp neg take a conditioning input instead of a CLIP one.
parent
574363a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
9 deletions
+5
-9
comfy_extras/nodes_perpneg.py
comfy_extras/nodes_perpneg.py
+5
-9
No files found.
comfy_extras/nodes_perpneg.py
View file @
9cad2f06
...
@@ -9,7 +9,7 @@ class PerpNeg:
...
@@ -9,7 +9,7 @@ class PerpNeg:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
s
):
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"model"
:
(
"MODEL"
,
),
return
{
"required"
:
{
"model"
:
(
"MODEL"
,
),
"
clip"
:
(
"CLIP
"
,
),
"
empty_conditioning"
:
(
"CONDITIONING
"
,
),
"neg_scale"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
100.0
}),
"neg_scale"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
100.0
}),
}}
}}
RETURN_TYPES
=
(
"MODEL"
,)
RETURN_TYPES
=
(
"MODEL"
,)
...
@@ -17,13 +17,9 @@ class PerpNeg:
...
@@ -17,13 +17,9 @@ class PerpNeg:
CATEGORY
=
"_for_testing"
CATEGORY
=
"_for_testing"
def
patch
(
self
,
model
,
clip
,
neg_scale
):
def
patch
(
self
,
model
,
empty_conditioning
,
neg_scale
):
m
=
model
.
clone
()
m
=
model
.
clone
()
nocond
=
comfy
.
sample
.
convert_cond
(
empty_conditioning
)
tokens
=
clip
.
tokenize
(
""
)
nocond
,
nocond_pooled
=
clip
.
encode_from_tokens
(
tokens
,
return_pooled
=
True
)
nocond
=
[[
nocond
,
{
"pooled_output"
:
nocond_pooled
}]]
nocond
=
comfy
.
sample
.
convert_cond
(
nocond
)
def
cfg_function
(
args
):
def
cfg_function
(
args
):
model
=
args
[
"model"
]
model
=
args
[
"model"
]
...
@@ -33,9 +29,9 @@ class PerpNeg:
...
@@ -33,9 +29,9 @@ class PerpNeg:
x
=
args
[
"input"
]
x
=
args
[
"input"
]
sigma
=
args
[
"sigma"
]
sigma
=
args
[
"sigma"
]
model_options
=
args
[
"model_options"
]
model_options
=
args
[
"model_options"
]
(
noise_pred_nocond
,
_
)
=
comfy
.
samplers
.
calc_cond_uncond_batch
(
model
,
nocond
,
None
,
x
,
sigma
,
model_options
)
(
noise_pred_nocond
,
_
)
=
comfy
.
samplers
.
calc_cond_uncond_batch
(
model
,
nocond
,
None
,
x
,
sigma
,
model_options
)
pos
=
noise_pred_pos
-
noise_pred_nocond
pos
=
noise_pred_pos
-
noise_pred_nocond
neg
=
noise_pred_neg
-
noise_pred_nocond
neg
=
noise_pred_neg
-
noise_pred_nocond
perp
=
((
torch
.
mul
(
pos
,
neg
).
sum
())
/
(
torch
.
norm
(
neg
)
**
2
))
*
neg
perp
=
((
torch
.
mul
(
pos
,
neg
).
sum
())
/
(
torch
.
norm
(
neg
)
**
2
))
*
neg
...
...
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