Skip to content

Commit

Permalink
debug2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovanm88 committed Aug 20, 2024
1 parent 148c897 commit c043d35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def __init__(self, context_dim, hidden_dim, ip_hidden_states=None, ip_scale=None
self.ip_hidden_states = ip_hidden_states
self.ip_scale = ip_scale
self.neg_hidden_states = None
self.in_hidden_states_pos = None
# Ensure context_dim matches the dimension of ip_hidden_states
self.context_dim = context_dim
self.hidden_dim = hidden_dim
Expand Down
1 change: 1 addition & 0 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ def applymodel(self, model, ip_adapter_flux, image, strength_model):
ipad.load_state_dict(block.state_dict())
ipad.to(dtype=torch.bfloat16)
ipad.neg_hidden_states = ip_neg_pr
ipad.in_hidden_states_pos = ip_projes
npp = DoubleStreamMixerProcessor()
npp.add_ipadapter(ipad)
ipad_blocks.append(npp)
Expand Down
9 changes: 7 additions & 2 deletions sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ def model_forward(
controlnet_depth = len(block_controlnet_hidden_states)
for index_block, block in enumerate(model.double_blocks):
if isinstance(block.processor, DoubleStreamMixerProcessor):
if not neg_mode is None:
if neg_mode:
for ip in block.processor.ip_adapters:
ip.ip_hidden_states = ip.neg_ip_hidden_states
else:
for ip in block.processor.ip_adapters:
ip.ip_hidden_states = ip.in_hidden_states_pos
img, txt = block(img=img, txt=txt, vec=vec, pe=pe)

img, txt = block(img=img, txt=txt, vec=vec, pe=pe)
# controlnet residual

Expand Down Expand Up @@ -299,7 +304,7 @@ def denoise_controlnet(
y=neg_vec,
timesteps=t_vec,
guidance=guidance_vec,
block_controlnet_hidden_states=[i * controlnet_gs for i in neg_block_res_samples]
block_controlnet_hidden_states=[i * controlnet_gs for i in neg_block_res_samples],
neg_mode = True,

)
Expand Down

0 comments on commit c043d35

Please sign in to comment.