Nodes/Comfyui-bitdance/BitDance VAE Encode
ComfyUI Node

BitDance VAE Encode

How to turn a real image into BitDance's token language

By aistudynow·Created 6 months ago·Updated 6 months ago· 33
BitDance VAE Encode
  • vae
  • image
  • bitdance_latent
parallel_num64

The decode side of a VAE is where most people live - prompt, sample, decode, done. This node is the reverse direction: it takes a real IMAGE and pushes it through the BitDance VAE to produce bitdance_latent, the same token-sequence format the sampler outputs. If BitDance's sampler someday grows an image-to-image or inpainting path, or you want to represent an existing image in the model's own token language for experimentation, this is the node that gets you there.

It's deliberately simple. Three required inputs:

  • vae - the BITDANCE_VAE from BitDance Loader. Same rule as the decode node: not a standard ComfyUI VAE.
  • image - a standard IMAGE tensor, [B, H, W, 3]. Anything LoadImage produces.
  • parallel_num - the one real knob, default 64, range 1–4096. This is the token-block size the image gets packed into, and it must be a perfect square (the code takes its square root to derive the patch grid and errors out otherwise). 64 = an 8×8 patch block, and it matches what the sampler uses internally.

The single output is bitdance_latent, the same BITDANCE_LATENT type the sampler returns - so whatever you make here can be handed straight to BitDance VAE Decode and round-tripped back to pixels.

The mechanism

The image is scaled to [-1, 1], run through the VAE's encoder, and the resulting 4D latent grid is rearranged from (batch, channels, h, w) into the flat token layout BitDance's autoregressive sampler works in - the mirror image of what BitDance Decode does on the way back. Because both nodes share the BITDANCE_LATENT type, an encode followed by a decode is a clean round-trip, and you can inspect what the model "sees" an image as.

What to watch for

parallel_num is the only thing that will bite you. If it's not a perfect square you get a hard error, and if the encoded latent grid isn't divisible by your chosen patch size you get another - so on an off-list resolution, use a value like 64 that divides cleanly. The usual VRAM notes apply too: this node unloads other models and moves the VAE to the GPU for the encode, then offloads it again, so it's polite to your card but takes a few seconds. It's not a node you'll reach for in every workflow - the pack's sampler generates from scratch, so encode is more of a bridge for image-based experiments than a daily step. But when you need it, it's the only way in.

Install once, with the pack: ComfyUI Manager → search "Comfyui-bitdance", or git clone https://github.com/aistudynow/Comfyui-bitdance into custom_nodes, pip install -r requirements.txt, restart.

Categorylatent/bitdance

Inputs (3)

NameTypeDefaultDescription
vaeBITDANCE_VAE
imageIMAGE
parallel_numINT641–4096

Outputs (1)

NameTypeDescription
bitdance_latentBITDANCE_LATENT