---
title: 'MoVQGAN Architecture: Enhanced VQGAN with MaskGIT'
url: https://www.emergentmind.com/topics/movqgan-based-architecture
type: topic
---

# MoVQGAN Architecture: Enhanced VQGAN with MaskGIT

MoVQGAN (Modulated Vector-Quantized Generative Adversarial Network) defines a two-stage image generation framework that introduces spatially conditional normalization and multichannel quantization for improved reconstruction fidelity and sample diversity. Addressing limitations in standard VQ-based pipelines—namely, repeated-pattern artifacts due to codebook collapse—MoVQGAN enables effective photorealistic image synthesis via a combination of architectural and training protocol innovations. At the prior modeling stage, it leverages Masked Generative Image Transformer (MaskGIT) for highly parallelizable discrete token prediction, accelerating image sampling while maintaining high output quality [2209.09002].

## 1. Pipeline Overview and Core Motivations

MoVQGAN operates in two stages: (i) a quantizer stage using a VQ-VAE-style encoder-decoder for vector-quantized latent representation of images, and (ii) a prior modeling stage using a bidirectional Transformer to generate latent index maps for image synthesis.

**Stage 1:** The encoder $\mathcal{E}_\psi$ maps $x\in\mathbb{R}^{256\times256\times3}$ to a continuous latent $\hat z\in\mathbb{R}^{16\times16\times256}$. Multichannel quantization is applied, generating a discrete latent index tensor $s\in\{0,\dots,1023\}^{16\times16\times4}$. The decoder $\mathcal{G}_\theta$ reconstructs the image.

**Stage 2:** A MaskGIT-based Transformer is trained to model the prior distribution over discrete index tensors. By conditioning on masked versions of $s$, the Transformer predicts latent tokens in parallel, enabling dramatically reduced sampling steps.

Key motivations relative to standard VQGAN include:
- Mitigating repeated “tile” artifacts from codebook index reuse.
- Injection of spatially variant information through Spatially Conditional Normalization (SCN).
- Expanding representational capacity via multichannel quantization (from $K$ to $K^c$ possible codes).
- Faster and more flexible generative prior sampling using MaskGIT over standard autoregressive models.

## 2. Encoder and Multichannel Quantization Methodology

The encoder follows the VQGAN/Taming Transformers structure, employing Gated ReLU activations and GroupNorm (encoder only). The input sequence of convolutions and residual blocks reduces spatial resolution, outputting $\hat z\in\mathbb{R}^{16\times16\times256}$.

**Multichannel Quantization** proceeds by splitting the 256-dimensional feature at each spatial location into $c=4$ chunks of 64 dimensions, quantizing each independently against a shared codebook $\mathcal{Z}\in\mathbb{R}^{1024\times64}$. For each chunk $m$ at location $(i,j)$,
\[
z_q^{(m)}[i,j] = \mathop{\arg\min}_{\,z_k\in\mathcal{Z}}\,\bigl\|\hat z^{(m)}[i,j]-z_k\bigr\|_2
\]
and $z_q = [z_q^{(1)},\ldots,z_q^{(4)}]$.

The discrete index tensor $s[i,j]\in\{1,\dots,1024\}^4$ encodes the quantized state per spatial location. Multichannel quantization increases the expressive capacity without scaling the codebook size, making $K^c$ compositional codes possible at constant memory and compute.

**Codebook updates** follow the standard VQ-VAE commitment and codebook loss formulation:
\[
\mathcal{L}_\mathrm{VQ} = \|x-\hat x\|^2_2 + \bigl\|\mathrm{sg}[\mathcal{E}_\psi(x)]-z_q\bigr\|^2_2 + \beta\,\bigl\|\mathrm{sg}[z_q]-\mathcal{E}_\psi(x)\bigr\|^2_2
\]
with $\beta=0.25$.

## 3. Spatially Conditional Normalization (SCN) and Decoder Advances

A noted problem in standard VQ-based generators is that decoder activations for locations sharing a codebook index become visually repetitive, leading to tiling artifacts. SCN addresses this by injecting per-location modulation signals derived from the quantized latent.

For each decoder block $i$ (in the first three blocks), the pre-activation $F^{i-1}\in\mathbb{R}^{H_i\times W_i\times C_i}$ is normalized via GroupNorm:
\[
\widetilde F^{i-1} = \frac{F^{i-1}-\mu(F^{i-1})}{\sigma(F^{i-1})}
\]
SCN then applies learned per-position affine transforms from up-/downsampled $z_q$:
\[
F^i = \alpha \odot \widetilde F^{i-1} + \beta, \quad \alpha = \phi_\gamma(z_q),\ \beta = \phi_\beta(z_q)
\]
where $\phi_\gamma$ and $\phi_\beta$ are $1\times 1$ convs mapping $z_q$ to $H_i\times W_i\times C_i$ scale and shift parameters.

The decoder otherwise follows the VQGAN upsampling stack, but only the first three blocks substitute GroupNorm with SCN.

## 4. Prior Modeling via MaskGIT

Conventional transformer priors factorize $p(s) = \prod_{t=1}^T p(s_t\,|\,s_{<t})$ and require sequential token prediction, with $T=1024$ for $16\times16\times4$ maps. MaskGIT instead models $p(s)= \prod_{t=1}^T p(s_t\,|\,s_{\bar m})$, with $s_{\bar m}$ masking a random subset $m$ of tokens.

**Training:** At each step, $r\%$ of tokens are randomly masked (with $r\in[20,100]$), and the transformer minimizes the cross-entropy over masked positions.

**Inference:** Starting with all locations masked, at each of $N$ iterations (e.g., $N=8\!-\!12$), the transformer predicts logits for all masked tokens in parallel, the most confident $k$ are selected to fill, and the process is repeated until all positions are filled. This reduces parallel sampling from 1024 to fewer than 12 steps.

## 5. Losses and Training Protocols

**Stage 1 (Quantizer+Decoder):**
- Pixelwise reconstruction: $L_\mathrm{rec} = \|x-\hat x\|_2^2$
- Perceptual (VGG feature) loss: $L_\mathrm{perc} = \|\phi(x)-\phi(\hat x)\|_2^2$
- Adversarial loss: $L_\mathrm{adv} = \max_D \mathbb{E}_x[\log D(x)] + \mathbb{E}_{\hat x}[\log(1-D(\hat x))]$
- VQ codebook and commitment losses per 2.3 above

The total loss is:
\[
L_\mathrm{stage1} = L_\mathrm{rec} + \lambda_\mathrm{perc}\,L_\mathrm{perc} + \lambda_\mathrm{adv}\,L_\mathrm{adv} + L_\mathrm{codebook} + \beta\,L_\mathrm{commit}
\]
with weights $\lambda_\mathrm{perc}=1$, $\lambda_\mathrm{adv}=1.5\times10^{-3}$, $\beta=0.25$.

**Stage 2 (MaskGIT Prior):**
- Negative log-likelihood on masked tokens:
\[
L_\mathrm{prior} = \mathbb{E}_{s,m}\Bigl[\sum_{t\in m}-\log p(s_t|s_{\bar m})\Bigr]
\]

Training utilizes batch sizes of 48 and 64 for stages 1 and 2, respectively; Adam optimizer with $\beta_1=0.9,\,\beta_2=0.99$, and a base learning rate of $2\cdot10^{-4}$.

## 6. Experimental Evaluation and Ablation Analysis

Quantitative and sample quality results on FFHQ and ImageNet highlight substantial gains relative to vanilla VQGAN.

| Model/Dataset   | PSNR  | SSIM  | LPIPS   | rFID  | FID (Stage 2) | IS (Stage 2) |
|-----------------|-------|-------|---------|-------|--------------|-------------|
| VQGAN/FFHQ      | 22.24 | 0.664 | 0.1175  | 4.42  | 11.4         | —           |
| MoVQGAN/FFHQ    | 26.72 | 0.821 | 0.0585  | 2.26  | 8.78         | —           |
| VQGAN/INet      | 19.47 | 0.521 | 0.1950  | 6.25  | —            | 78.3        |
| MoVQGAN/INet    | 22.42 | 0.673 | 0.113   | 1.12  | 7.22         | 130.1       |
| MaskGIT/INet    | —     | —     | —       | —     | 6.18         | 182.1       |

MoVQGAN eliminates repeating artifacts observed in past models such as standard VQGAN (“grass-tile” effects, as shown in Fig. 3 of [2209.09002]). It also exhibits efficient sampling—8 MaskGIT inference steps versus up to 1024 steps for AR baselines.

**Ablations**:
- Fourier features combined with SCN and multichannel quantization yield the best rFID (2.26) and FID (8.78).
- Increasing codebook size $K$ from 1024 to 16,384 produces negligible rFID improvements in MoVQGAN, but has much more impact in vanilla VQGAN; this suggests code capacity in MoVQGAN is not a limiting factor.
- Increasing number of channels $c$ improves PSNR but can degrade Stage 2 FID as sampling complexity increases; $c=4$ yields the best trade-off.

## 7. Architectural and Implementation Details

- Hardware: 4×Tesla V100 GPUs
- Encoder: Input $256\times256\times3$, down to $16\times16\times256$
- Quantization: Codebook size $K=1024$, code dimension 64, $c=4$ channels per spatial location
- Decoder: Up-convolutional stack, three initial blocks with SCN, all blocks otherwise match VQGAN
- Stage 2 Transformer: 24 layers, 16 heads, $d_\mathrm{model}=1024$, $d_\mathrm{ff}=4096$
- MaskGIT: 8 sampling steps (FFHQ), 12 steps (ImageNet), with progressive random masking schedule

The architecture enables high compression rates, improved quality metrics, and practical inference time for high-resolution image synthesis [2209.09002].

Source: https://www.emergentmind.com/topics/movqgan-based-architecture