Nodes/ComfyUI-productfix/VQ encoder diffusers (middlek)
ComfyUI Node

VQ encoder diffusers (middlek)

Encode an image into VQ latent space — the quiet half of the pack's codec duo

By MiddleKD·Created 2 years ago·Updated about a year ago· 21
VQ encoder diffusers (middlek)
  • vq
  • images
  • LATENT

VQEncoder is the input half of the pack's alternative latent codec: it takes an image, pushes it through a diffusers VQModel (loaded by VQLoader), and hands you the resulting quantized latents. If the VQ path is a niche, this node is the unglamorous workhorse within it - it's what turns a product photo into the latent representation that Kandinsky-style latent composition operates on.

How it works

Straightforward wrapper with three real steps. It normalizes the image from [0,1] to [-1,1] (the range diffusers models expect), permutes it from B,H,W,C into B,C,H,W, and calls vqmodel.encode(...)["latents"]. Then it packages the result as a standard {"samples": ...} latent dict, which is what keeps it interoperable with everything else in ComfyUI. The model is moved to the compute device for the encode and back off to intermediate memory afterwards - a small VRAM courtesy.

The inputs and output

  • vq - the VQ model from VQLoader.
  • images - an IMAGE, the thing you want encoded.
  • Returns a LATENT dict - feed it to VQDecoder, or into latent-space composition like DetailTransferLatentAdd.

Note the input name is images (plural) and it handles batches fine - handy if you're encoding a batch of product shots.

Install

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

Restart. Requires diffusers (pack dependency) plus a VQ model already loaded via VQLoader.

Gotchas

  • Not a VAE. The latents here are quantized (that's what the "Q" is for), with a different structure and resolution behavior than SD VAE latents. Don't assume a VAE decode node can read them.
  • Model must be loaded first - VQEncoder has no fallback; if vq_name was never set in VQLoader, there's nothing to encode with.
  • Output assumes samples layout - which is what the node produces, so the pair is self-consistent.

The plain truth: you will only touch this node if you've committed to the VQ composition path, and that path is deep enough that the pack's own demos barely depend on it. But as far as diffusers VQModel wrappers go, this one is clean, batched, and does exactly one job.

Categoryproductfix

Inputs (2)

NameTypeDefaultDescription
vqVQ
imagesIMAGE

Outputs (1)

NameTypeDescription
LATENTLATENT