Nodes/Fearnworks Nodes/πŸ” FW Token Count Ranker
ComfyUI Node

πŸ” FW Token Count Ranker

Find which part of your prompt is eating your token budget

By fearnworksΒ·Created 3 years agoΒ·Updated 2 years agoΒ· 26
πŸ” FW Token Count Ranker
  • clip
  • STRING
β—„textβ€”β–Ί

Say you already know your prompt is over CLIP's 77-token ceiling - CountTokens told you the total. The next question is where to cut, and that's not obvious just by reading the prompt back. A short clause with an unusual word can quietly cost more tokens than a whole run of common tags. TokenCountRanker answers that: it breaks your text into segments and words, counts the tokens on each piece, and ranks them so you can see exactly what's expensive instead of guessing.

This is a diagnostic node, not something you feed into your sampler. Its job is to sit off to the side of your real pipeline, take the same prompt string you're about to encode, and hand you back a breakdown you can actually act on before you start deleting words at random.

How it works

Same mechanism as its siblings in this pack: it runs your text through the CLIP tokenizer tied to whichever CLIP model you wire in, so the token counts match what will really happen at encode time. Where it differs from CountTokens is that it doesn't just total everything up - it splits the text into pieces (segments and individual words, per the pack's own description) and sorts them by token cost, surfacing the heaviest ones.

One thing worth flagging honestly: the pack's README describes this as producing "two lists: one for segments and one for words," but the node itself only has a single output socket, typed STRING. In practice that means you get one combined text report out of the node rather than two separate outputs - read it as a formatted ranking rather than expecting two distinct sockets to wire up.

The inputs and outputs that matter

  • clip (CLIP) - the CLIP model already in your graph, same requirement as CountTokens and TrimToTokens.
  • text (STRING) - the prompt you want broken down.

The output is a single STRING - the ranked breakdown. Wire it into a text preview node to actually read it; there's nothing here you'd normally send onward to a sampler.

How to install it

It ships in the same repo as the other three Fearnworks nodes, so one install gets you all of them:

  • ComfyUI Manager - search "Fearnworks Nodes" and install.
  • Manual:
    cd ComfyUI/custom_nodes
    git clone https://github.com/fearnworks/ComfyUI_FearnworksNodes
    
    then restart ComfyUI. No extra dependencies or model downloads - it uses the CLIP model you've already got loaded.

Common issues & troubleshooting

It's the least-used node in a small pack, for good reason. This is a niche, deep-cut tool - most people who hit this pack are after the blunter instruments, CountTokens for "how bad is it" and TrimToTokens for "just fix it." Reach for TokenCountRanker specifically when you've got a stubborn prompt that's over budget and you genuinely can't tell why by eye.

Only relevant on CLIP-lineage checkpoints. Same boundary as the rest of this pack: SD 1.5, SDXL, Illustrious, Pony, and similar CLIP-encoded models have the 77-token chunk to rank against. Modern LLM-encoder models (Flux, Z-Image and friends) don't truncate the same way, so there's nothing meaningful for this node to measure there.

SDXL 1.0 is what it was actually tested on. The README states the pack was validated on SDXL 1.0 and that 1.x models need "an additional switch" it doesn't currently have - treat rankings on an SD 1.5 checkpoint as unverified rather than assumed-correct.

If the output looks empty or unhelpful, first confirm with CountTokens that the total is actually meaningful for your clip input - if that one's producing sane numbers, this one should be reading the same text correctly.

CategoryFearnworks/Text/Tokens

Inputs (2)

NameTypeDefaultDescription
clipCLIPβ€”
textSTRINGβ€”

Outputs (1)

NameTypeDescription
STRINGSTRINGβ€”