Nodes/KJNodes for ComfyUI/MiniMax H3 Token Counter
ComfyUI Node Runs on cloud

MiniMax H3 Token Counter

Know your H3 token count before you burn an hour of VRAM

By kijai·Created 3 years ago·Updated 3 days ago· 3,123
MiniMax H3 Token Counter
  • samples
  • conditioning
  • samples
  • conditioning
  • tokens
  • breakdown

MiniMax H3 doesn't condition the way you'd expect. Everything - text, keyframes, reference images, audio, video - gets packed into one giant token stream, and that packed length is what decides both your VRAM and your render time. This node tells you that number before you sample. It builds the exact same layout the model will use and reports the sequence length, with a breakdown of where the tokens went. Cost: essentially zero. It doesn't run the model, it just counts.

That's the whole pitch, and it's genuinely useful on a model this heavy. Rather than guessing whether a longer clip or an extra reference will OOM, you insert one node, queue, and read the answer.

How it works

It reconstructs the packed layout from the two things that define it. The AV latent (samples) gives the video frame count and dimensions, rounded up to the DiT's 2×2 patch grid, plus the audio length when the latent carries an audio track. The conditioning gives the text length and any keyframe or reference blocks (minimax_keyframes, minimax_refs, minimax_frame_count in the conditioning). It feeds all of it into the same PackedLayout object ComfyUI's H3 model uses internally, then sums the segments. With scheduled conditioning that varies in text length, it reports the largest sequence - the one that actually has to fit.

The inputs and outputs that matter

  • samples - the AV latent that would be sampled (the video+audio pair from the H3 latent nodes).
  • conditioning - the positive conditioning; text length and keyframe/reference blocks are read from it.
  • Outputs: tokens (the packed sequence length, an INT), breakdown (a STRING, also shown inline on the node), and pass-through samples and conditioning so you can drop the node inline in the graph and change nothing.

That last point is the trick: wire it between your latent/conditioning and the sampler, and it's invisible to the workflow except for the number it shows you.

Installing KJNodes

ComfyUI Manager, search KJNodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
cd ComfyUI-KJNodes
pip install -r requirements.txt

Restart after. You need a ComfyUI build with native MiniMax H3 support - this node calls into comfy.ldm.minimax.model directly.

Gotchas

If you're on an older ComfyUI, you may get a RuntimeError telling you the PackedLayout doesn't support keyframes/references - that's a version check, not a bug in your workflow; update ComfyUI. And the breakdown carries a real warning worth heeding: if the sequence length pushes past roughly 300k packed tokens, it flags that you're at the edge of what the int32-addressed attention kernels can safely handle, and you should shrink something - fewer frames, lower resolution, or fewer references. That warning is the node doing its job: catching an OOM or a silent overflow before the render starts instead of after.

CategoryKJNodes/misc

Inputs (2)

NameTypeDefaultDescription
samplesLATENTThe AV latent that would be sampled (video+audio pair from the H3 latent nodes).
conditioningCONDITIONINGPositive conditioning; text length and any keyframe/reference blocks are read from it.

Outputs (4)

NameTypeDescription
samplesLATENTThe input latent, unchanged.
conditioningCONDITIONINGThe input conditioning, unchanged.
tokensINT
breakdownSTRING