ComfyUI Node

CPA AttnChunk

Pointing a Generative Matte at One Person

By rik-python·Created about a month ago·Updated 9 days ago· 50
CPA AttnChunk
  • mask
  • attention_mask
◄start0►
◄length49►
◄end-1►
◄grow20►
◄blur10.00►

LTX-2.5 alpha-gen is very good at drawing hair and completely uninterested in your opinion about whose hair. It mattes every main subject in the frame, all at once, and there is no prompt that fixes that - alpha-gen runs on an empty prompt by design. The way you steer it is the IC-LoRA guide's attention mask, and CPA AttnChunk is the node that turns a SAM 3 mask into one.

This node only matters in overlap mode (v13), the pack's mode for when somebody's hand, arm or hair crosses in front of your subject. In the default Best (v12) path the other people get painted out of the plate instead, so LTX has nothing to be confused about and no attention mask is needed. In v13 the real plate is kept - the whole point - and LTX is steered with a mask per pass: one for your subject, one for everyone else.

What it does to the mask

Three things, and the first two are the interesting ones.

It grows the mask with an elliptical dilation, grow pixels (default 20). This exists because a SAM 3 outline is a segmentation, not a matte - it stops at the visible boundary of hair and leaves the strands outside it. Growing before LTX sees it means the model gets permission to draw hair beyond the SAM outline. The pack's default of 20 was swept against test shots; raise it toward 30–40 if long or wild hair is getting cut off, drop to 10 if the subject's matte starts swallowing a person standing right next to them.

It feathers the edge with a Gaussian, blur (default 10 as a sigma). This matters more than it looks: the author measured that a hard-edged attention mask cuts the hair, at roughly 1.5x the error. LTX needs the mask to fade out so the generative edge has somewhere to be a soft edge. Leave it at 10 unless you've got genuinely wispy flyaway hair and want 15–20.

Then it pads like the frames do: length filled by repeating the last frame up to length, and height/width replicate-padded to a multiple of 32, so the mask is exactly the shape and length of the guide's image chunk. That alignment is why this is a separate node rather than something the guide does internally - mismatched lengths are the kind of bug that shows up as a silently wrong matte rather than an error.

Output is attention_mask, a MASK wired into the guide node's attention_mask input, with attention_strength alongside it (1.0 in the pack; 0.7 measured about 1.3x the error, so don't get creative).

Inputs

mask is a subject mask over the processed range - the SAM 3 track, not the ViTMatte refined edge. start, length, end work exactly like CPA ChunkPad: absolute index, chunk length, and an optional absolute end that truncates. grow and blur are the two above, surfaced on the main node as attn_grow and attn_blur under Advanced, where the tooltips repeat the sweep results.

When it causes trouble

The failure modes are all "the mask is the wrong size for the job", and they read as edge quality problems rather than mask problems:

  • Hair beyond the SAM outline is chopped off. grow too low for this shot. Try 30.
  • The subject's matte picks up the edge of the person beside them. grow too high. Try 10.
  • Grey gaps between someone's curls where they cross the subject. That's not this node's mask - that's the pack's hair_guide (guided-filter re-fit of the crossing hair to plate edges), a separate switch.
  • Everything is soft and mushy along a crossing. blur too high, or you're looking at the ViTMatte fallback rather than a generative edge.

And the honest caveat from the pack's own numbers: the v13 edges are sharper but they flicker more - 1.9x versus 1.2x LTX alone, on motion-compensated measurement. Sharp fingers that move score as more movement than a soft line that doesn't. Check your own shot in motion before deciding it's a bug.

Install

It comes with the pack. Nothing extra to install for the node itself; using v13 end to end also needs ComfyUI-SAM3, ComfyUI-LTXVideo, the LTX-2.5 transformer and alpha-gen IC-LoRA, plus Depth Anything V2 Small, which downloads itself (~100 MB) on the first overlap-mode run.

cd ComfyUI/custom_nodes
git clone https://github.com/rik-python/ComfyUI-Comfy-Pro-Alpha-Generator.git
pip install -r ComfyUI-Comfy-Pro-Alpha-Generator/requirements.txt

Then restart and reload the browser tab. Like every /internal node in this pack it's hidden from the node menu - it exists in the graph the generator builds, not in your palette.

CategoryComfy Compositing/internal

Inputs (6)

NameTypeDefaultDescription
maskMASK—
startINT0—
lengthINT49—
endINT-1—
growINT20—
blurFLOAT10.00—

Outputs (1)

NameTypeDescription
attention_maskMASK—