Nodes/Comfyui_CharaConsist/Batched Masked Reference Gen
ComfyUI Node

Batched Masked Reference Gen

The all-in-one-batch route to consistency

By thatname·Created 10 months ago·Updated 9 months ago· 1
Batched Masked Reference Gen
  • model
  • source_patch_masks
  • target_patch_masks
  • conditions_mask
  • conditions_ref_mask
  • model

The core CharaConsist flow - ExtractAttn, GetCrossSim, GenConsistent - runs your reference and your target as separate passes. BatchedMaskedReferenceGen is the alternative route: generate the reference and target images in one batch, together, and use masks to decide which tokens are allowed to look at which. Same training-free consistency idea, different shape. You use this node when you want multiple subjects rendered side by side in a single sampling run, or when the two-pass cache dance is too RAM-hungry and you'd rather mask than cache.

The mechanism is masked attention. The node takes pixel-patch masks and turns them into attention masks: reference images can attend to other references (so your subjects stay internally consistent), and each target image can attend to the references plus its own tokens, but a target can't attend to another target's tokens. The subject stays where it belongs, and cross-subject blending - the classic "two characters merged into one" failure - gets structurally blocked instead of prayed away.

How it works

You feed it four masks, all produced by the pack's other nodes:

  • source_patch_masks and target_patch_masks - patch-level masks from MasksToPatches or MaskToPatchMask that say where the subject is in the source and target images.
  • conditions_mask and conditions_ref_mask - from ReferenceConditionCombine and ConditioningMatchMask. These mark which text tokens in the batch belong to which image row.

Internally it flattens the patch masks, builds log-space attention masks, and overrides the attention function. Here's the neat bit: it checks the model class and patches the right module automatically - comfy.ldm.flux for Flux/Qwen and comfy.ldm.chroma for Chroma. So you don't pick a mode; the node sniffs your model.

Output is a single patched MODEL - chain it into your KSampler and let the whole batch sample under the mask. That's the whole node: masks in, masked-attention model out.

When you'd reach for it

This is the multi-subject path the README brags about. Want a character and their twin, or a scene with two consistent characters, in one render? Batch them, mask them, and BatchedMaskedReferenceGen keeps each identity isolated. It's also the path that pairs with ReferenceConditionCombine - which builds the batched conditioning and its token mask - so if you see that node in a workflow, this one is usually waiting downstream.

The trade-off is complexity. The batched flow asks you to keep four masks in alignment and understand what your conditioning looks like as a padded batch. For a single subject, the two-pass ExtractAttn → GenConsistent route is easier to reason about and better documented by the example JSONs. Batch it when you have multiple subjects; don't batch for one.

Install and troubleshooting

ComfyUI Manager → search "Comfyui_CharaConsist", or:

cd ComfyUI/custom_nodes
git clone https://github.com/thatname/Comfyui_CharaConsist.git

Restart, find it under chara_consist. No pip dependencies; Flux, Chroma, and Qwen-Image models only. The example workflows in the repo use GroundingDinoSAM (from the Segment Anything pack) to produce clean subject masks - worth installing if you want masks that actually hug your character.

Watch the mask shapes. The node squeezes 3D masks down to their first batch row, so if your patch masks and condition masks disagree on batch dimensions you'll get garbage masks and the attention math goes sideways. It prints "Processing with model" and "Detected model type" to the console on run - if you don't see both lines, your model isn't one this node understands and the override never fires. Which, again, means a silent no-op rather than an error. When the mask lands right, though, it's the cleanest way to keep several characters from bleeding into each other in a single pass.

Categorychara_consist

Inputs (5)

NameTypeDefaultDescription
modelMODEL
source_patch_masksMASK
target_patch_masksMASK
conditions_maskMASK
conditions_ref_maskMASK

Outputs (1)

NameTypeDescription
modelMODEL