---
title: 'QuadTok: Hierarchical Visual Tokenization'
url: https://www.emergentmind.com/topics/quadtok
type: topic
---

# QuadTok: Hierarchical Visual Tokenization

QuadTok is a visual tokenizer and autoregressive image-generation framework based on a content-adaptive quadtree representation. Rather than encoding a $256\times256$ image with a fixed $16\times16$ grid of 256 tokens or with an unstructured variable-length sequence, QuadTok organizes visual tokens hierarchically: homogeneous regions remain represented by coarse parent nodes, while visually complex regions are recursively expanded into finer child tokens. The resulting representation combines explicit two-dimensional spatial correspondence with one-dimensional sequence flexibility. In the reported ImageNet experiments, QuadTok reduces the mean token count by approximately 10% relative to a fixed 256-token grid on ImageNet and 9% under zero-shot transfer to COCO while maintaining comparable reconstruction fidelity. Its 947M-parameter autoregressive generator reaches a gFID of 2.08 on ImageNet at $256\times256$ resolution [2610.10497].

## 1. Conceptual foundations and terminology

QuadTok is centered on the premise that image information density is spatially heterogeneous. Smooth sky, walls, or uniform backgrounds can often be represented at coarse resolution, whereas object boundaries, foliage, animals, and highly textured regions benefit from finer spatial subdivision. A fixed grid allocates equal token capacity to all regions, while an unstructured one-dimensional tokenizer permits variable sequence lengths but weakens the correspondence between tokens and image regions.

The method therefore combines two properties:

- **Hierarchical spatial correspondence**: every token is associated with a quadtree level and spatial position.
- **Variable-length serialization**: the selected tree is converted into a one-dimensional sequence suitable for autoregressive modeling.

The full discrete representation is the pair $(Y,T)$ rather than the code sequence alone. Here, $Y=[y_1,\ldots,y_M]$ contains the discrete visual codes and $T=(n_1,n_2,\ldots,n_M)$ contains the topology, with each node represented as

$$
n_i=(l_i,p_i),
$$

where $l_i$ is the hierarchy level and $p_i$ indexes the spatial cell at that level. The same code index may have different spatial meanings at different levels or positions.

The name QuadTok should be distinguished from the tokenizer conceptually called QuadTok in “Vision Transformers with Mixed-Resolution Tokenization” [2304.00287]. That earlier method uses a quadtree to allocate mixed-resolution image patches before a standard Vision Transformer and calls the complete model a Quadformer. The present QuadTok instead uses a quadtree for discrete visual tokenization and autoregressive image generation [2610.10497].

## 2. Quadtree topology and sequence construction

The default $256\times256$ configuration uses a two-level hierarchy:

- level 1: an $8\times8$ coarse grid;
- level 2: a $16\times16$ fine grid.

All 64 coarse cells are retained. Each coarse cell either remains one token or is expanded into four child tokens. If $K$ coarse cells are expanded, the sequence length is

$$
M=64+4K.
$$

The minimum sequence length is therefore 64 tokens, while the maximum for the two-level hierarchy is 320 tokens. A three-level extension adds a $32\times32$ grid, forming the hierarchy

$$
8\times8\rightarrow16\times16\rightarrow32\times32.
$$

QuadTok serializes tree nodes using breadth-first search (BFS). Coarse nodes occur before their descendants, yielding a coarse-to-fine sequence in which global structure precedes regional refinement. The sequence remains compatible with Transformer processing, while the node attributes retain information about hierarchy and spatial location.

BFS supplies the autoregressive ordering used by the generator:

1. coarse level-1 codes are generated first;
2. child codes are generated for expanded regions;
3. increasingly fine tokens refine selected spatial areas.

The topology is supplied before generation. The generator does not infer the topology from an image during unconditional generation because no image is available; instead, the topology is selected or constructed before visual-code sampling.

## 3. Token formation and topology-aware attention

Given an image $I$, QuadTok first computes dense ViT features,

$$
F=\operatorname{Encoder}(I),\qquad F\in\mathbb{R}^{N\times D}.
$$

For each quadtree node $n_i=(l_i,p_i)$, a learnable structural instruction embedding is constructed:

$$
q_i=\operatorname{Emb}_{l_i}(p_i).
$$

The dense features and node instructions are jointly processed by an Aggregator Transformer:

$$
[F'\parallel Z]=\operatorname{Aggregator}([F\parallel Q]),
$$

where $Z=[z_1,\ldots,z_M]$ contains one continuous representation for each selected quadtree node. The structural instruction acts as a region-specific query: the node representation can access globally contextualized ViT features while retaining the level and spatial position of the region it represents.

QuadTok then applies vector quantization using a shared codebook

$$
\mathcal{C}=\{e_k\}_{k=1}^{K}.
$$

The reported $256\times256$ configuration uses vocabulary size $K=16{,}384$ and code dimensionality $d=8$. Each node embedding is assigned to its nearest codebook vector:

$$
y_i=\operatorname{Quant}(z_i)
=\arg\min_{k\in\{1,\ldots,K\}}\|z_i-e_k\|_2^2.
$$

The resulting representation is the variable-length discrete sequence $Y$ together with the topology $T$.

### Kinship Causal Attention

QuadTok uses a topology-aware attention mask called the **Kinship Causal Mask** in the tokenizer’s Aggregator and Decoder. For the two-level tree:

- coarse nodes attend bidirectionally to one another;
- child nodes attend to their parents, but parents do not attend to children;
- siblings attend bidirectionally to one another;
- unrelated fine-level nodes do not attend directly.

For deeper trees, a node can attend to all coarser nodes and same-level siblings, but not to finer-level descendants. The mask is therefore partly bidirectional and structured by tree relationships. It is distinct from the generator’s ordinary left-to-right causal mask.

The mask preserves locality and region-code binding. In perturbation tests, changing a fine-level code produces a localized reconstruction change when the mask is used. Without it, perturbations spread across the image, and the representation behaves more like an unstructured one-dimensional code stream. The reported ablation gives:

| Tokenizer | rFID | PSNR | gFID |
|---|---:|---:|---:|
| Without Kinship Mask | 1.41 | 19.16 | 3.17 |
| With Kinship Mask | 1.46 | 20.37 | 2.23 |

The unconstrained variant obtains slightly lower rFID but substantially lower PSNR and much worse generation gFID. For spatially grounded autoregression and topology-based control, the topology-aware mask preserves the more important structural correspondence.

## 4. Hierarchical decoding and adaptive topology selection

After quantization, codebook embeddings are combined with structural instructions:

$$
\tilde z_i=e_{y_i}+q_i.
$$

A Transformer Decoder processes the sequence $\tilde Z=[\tilde z_1,\ldots,\tilde z_M]$. Unlike a conventional decoder that reshapes all tokens into a single dense grid, QuadTok projects each node into a region-specific feature patch according to its tree level and spatial position:

$$
C_{l_i}(p_i)=U_{l_i}(\tilde z_i),
$$

where $U_l$ is a level-specific projection or unpatching operator. Patches at each level are placed at their spatial positions to form a residual feature map $C_l$. Hierarchical feature maps are then combined through learned upsampling:

$$
H_{l+1}=F^{\mathrm{up}_{l+1}}(H_l)+C_{l+1},
\qquad H_0=0.
$$

The final feature representation is projected to RGB space:

$$
\hat I=\operatorname{RGB}(H_L).
$$

Coarse nodes establish broad image structure, while children contribute local residual detail. A homogeneous region can therefore be reconstructed from a parent token alone, whereas a complex region can be refined using four child tokens.

### Training-time tree sampling

During training, all level-1 nodes are retained. Each parent independently expands into its four children with probability $\gamma$, using the default value

$$
\gamma=0.5.
$$

This exposes the tokenizer to multiple valid tree shapes and sequence lengths rather than a single deterministic topology.

The tokenizer is trained with pixel, perceptual, vector-quantization, and adversarial losses:

$$
\mathcal{L}_{\mathrm{total}}
=
\lambda_{\mathrm{MSE}}\mathcal{L}_{\mathrm{MSE}}
+\lambda_{\mathrm{LPIPS}}\mathcal{L}_{\mathrm{LPIPS}}
+\lambda_{\mathrm{VQ}}\mathcal{L}_{\mathrm{VQ}}
+\lambda_{\mathrm{GAN}}\mathcal{L}_{\mathrm{GAN}}.
$$

Adversarial training is initially disabled, with $\lambda_{\mathrm{GAN}}=0$ for the first 200,000 steps, and activated afterward. The reported tokenizer has approximately 120M parameters; its encoder, Aggregator, and Decoder each use eight Transformer blocks with hidden size 512. The ViT encoder uses $16\times16$ patches.

### Region-Wise Complexity Guidance

QuadTok selects image-dependent topologies using **Region-Wise Complexity Guidance**. Two complementary probing trees are constructed: one expands approximately half of the coarse regions, and the other expands the complementary half. Each tree is decoded to produce a reconstruction and a spatial LPIPS error map.

For a region $r$, the benefit of expansion is defined as

$$
b_r=\operatorname{AvgPool}_r
\left(
E_r^{\mathrm{collapsed}}
-
E_r^{\mathrm{expanded}}
\right).
$$

The region is expanded when

$$
b_r>\tau,
$$

with default threshold $\tau=0.05$. The complete adaptive encoding procedure is:

1. compute ViT features;
2. construct probing trees;
3. decode the alternative tree configurations;
4. calculate regional LPIPS improvement;
5. expand regions satisfying $b_r>\tau$;
6. encode the image using the selected tree;
7. quantize the resulting node representations.

This is a probing and selection algorithm rather than a conventional learned topology-prediction network. Its computational cost is substantial because topology search requires multiple reconstructions and LPIPS calculations.

## 5. Autoregressive generation and spatial control

Given a class condition $c$, a topology $T$, and its BFS-ordered visual-code sequence $Y=[y_1,\ldots,y_M]$, QuadTok models

$$
p(Y\mid c,T)
=
\prod_{i=1}^{M}
p(y_i\mid y_{<i},c,t_{\leq i}),
$$

where $t_i=(l_i,p_i)$ is the structural attribute of node $i$ and $y_{<i}$ contains preceding visual codes.

At step $i$, the generator receives:

- preceding visual codes;
- the class-conditioning signal;
- current and preceding node instructions;
- no future topology instructions or future visual codes.

The generator is a decoder-only LLaMA-style Transformer with standard causal attention, Query-Key normalization, SwiGLU activations, rotary position embeddings, class conditioning, classifier-free guidance, and KV caching. It does not use the tokenizer’s Kinship Causal Mask; spatial structure enters through node instructions and BFS ordering.

The reported two-level generator sizes are:

| Model | Parameters |
|---|---:|
| QuadTok-B | 111M |
| QuadTok-L | 343M |
| QuadTok-XL | 697M |
| QuadTok-XXL | 947M |

The three-level generator has 344M parameters. Generators are trained for 300 epochs, approximately 360K iterations, using global batch size 1024. AdamW is used with $\beta_1=0.9$, $\beta_2=0.95$, and weight decay $0.05$. The learning rate is $4\times10^{-4}$ for the first 250 epochs and linearly decays to $10^{-5}$ over the final 50 epochs. Class labels are dropped with probability 0.1 for classifier-free guidance.

QuadTok supports zero-shot spatially controlled generation because topology directly specifies which regions receive fine-grained tokens. A requested layout can be converted into a topology by retaining all coarse nodes, expanding nodes inside the target region, and leaving nodes outside it coarse. For a half-image layout at $256\times256$, expanding 32 of the 64 coarse cells produces

$$
64+32\cdot4=192
$$

tokens.

At 192 tokens, prescribed topologies improve localization relative to matched random topologies. The reported metrics are:

| Target | Topology | Grad-CAM | Box | Mask |
|---|---|---:|---:|---:|
| Left | Random | 29.6 | 47.5 | 51.1 |
| Left | Prescribed | 58.3 | 51.8 | 59.0 |
| Right | Random | 70.4 | 51.0 | 48.5 |
| Right | Prescribed | 87.9 | 58.1 | 55.7 |
| Top | Random | 33.9 | 40.7 | 42.9 |
| Top | Prescribed | 55.4 | 47.0 | 47.8 |
| Bottom | Random | 66.1 | 58.9 | 56.7 |
| Bottom | Prescribed | 83.6 | 64.6 | 62.5 |

Matched FID-50cls values remain nearly unchanged, ranging from 34.88 to 35.15 compared with 35.03 for the random baseline. These results indicate that topology can steer localization without a major distributional-quality penalty in the reported experiment.

## 6. Empirical results, efficiency, and limitations

### Reconstruction

QuadTok is trained on ImageNet-1K at $256\times256$ and evaluated on ImageNet-1K validation images and MS-COCO validation images without fine-tuning. The principal metrics are mean token count, reconstruction FID (rFID), and PSNR.

| Tokenizer | Dataset | Tokens | rFID | PSNR |
|---|---|---:|---:|---:|
| LlamaGen $f=16$ | ImageNet | 256 | 2.19 | 20.79 |
| LlamaGen $f=16$ | COCO | 256 | 8.11 | 20.42 |
| TiTok-S | ImageNet | 128 | 1.71 | 17.80 |
| One-D-Piece-L | ImageNet | 256 | 1.08 | 19.04 |
| GigaTok-B-L | ImageNet | 256 | 0.81 | 21.21 |
| QuadTok | ImageNet | 230 | 1.46 | 20.37 |
| QuadTok | COCO | 232 | 7.88 | 19.30 |

The mean token count is approximately 230 on ImageNet and 232 on COCO, corresponding to savings of about 10.2% and 9.4%, respectively, relative to 256 tokens. The comparison is not uniformly favorable on every metric: LlamaGen has higher ImageNet PSNR, while QuadTok has lower rFID than LlamaGen $f=16$. The reported result is therefore an efficiency-quality tradeoff rather than universal dominance.

The three-level version obtains 989 tokens and rFID 0.770 with PSNR 23.31 on ImageNet, and 1012 tokens with rFID 3.92 and PSNR 23.83 on COCO. These results demonstrate deeper-tree extensibility but use a substantially larger token budget.

In the guidance ablation, the guided tree obtains 230 tokens, rFID 1.46, and PSNR 20.37, compared with 320 tokens, rFID 1.50, and PSNR 20.39 for the full tree. Random expansion produces 253 tokens, rFID 1.601, and PSNR 19.40. The LPIPS-based selection with threshold $\tau=0.05$ is the strongest reported perceptual allocation strategy in that ablation.

### ImageNet generation

The principal generation metric is gFID, the Fréchet Inception Distance between generated samples and real ImageNet reference images in Inception-feature space. QuadTok-XXL obtains

$$
\mathrm{gFID}=2.08
$$

with 947M parameters.

| Model | Size | gFID | IS |
|---|---:|---:|---:|
| LlamaGen-B | 111M | 5.46 | 193.61 |
| DPAR-XL | 789M | 2.67 | 281.65 |
| RandAR-XXL | 1.4B | 2.15 | 321.97 |
| GigaTok-XL-XXL | 1.4B | 1.98 | 256.76 |
| QuadTok-B | 111M | 4.41 | 205.61 |
| QuadTok-L | 343M | 2.93 | 226.69 |
| QuadTok three-level-L | 344M | 2.77 | 231.70 |
| QuadTok-XL | 697M | 2.23 | 262.38 |
| QuadTok-XXL | 947M | 2.08 | 273.35 |

These are system-level comparisons involving different tokenizers, training procedures, sampling policies, and token budgets; they are not perfectly controlled architecture-only comparisons. The expansion-probability sweep further shows a nonmonotonic relationship between token count and generation quality: increasing expansion initially improves gFID, but excessive expansion eventually worsens it.

### Computational tradeoffs

For the two-level hierarchy, independent expansion probability $p$ yields expected sequence length

$$
\mathbb{E}[M]=64+256p.
$$

The reported examples are approximately 128 tokens at $p=0.25$, 192 tokens at $p=0.50$, and 256 tokens at $p=0.75$. Relative to a 256-token LlamaGen baseline, generation speedups range from 1.57–2.40$\times$ at $p=0.25$, 1.09–1.58$\times$ at $p=0.50$, and 1.09–1.20$\times$ at $p=0.75$, depending on model size and batch or classifier-free-guidance settings.

Adaptive pretokenization is slower than fixed-grid encoding because it includes topology probing and LPIPS computation. At batch size 32, the reported times are approximately 2.9 ms/image for LlamaGen VQ-16 and 8.8 ms/image for QuadTok. This overhead can be cached during generator training, and it is not required during generation when the topology is supplied in advance.

At $512\times512$, QuadTok uses a two-level $16\times16\rightarrow32\times32$ hierarchy. All 256 coarse tokens are retained, and the maximum sequence length is 1,280 tokens. The mean reconstruction length is approximately 987 tokens. QuadTok obtains rFID 0.84 and PSNR 24.96, compared with rFID 0.70 and PSNR 23.03 for LlamaGen at 1024 tokens. A 344M QuadTok generator obtains gFID 2.734 and IS 268.01 in the reported $512\times512$ class-conditional experiment.

### Limitations

QuadTok’s generator requires a topology before visual-code generation. A poor topology can allocate insufficient capacity to important regions, waste tokens on uninformative regions, create a distribution shift relative to training topologies, or reduce generation quality when expansion is excessive.

The complexity-guidance procedure is computationally expensive because it requires multiple reconstructions and spatial LPIPS calculations. Token savings are also moderate: the default $256\times256$ configuration saves approximately 9–10% relative to a fixed 256-token grid, rather than achieving the much stronger compression associated with some 32–128-token one-dimensional tokenizers.

Increasing hierarchy depth improves reconstruction and generation in some settings but substantially increases token count, autoregressive sampling cost, and decoder complexity. The main experiments focus on class-conditional ImageNet and zero-shot COCO reconstruction; large-scale open-domain text-to-image generation is not demonstrated. Because ImageNet is predominantly object-centric and often single-subject, the reported spatial-control experiments primarily test relocation of one dominant object rather than multi-object interactions, depth ordering, or complex relational layouts.

Finally, threshold selection is empirical. The expansion threshold $\tau$ affects both token count and reconstruction quality, and the preferred value may vary across datasets, resolutions, and domains. QuadTok’s central contribution is consequently not a universally optimal tree, but a framework in which spatial topology, discrete tokenization, attention structure, and autoregressive generation are jointly organized around hierarchical visual complexity.

Source: https://www.emergentmind.com/topics/quadtok