From 1ba31561027b8ee1604cee229e5e68f77a8985d0 Mon Sep 17 00:00:00 2001 From: asagi4 <130366179+asagi4@users.noreply.github.com> Date: Sat, 2 May 2026 16:28:11 +0800 Subject: [PATCH] samplers: stack hook patches on top of model patches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- comfy/samplers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/comfy/samplers.py b/comfy/samplers.py index 0a4d062db..baf3338fb 100755 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -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) if 'transformer_options' in model_options: - transformer_options = comfy.patcher_extension.merge_nested_dicts(transformer_options, - model_options['transformer_options'], - copy_dict1=False) + # Hook-derived patches must stack on top of model patches, so + # model's transformer_options is dict1 (existing) and the + # 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: transformer_options["patches"] = comfy.patcher_extension.merge_nested_dicts(