samplers: stack hook patches on top of model patches

After 493b81e (#10591) swapped the argument order of `merge_nested_dicts`,
the merge call in `_calc_cond_batch` ended up assembling list-valued patch
keys (e.g. `attn2_patch`) as `[hook_patches, model_patches]` instead of
`[model_patches, hook_patches]`. This breaks combinations where a hook
needs to run *after* a model-level attention patch — for example NegPip
(model patch via `set_model_attn2_patch`) + AttentionCouple (registered
as a `TransformerOptionsHook` by asagi4/comfyui-prompt-control). With
the wrong order, couple's masked-attention math runs on un-NegPip'd
values and per-region weighting is washed out.

Fix: swap the merge args so model's `transformer_options` is dict1 and
the hook-derived dict is dict2. This restores `attn2_patch =
[model_patches, hook_patches]`. `copy_dict1=True` is required because
dict1 is now a reference to persistent model state.

Reported and root-caused in asagi4/comfyui-prompt-control#135. Patch
authored and locally tested by @asagi4 in that thread.

Co-authored-by: Booyaka101 <cbosch101@gmail.com>
This commit is contained in:
asagi4 2026-05-02 16:28:11 +08:00 committed by Booyaka101
parent 3e3ed8cc2a
commit 1ba3156102

View File

@ -300,9 +300,12 @@ def _calc_cond_batch(model: BaseModel, conds: list[list[dict]], x_in: torch.Tens
transformer_options = model.current_patcher.apply_hooks(hooks=hooks) transformer_options = model.current_patcher.apply_hooks(hooks=hooks)
if 'transformer_options' in model_options: if 'transformer_options' in model_options:
transformer_options = comfy.patcher_extension.merge_nested_dicts(transformer_options, # Hook-derived patches must stack on top of model patches, so
model_options['transformer_options'], # model's transformer_options is dict1 (existing) and the
copy_dict1=False) # hook-derived dict is dict2 (extends model's lists).
transformer_options = comfy.patcher_extension.merge_nested_dicts(model_options['transformer_options'],
transformer_options,
copy_dict1=True)
if patches is not None: if patches is not None:
transformer_options["patches"] = comfy.patcher_extension.merge_nested_dicts( transformer_options["patches"] = comfy.patcher_extension.merge_nested_dicts(