Skip to content

Commit

Permalink
Override calc_cond_uncond_batch only when we call it
Browse files Browse the repository at this point in the history
This allows compatibility with other forge extensions like
self-attention guidance that call the function outside of
the normal context.
  • Loading branch information
wbclark committed Mar 26, 2024
1 parent a69fe5c commit 5b20b41
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib_neutral_prompt/cfg_denoiser_hijack.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,17 @@ def visit_composite_prompt(

@samplers_hijacker.hijack('calc_cond_uncond_batch')
def calc_cond_uncond_batch(model, cond, uncond, x_in, timestep, model_options, original_function):
if not global_state.is_enabled:
try:
cond_composition = model_options['cond_composition']
original_strengths = model_options['original_strengths']
del model_options['cond_composition']
del model_options['original_strengths']
if uncond is None:
uncond = model_options['uncond']
del model_options['uncond']
except KeyError:
return original_function(model, cond, uncond, x_in, timestep, model_options)

cond_composition = model_options['cond_composition']
original_strengths = model_options['original_strengths']
if uncond is None:
uncond = model_options['uncond']

for i in range(len(cond)):
cond[i]['strength'] = original_strengths[i]

Expand Down

0 comments on commit 5b20b41

Please sign in to comment.