Cosmos Tokenizer is a suite of visual tokenizers for images and videos that delivers various compression rates while maintaining high reconstruction quality. Cosmos Tokenizer can serve as an effective and efficient building block in both diffusion-based and autoregressive models for image and video generation.
Our tokenizers come in two types: Continuous (C) and Discrete (D), each with Image (I) and Video (V) variants:
Continuous tokenizers encode visual data into continuous latent embeddings, as shown in latent diffusion models like Stable Diffusion. These embeddings are suitable for models that generate data by sampling from continuous distributions.
Discrete tokenizers encode visual data into discrete latent codes, mapping them into quantized indices, as seen in autoregressive transformers such as VideoPoet. This discretization is required for models that generate data by optimizing the cross-entropy loss, such as the GPT models.
Continuous ( C )
Discrete ( D )
Images ( I )
Cosmos-Tokenizer-CI
Cosmos-Tokenizer-DI
Videos ( V )
Cosmos-Tokenizer-CV
Cosmos-Tokenizer-DV
Given an image or a video, Cosmos Tokenizer outputs either continuous latents or discrete tokens. Cosmos Tokenizer achieves spatial compression rates of 8x8 or 16x16 and temporal compression factors of 4x or 8x, resulting in a total compression factor of up to 2048x (=8x16x16). Cosmos Tokenizer delivers 8x more total compression than state-of-the-art (SOTA) methods while simultaneously maintaining higher image quality and running up to 12x faster than the best available SOTA tokenizers.
Model Developer: NVIDIA
Model Versions
The initial release (v1.0) of Cosmos Tokenizer includes the following tokenizers:
Under the NVIDIA Open Model License, NVIDIA confirms:
Models are commercially usable.
You are free to create and distribute Derivative Models.
NVIDIA does not claim ownership to any outputs generated using the Models or Derivative Models.
Model Architecture:
We designed Cosmos Tokenizer using a lightweight and computationally efficient architecture, featuring a temporally causal design. Specifically, we employ causal temporal convolution and causal temporal attention layers to preserve the natural temporal order of video frames, ensuring seamless tokenization of images and videos using a single unified network architecture. The encoder and decoder form a symmetrical pair, which are mirrors of each other. The encoder starts with a 2-level Haar wavelet transform layer, which down-samples inputs by a factor of 4 in both spatial and temporal dimensions. Likewise, the decoder ends with an inverse wavelet transform. We employ the vanilla autoencoder (AE) formulation to model the latent space for continuous tokenizers. For discrete tokenizers, we adopt the Finite-Scalar-Quantization (FSQ) as the latent space quantizer.
image/jpeg
Input/Output Specifications
Encoder
Input
Types: Images or Videos
Format: RGB (Red, Green, Blue)
Resolution:
Minimum: 256px (shorter side)
Maximum: Up to 4K
Video Length: Up to 8 seconds for 1080p videos (bounded by A100 80G GPU memory; higher resolutions will have shorter supported durations)
Output
Types: Tokens
Continuous Image/Video Tokenizers: Continuous value feature vectors
Discrete Image/Video Tokenizers: Integer indices
Decoder
Input
Types: Tokens from encoder
Output
Types: Images or Videos (matching input type)
Format: RGB (Red, Green, Blue)
Resolution: Same as input resolution
Video Length: Same as input video length
Software Integration (Required For NVIDIA Models Only):
Note: We have only tested Cosmos Tokenizer with BF16 precision on Ampere and Hopper GPUs. If you are using older versions of NVIDIA GPUs (e.g., NVIDIA Volta GPUs), you may need to switch to FP32 precision.
Operating System(s):
Linux (We have not tested on other operating systems.)
Preferably, you could build a docker image using our provided Dockerfile.
bash
1docker build -t cosmos-docker -f Dockerfile.
2# You can run the container as:3docker run --gpus all -it --rm -v /home/${USER}:/home/${USER}\4 --workdir ${PWD} cosmos-docker /bin/bash
Step-2: Download Pre-trained Checkpoints
Create a local directory for the pre-trained checkpoints and download the
pre-trained checkpoints from HuggingFace.
python
1from huggingface_hub import login, snapshot_download
2import os
3# You could get your Hugging Face token from https://huggingface.co/settings/tokens4login(token=<YOUT-HF-TOKEN>, add_to_git_credential=True)5# You could specify the tokenizers you want to download.6model_names =[7"Cosmos-Tokenizer-CI8x8",8"Cosmos-Tokenizer-CI16x16",9"Cosmos-Tokenizer-CV4x8x8",10"Cosmos-Tokenizer-CV8x8x8",11"Cosmos-Tokenizer-CV8x16x16",12"Cosmos-Tokenizer-DI8x8",13"Cosmos-Tokenizer-DI16x16",14"Cosmos-Tokenizer-DV4x8x8",15"Cosmos-Tokenizer-DV8x8x8",16"Cosmos-Tokenizer-DV8x16x16",17]18for model_name in model_names:19 hf_repo ="nvidia/"+ model_name
20 local_dir ="pretrained_ckpts/"+ model_name
21 os.makedirs(local_dir, exist_ok=True)22print(f"downloading {model_name} to {local_dir}...")23 snapshot_download(repo_id=hf_repo, local_dir=local_dir)
Under the ech checkpoint directory pretrained_ckpts/<model-name>, we provide the encoder,
decoder and the full autoencoder JIT models.
You can use the following example commands to encode and decode images or videos. For each, the same command works for both continuous and discrete tokenization. Simply provide the proper JIT-compiled ckpt to checkpoint_enc, checkpoint_dec, or the full autoencoder ckpt to checkpoint.
python
1import torch
2from cosmos_tokenizer.image_lib import ImageTokenizer
34model_name ="Cosmos-Tokenizer-CI8x8"5input_tensor = torch.randn(1,3,512,512).to('cuda').to(torch.bfloat16)# [B, C, H, W]6encoder = ImageTokenizer(checkpoint_enc=f'pretrained_ckpts/{model_name}/encoder.jit')7(latent,)= encoder.encode(input_tensor)8torch.testing.assert_close(latent.shape,(1,16,64,64))910# The input tensor can be reconstructed by the decoder as:11decoder = ImageTokenizer(checkpoint_dec=f'pretrained_ckpts/{model_name}/decoder.jit')12reconstructed_tensor = decoder.decode(latent)13torch.testing.assert_close(reconstructed_tensor.shape, input_tensor.shape)
The latent will have the shape (1, 16, 64, 64), where C=16 is the number of channels of the latent.
Note: More inference usage commands, including both TorchScript (JIT) and PyTorch Inference APIs on real images and videos, can be found on our GitHub repository github.com/NVIDIA/Cosmos-Tokenizer.
Inference with NeMo
Step-1: Install NeMo
Please install NeMo from the GitHub main branch following the instructions here.
We have extensively evaluated the Cosmos Tokenizer suite on various image and video benchmark datasets.
For the evaluation of image tokenizers, we follow prior art to evaluate on MS-COCO 2017, ImageNet-1K, FFHQ, and CelebA-HQ. We use the MS-COCO 2017 validation subset of 5,000 images, ImageNet-1K validation subset of 50,000 images, FFHQ subset of 10,000 images, and CelebA-HQ subset of 14,645 images as image evaluation benchmark.
Tokenizer
Compression Ratio
Formulation
PSNR (MS-COCO)
SSIM (MS-COCO)
rFID (MS-COCO)
PSNR (ImageNet-1K)
SSIM (ImageNet-1K)
rFID (ImageNet-1K)
PSNR (FFHQ)
SSIM (FFHQ)
rFID (FFHQ)
PSNR (CelebA-HQ)
SSIM (CelebA-HQ)
rFID (CelebA-HQ)
FLUX
8×8
VAE
31.87
0.692
2.501
30.92
0.518
1.229
38.51
0.960
0.043
41.11
0.987
0.040
Cosmos-Tokenizer-CI
8×8
AE
32.98
0.836
1.760
33.12
0.837
0.689
39.67
0.957
0.042
46.47
0.988
0.016
Cosmos-Tokenizer-CI
16×16
AE
31.74
0.703
5.600
31.74
0.700
2.017
32.39
0.833
1.833
32.48
0.879
1.114
We compare with the state-of-the-art continuous image tokenizer, FLUX.
Evaluation metrics:
Peak Signal-to-Noise Ratio (PSNR)
Structural Similarity (SSIM)
Reconstruction Fréchet Inception Distance (rFID)
Runtime Comparison
The following table shows the number of parameters and the averaged encoding and decoding times per image or video frame, measured on a single A100 80GB GPU. For comparison, we also list the parameters and average speeds of prior state-of-the-art tokenizer(s) with the same compression ratio.
Tokenizer
Resolution
Compression Ratio
Parameters
Time (ms)
FLUX
1024x1024
8×8
84M
242
Cosmos-Tokenizer-CI
1024x1024
8×8
77M
62.7
Note: We benchmarked the runtime for images under the 8x8 compression and videos under the 4×8×8 compression. Tokenizers with different compression ratios are not included in this comparison.
Ethical Considerations
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
For more detailed information on ethical considerations for this model, please see the subcards of Explainability, Bias, Safety & Security, and Privacy below. Please report security vulnerabilities or NVIDIA AI Concerns here.
Bias
Field
Response
Participation considerations from adversely impacted groups protected classes in model design and testing:
None
Measures taken to mitigate against unwanted bias:
None
Explainability
Field
Response
Intended Application & Domain:
Tokenization of images and videos
Model Type:
Auto-Encoder
Intended Users:
Generative AI developers for image and video generation models
Output:
Images/Videos and Latent Tokens
Describe how the model works:
Compresses and decompresses visual input (image/video).
Technical Limitations:
Due to tokenizer compression limitations, some visual information (such as small text and other structured fine details) may not be reconstructed accurately.
Verified to have met prescribed NVIDIA quality standards:
Yes
Performance Metrics:
Peak Signal-to-Noise Ratio (PSNR), Structural Similarity (SSIM), Reconstruction Fréchet Video Distance (rFVD), Reconstruction Fréchet Inception Distance (rFID), Latency
Potential Known Risks:
Tokenizer's output can parse all forms of input, including what may be considered toxic, offensive, or indecent.
The Principle of least privilege (PoLP) is applied limiting access for dataset generation and model development. Restrictions enforce dataset access during training, and dataset license constraints adhered to. Model checkpoints are made available on Hugging Face, and may become available on cloud providers' model catalog.
Plus Plus (++) Promise
We value you, the datasets, the diversity they represent, and what we have been entrusted with. This model and its associated data have been:
Verified to comply with current applicable disclosure laws, regulations, and industry standards.
Verified to comply with applicable privacy labeling requirements.
Annotated to describe the collector/source (NVIDIA or a third-party).
Characterized for technical limitations.
Reviewed to ensure proper disclosure is accessible to, maintained for, and in compliance with NVIDIA data subjects and their requests.
Reviewed before release.
Tagged for known restrictions and potential safety implications.