AttentionMask
The Flux attention mask ComfyUI never shows you
- pipe
- ATTENTION_MASK
- PROMPT_BATCH
If you've ever wondered whether Flux is really reading your whole prompt - every token, including the padding - this node is the experiment someone built to find out. AttentionMask is the middle piece of a three-node pack that gives Flux and SD3 the T5 text attention mask that diffusers has been quietly dropping. Native ComfyUI Flux never exposes this knob, which is both the pack's entire reason to exist and a big hint about how niche it is.
Here's the mechanism, and it's a real one. When your prompt goes through the T5 tokenizer (Flux's tokenizer_2, SD3's tokenizer_3), you get token IDs plus an attention mask: a row of 1s for real tokens and 0s for padding. Back in mid-2024 the SD3 training crowd discovered diffusers was feeding T5 embeddings into the transformer without that mask - so short prompts were padded with noise the model treated as equally meaningful, and the problem got worse the longer you made the sequence. There's a HuggingFace PR (#10044) that threads the mask through Flux and SD3 via joint_attention_kwargs. It's still unmerged, and this pack is built on top of it.
What the node actually does: it takes the pipe from AMModelLoader, tokenizes your positive_prompt (and negative_prompt on SD3), and returns the mask plus the tokenized prompt batch. The interesting bit is it pads Flux to 512 tokens - double the 256-token window diffusers normally truncates Flux prompts to. With a real attention mask, that extra padding doesn't pollute attention, which is the pack's whole pitch: longer prompts, better semantic alignment.
Inputs a beginner actually sets:
- positive_prompt - the one that matters. Multiline; defaults to "a tiny astronaut hatching from an egg on the moon".
- negative_prompt - only used in SD3 mode. Flux is guidance-distilled with no true negative prompt, so this sits idle on FLUX.
- max_length - accepted (64–1024), but right now the code hardcodes 512 for Flux and 256 for SD3. Don't sweat it.
- pipe - wire from
AMModelLoader. Not optional, and it's a diffusers pipeline object, not a ComfyUI checkpoint.
Outputs: ATTENTION_MASK and PROMPT_BATCH. Wire both into AMSample - they're a matched pair and the sampler expects them together.
Install, the real way (the README's clone line is wrong - it points at a repo that doesn't exist):
cd ComfyUI/custom_nodes
git clone https://github.com/leeguandong/ComfyUI_FluxAttentionMask
Restart ComfyUI. There's no requirements.txt, so the pack rides on whatever diffusers/transformers your env already has. That's the trap: mainline diffusers accepts an attention_mask argument and ignores it - the pack only does anything if your diffusers build includes the unmerged PR #10044.
Where people get burned: the mask silently doing nothing on stock diffusers (your long-prompt output looks identical to the short version - that's the tell), and the gated FLUX.1-dev model failing to download until you accept the license. And set expectations: this is a Feb 2025, four-star, unmaintained research demo from a developer with a string of Flux experiment packs. The premise - more tokens is better - also cuts against what the community actually found, that past roughly 100 effective tokens Flux starts to drift. If you just want Flux in ComfyUI, use the native nodes. Reach for this only if you specifically want to poke at the attention-mask hypothesis.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| pipe | MODEL_PIPE | — | |
| positive_prompt | STRING | a tiny astronaut hatching from an egg on the moon | — |
| negative_prompt | STRING | — | |
| max_length | INT | 51264–1024 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| ATTENTION_MASK | ATTENTION_MASK | — |
| PROMPT_BATCH | PROMPT_BATCH | — |