Conditioning Match Mask
Let the pack figure out which prompt words describe which subject
- reference_condition1
- reference_condition2
- reference_condition3
- reference_condition4
- reference_condition5
- target_condition
- mask
Here's a genuinely clever little node hiding in a pack nobody talks about. ConditioningMatchMask takes each of your reference conditions and figures out which part of your target prompt they correspond to - automatically, by reading the embeddings. The output is a MASK that marks, for each reference subject, the stretch of target-prompt tokens that best matches that subject. It's the "which subject is which" answer for the batched workflow, and it's the piece that saves you from hand-labeling prompt regions.
Why it exists: in the batched flow, your target image is a new scene that contains the same characters as your references. For the masked-attention machinery in BatchedMaskedReferenceGen to keep each character's identity anchored, it needs to know that "the knight" in the target prompt is subject 1. ConditioningMatchMask computes that mapping from the conditioning tensors themselves rather than from you fiddling with masks by hand.
How it works
The mechanism is a sliding-window similarity search in embedding space. For each reference condition, it takes that reference's token embeddings and slides them across the target condition's sequence, computing mean cosine similarity at every offset. The window with the highest similarity wins, and those target positions get marked with a 1 in the output mask. Cosine similarity of embeddings, argmax over the window positions, done.
Concretely: reference conditions go in via reference_condition1 through reference_condition5, plus the shared target_condition. All optional in the schema, but the node raises a ValueError if you give it no references or no target - so "optional" really means "wire whichever of the five you need." Output is a single mask (MASK) shaped [num_references, target_seq_len]: one row per reference, with a 1 in the columns belonging to the matched target sub-sequence.
How it fits
Pair it with ReferenceConditionCombine. The combine node builds the batched conditioning and marks where tokens exist; ConditioningMatchMask tells you which target tokens match which subject. Together they produce the two masks - conditions_ref_mask and conditions_mask - that BatchedMaskedReferenceGen needs. A workflow using the batched path will typically have one ConditioningMatchMask wired from the same five reference conditions plus the target condition, feeding straight into the batched generator.
There's a softness to it you should know about: "best matching window" is a heuristic, and it assumes each reference subject is actually mentioned in the target prompt. If you reference a character that never appears in the target prompt, the node will still pick the least-bad window and mark it - that's a wrong match, and the batched flow will happily act on it. Keep your target prompt describing all the subjects you reference.
Install
ComfyUI Manager → search "Comfyui_CharaConsist", or git clone https://github.com/thatname/Comfyui_CharaConsist.git into custom_nodes, restart. Find it under chara_consist. No pip dependencies; Flux, Chroma, and Qwen-Image models only, same as the rest of the pack.
It's the rare node that makes a real decision for you, which is both the appeal and the trap - trust the mask, but sanity-check it with a MaskPreview if your subjects are similar to each other. Similar characters produce similar embeddings, and the argmax can flip the mapping. Distinct subjects, distinct descriptions, and it's reliably right.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| reference_condition1opt | CONDITIONING | — | |
| reference_condition2opt | CONDITIONING | — | |
| reference_condition3opt | CONDITIONING | — | |
| reference_condition4opt | CONDITIONING | — | |
| reference_condition5opt | CONDITIONING | — | |
| target_conditionopt | CONDITIONING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |