This repository implements UniTok, a unified visual tokenizer well-suited for both generation and understanding tasks.
It is compatible with autoregressive generative models (e.g. LlamaGen),
multimodal understanding models (e.g. LLaVA), and unified MLLMs (e.g. Chameleon and Liquid).
teaser
Built upon UniTok, we construct an MLLM capable of both multimodal generation and understanding
with the Liquid framework,
which sets a new state-of-the-art among unified autoregressive MLLMs.
teaser
Abstract
Visual generative and understanding models typically rely on distinct tokenizers to process images, presenting a key challenge for unifying them within a single framework. Recent studies attempt to address this by connecting the training of VQVAE (for autoregressive generation) and CLIP (for understanding) to build a unified tokenizer. However, directly combining these training objectives has been observed to cause severe loss conflicts. In this paper, we show that reconstruction and semantic supervision do not inherently conflict. Instead, the underlying bottleneck stems from limited representational capacity of discrete token space. Building on these insights, we introduce UniTok, a unified tokenizer featuring a novel multi-codebook quantization mechanism that effectively scales up the vocabulary size and bottleneck dimension. In terms of final performance, UniTok sets a new record of 0.38 rFID and 78.6% zero-shot accuracy on ImageNet. Besides, UniTok can be seamlessly integrated into MLLMs to unlock native visual generation capability, without compromising the understanding performance. Additionally, we show that UniTok favors cfg-free generation, reducing gFID from 14.6 to 2.5 on ImageNet 256$\times$256 benchmark. GitHub: this https URL .
News
2025-09-18: UniTok is accepted at NeurIPS 2025 as a spotlight.
2025-05-19: We find UniTok favors generation without classifier-free-guidance --
it reduces gFID (without cfg) from 14.6 to 2.51 on ImageNet 256x256 using LlamaGen-XXL as the generator.
Please refer to the updated EVAL.md for more details.
2025-04-15: The gradio demo of UniTok MLLM is available on Huggingface now!
2025-04-02: A new checkpoint
of UniTok is released, which has better downstream task performance
by replacing the causal attention projection layer with full attention.
The model weights
of our unified MLLM are also available on Huggingface now!
2025-02-28: Paper, code, model, and project page for UniTok are all released.
Performance
Method
#Tokens
rFID ↓
Accuracy
VQVAE Model
VQ-GAN
256
4.98
--
RQ-VAE
256
1.30
--
VAR
680
0.90
--
CLIP Model
CLIP
256
--
76.2
SigLIP
256
--
80.5
ViTamin
256
--
81.2
Unified Model
TokenFlow †
680
1.37
--
VILA-U †
256
1.80
73.3
UniTok
256
0.41
70.8
UniTok †
256
0.38
78.6
† indicates the model uses pretrained CLIP weights for initialization. Although CLIP weight initialization boosts ImageNet zero-shot accuracy,
we notice that random initialization leads to better downstream understanding performance.
We thus release the model checkpoint of UniTok that is trained from scratch.
1from inference_solver import FlexARInferenceSolver
2from PIL import Image
34# ******************** Image Generation ********************5inference_solver = FlexARInferenceSolver(6 model_path="Alpha-VLLM/Lumina-mGPT-7B-768",7 precision="bf16",8 target_size=768,9)1011q1 = f"Generate an image of 768x768 according to the following prompt:12" \
13f"Image of a dog playing water, and a waterfall is in the background."1415# generated: tuple of (generated response, list of generated images)16generated = inference_solver.generate(17 images=[],18 qas=[[q1,None]],19 max_gen_len=8192,20 temperature=1.0,21 logits_processor=inference_solver.create_logits_processor(cfg=4.0, image_top_k=2000),22)2324a1, new_image = generated[0], generated[1][0]252627# ******************* Image Understanding ******************28inference_solver = FlexARInferenceSolver(29 model_path="Alpha-VLLM/Lumina-mGPT-7B-512",30 precision="bf16",31 target_size=512,32)3334# "<|image|>" symbol will be replaced with sequence of image tokens before fed to LLM35q1 ="Describe the image in detail. <|image|>"3637images =[Image.open("image.png")]38qas =[[q1,None]]3940# `len(images)` should be equal to the number of appearance of "<|image|>" in qas41generated = inference_solver.generate(42 images=images,43 qas=qas,44 max_gen_len=8192,45 temperature=1.0,46 logits_processor=inference_solver.create_logits_processor(cfg=4.0, image_top_k=2000),47)4849a1 = generated[0]50# generated[1], namely the list of newly generated images, should typically be empty in this case.515253# ********************* Omni-Potent *********************54inference_solver = FlexARInferenceSolver(55 model_path="Alpha-VLLM/Lumina-mGPT-7B-768-Omni",56 precision="bf16",57 target_size=768,58)5960# Example: Depth Estimation61# For more instructions, see demos/demo_image2image.py62q1 ="Depth estimation. <|image|>"63images =[Image.open("image.png")]64qas =[[q1,None]]6566generated = inference_solver.generate(67 images=images,68 qas=qas,69 max_gen_len=8192,70 temperature=1.0,71 logits_processor=inference_solver.create_logits_processor(cfg=1.0, image_top_k=200),72)7374a1 = generated[0]75new_image = generated[1][0]
Training
We train UniTok on DataComp-1B.
Please follow the instructions to download and prepare the data.
Download the models used for loss calculation and put them under ./external.
We also benchmark UniTok in terms of both understanding performance using the LLaVA framework
and generation performance using the LLamaGen framework.
Please refer to EVAL.md for more details.
This project is licensed under the MIT License. See the LICENSE file for details.
Citation
If you find this project useful, please consider citing:
bibtex
1@article{unitok,
2 title={UniTok: A Unified Tokenizer for Visual Generation and Understanding},
3 author={Ma, Chuofan and Jiang, Yi and Wu, Junfeng and Yang, Jihan and Yu, Xin and Yuan, Zehuan and Peng, Bingyue and Qi, Xiaojuan},
4 journal={arXiv preprint arXiv:2502.20321},
5 year={2025}
6}