DL0177 Discrete vs Continuous Visual Tokens

What is the difference between discrete visual tokenization (e.g., VQ-VAE, VQ-GAN) and continuous vision embeddings (e.g., ViT patch outputs), and when is each preferred for generation versus understanding tasks?

Answer

Both paths begin identically, with a convolutional or ViT encoder turning the image into a grid of d-dimensional vectors. The only structural difference is whether a quantizer follows. A discrete tokenizer (VQ-VAE, VQ-GAN) snaps each vector to its nearest entry in a learned codebook of K vectors and keeps only the integer index, so an image becomes a string of ids over a finite vocabulary that a jointly trained decoder can invert back to pixels. A continuous representation (ViT patch outputs, CLIP or SigLIP features, KL-VAE latents) keeps the float vector, which preserves far more information but has no finite support, so no softmax and no cross-entropy can be defined over it. That single difference decides the downstream interface: discrete ids plug into next-token or masked-token prediction with exactly the machinery used for text, while continuous features must be projected into an LLM or denoised by a diffusion model. As a default, understanding prefers continuous features because quantization discards the high-frequency detail that OCR and fine-grained VQA depend on, while generation historically preferred discrete tokens because a categorical likelihood is easy to train and easy to sample.

(1) Only The Quantizer Differs: the encoder, the patch grid, and the spatial downsampling factor can be identical; adding a nearest-code lookup converts a float grid into an id grid.
(2) Information Budget: a discrete token carries \log_2 K bits (10 to 18 in practice), while a continuous patch vector carries roughly d \times 16 bits of activation, three orders of magnitude more.
(3) Gradient Path: \arg\min is non-differentiable, so VQ needs a straight-through estimator plus codebook and commitment losses, whereas continuous encoders train by plain backpropagation.
(4) Reconstruction Cost: heavy compression makes plain L2 reconstruction blurry, which is why VQ-GAN adds perceptual and patch-GAN losses to keep 16x-downsampled decodes sharp.
(5) Downstream Interface: discrete gives one softmax vocabulary shared with text; continuous gives features for a projector, cross-attention, or a latent diffusion denoiser.
(6) Task Split: continuous features dominate VLM understanding benchmarks; discrete tokens dominate when the goal is a single unified next-token model that also emits pixels.

Two horizontal pipelines: the upper understanding path runs input image to ViT patch encoder to 256 continuous vectors in R^1024 to a linear projector to an LLM emitting text, with no quantizer and no pixel decoder; the lower generation path runs input image to a CNN or ViT encoder to a quantizer that picks the nearest of K codes, to a 16 by 16 grid of integer ids, to a transformer with a softmax over K, to a decoder producing pixels

Figure 1: The same encoder, two endings. Deleting the quantizer leaves continuous features that a projector feeds to an LLM; inserting it buys a finite vocabulary and a pixel decoder at the price of \log_2 K bits per token. Note that the understanding path has no decoder at all, which is why an understanding-only encoder is never required to be invertible.

The practical difficulty of discrete tokenization is that the codebook must be learned through a non-differentiable lookup. The straight-through estimator simply copies the decoder gradient past the quantizer, which is a biased estimate that works only if the encoder output stays close to its assigned code, hence the commitment loss. The characteristic failure is codebook collapse: a few entries win most assignments, the rest receive no gradient and die, and effective vocabulary size stops tracking nominal K. Standard mitigations are EMA codebook updates, low-dimensional \ell_2-normalized codes, dead-code re-initialization, and an entropy bonus on the assignment distribution. Continuous encoders have none of this machinery, but they also cannot be sampled from, since there is no distribution over \mathbb{R}^{d} that a softmax can express, which is precisely why continuous-latent generation requires a diffusion or flow model rather than a token classifier.

Mathematical Formulation:
z = E(x)
k = \arg\min_{j} \lVert z - e_j \rVert_2
z_q = e_k
\hat{x} = D(z_q)
\mathcal{L}_{\mathrm{com}} = \beta \lVert z - \mathrm{sg}(e_k) \rVert_2^2

Where:

  • x is the input image, E the encoder, and z \in \mathbb{R}^{d} one continuous patch vector from the encoder grid; keeping z and stopping here is the continuous path.
  • e_j for j \in \{1,\ldots,K\} are the learned codebook vectors, k is the selected index (the actual token), and K is the vocabulary size.
  • z_q is the quantized vector fed to the decoder D, and the residual z - z_q is information the model can never recover.
  • \mathrm{sg}(\cdot) is the stop-gradient operator and \beta (typically 0.25) weights the commitment loss that pulls encoder outputs toward their assigned codes.
  • The full VQ-GAN objective adds a reconstruction term, an LPIPS perceptual term, and a patch-discriminator term to \mathcal{L}_{\mathrm{com}}; only the reconstruction term survives in a plain VQ-VAE.

Bit Budget For One 256×256 Image:
B_{\mathrm{disc}} = 256 \times 14 = 3584
B_{\mathrm{cont}} = 256 \times 1024 \times 16
B_{\mathrm{cont}} = 4194304
B_{\mathrm{cont}} / B_{\mathrm{disc}} \approx 1170

All four numbers are in bits. A 16x-downsampling tokenizer with K = 16384 compresses the image to 256 ids of 14 bits each, about 448 bytes, while a ViT-L/14 tower keeps 256 patch vectors of 1024 bf16 activations, about 512 KiB. That ratio is the whole argument: it is why a discrete sequence is short enough to model autoregressively alongside text, and equally why an OCR-heavy or chart-reading task should not be routed through it.

Left panel shows a two-dimensional scatter of continuous encoder outputs partitioned into nine square cells by dashed boundaries, with a black X codebook entry at each cell center and one highlighted red point joined by an arrow to its nearest code, labelled quantization error. Right panel plots reconstruction FID against bits per token from 10 to 18, with a plain VQ curve that stalls near 5 and rises after 14 bits, a lookup-free or FSQ curve that keeps falling toward 1.2, and a dashed horizontal line marking the continuous KL-VAE floor near 0.74

Figure 2: Left, quantization is a Voronoi partition of the latent space: the id names the cell, and the offset inside the cell is thrown away. Right, approximate published reconstruction results show that a plain VQ codebook stops improving past about 2^{14} entries because of codebook collapse, whereas lookup-free and FSQ-style quantizers keep scaling toward the continuous-latent floor.

PropertyDiscrete (VQ-VAE / VQ-GAN)Continuous (ViT / KL-VAE)
What a token isAn integer index into a learned codebook of K vectorsAn unconstrained d-dimensional float vector
Information per tokenlog2 K bits, typically 10 to 18About d x 16 bits, typically 4k to 16k
Gradient pathNon-differentiable argmin, needs a straight-through estimator plus commitment lossPlain end-to-end backpropagation
Known instabilityCodebook collapse and dead codes, with usage often below 10 percent at large KLatent scale drift without a KL term or normalization
Generation interfaceCross-entropy over K, autoregressive or masked sampling, one vocabulary shared with textLatent diffusion or flow matching, or a small per-token diffusion head
Understanding qualityWeaker OCR, charts, and fine-grained recognition after the bottleneckDefault choice: CLIP or SigLIP features feed the projector in most VLMs
Pixel decoderRequired, trained jointly with the codebookOnly if the task emits pixels; understanding-only towers have none

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *