RepoByteDance (Doubao/Seed)ByteDance (Doubao/Seed)published Oct 29, 2026seen 3w

ByteDance-Seed/GenFirst

Python

Open original ↗

Captured source

source ↗
published Oct 29, 2026seen 3wcaptured 3whttp 200method plain

ByteDance-Seed/GenFirst

Language: Python

License: NOASSERTION

Stars: 9

Forks: 0

Open issues: 0

Created: 2026-10-29T03:00:32Z

Pushed: 2026-11-03T07:00:01Z

Default branch: main

Fork: no

Archived: no

README:

GenFirst: Generation Before Reconstruction for Stable End-to-End Latent Generative Modeling

Official PyTorch Implementation

This is a PyTorch/GPU implementation of the paper GenFirst: Generation Before Reconstruction for Stable End-to-End Latent Generative Modeling:

@article{zheng2026genfirst,
title={GenFirst: Generation Before Reconstruction for Stable End-to-End Latent Generative Modeling},
author={Zheng, Guangting and Zhang, Yiyuan and Yang, Tao and Chen, Yunpeng and Zhu, Rui and Deng, Jiajun and Zhang, Yanyong},
journal={arXiv preprint arXiv:2608.29335},
year={2026}
}

What we do:

  • 🚀 Simple, effective, and stable end-to-end training of VAEs with generative models (AR and Diffusion), without latent collapse.
  • ⚖️ Mitigates the generation–reconstruction conflict by using our GenFirst training strategy during end-to-end training.
  • 🏆 Strong generation performance: 0.97 gFID with CFG on ImageNet-256 without FD loss, and 0.90 GenEval on text-to-image generation.
  • 🌐 Beyond generation: 1) extends to a shared latent space for generation and understanding, and 2) unified text–image modeling via an end-to-end diffusion.

This repo contains:

  • 🪐 The end-to-end VAE + SiT trainer ([train_e2e.py](train_e2e.py)), the decoder-only finetune that follows it ([train_decoder_ft.py](train_decoder_ft.py)), and the prior-only frozen E2E-VAE SiT trainer ([Prior_only/train_prior_only.py](Prior_only/train_prior_only.py))
  • ⚡️ Both configurations from the paper: f8d4+SiT-XL/2 and f16d32+SiT-XL/1, at 256x256 and 512x512
  • 🛸 Text-to-image training on the FLUX.1 VAE with MMDiT ([docs/T2I.md](docs/T2I.md))
  • 🧠 An optional understanding objective on the latent, for a shared generation +

understanding latent space, with an ImageNet linear probe to evaluate it ([docs/UND.md](docs/UND.md))

  • 🔗 Unified text-image modeling: one block-causal MMDiT over image *and* text

latents, generating in both directions ([docs/JOINT.md](docs/JOINT.md))

  • 💥 Evaluation: 50k-sample FID/IS, plus GenEval and DPG-Bench ([eval_bench/](eval_bench))

Note this repository is the EiT (SiT / diffusion prior) instantiation in the paper's tables. The autoregressive EAR instantiation is not included here.

Preparation

Installation

conda env create -f environment.yml
conda activate genfirst

Or pip install -r requirements.txt (install torch first).

Dataset

Download ImageNet dataset and place it in your IMAGENET_PATH. The two stages want it in two different layouts.

The end-to-end stage reads a single HDF5 of raw images:

python tools/build_image_h5.py --source ${IMAGENET_PATH}/train \
--dest data --resolution 256

The prior-only stage reads a directory of cropped images, which it then encodes into cached latents:

python tools/build_image_dir.py \
--source=${IMAGENET_PATH}/train \
--dest=data/imagenet256/images \
--resolution=256x256 --transform=center-crop-dhariwal

See [docs/DATA.md](docs/DATA.md) for 512x512 and the disk budget.

Download pre-trained VAE initializations

The end-to-end stage starts from an existing VAE. Place the files under pretrained/:

| Config | Source | Expected files | | -------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | | f8d4 | stabilityai/sd-vae-ft-ema | pretrained/sdvae/sdvae-f8d4.pt, pretrained/sdvae/sdvae-f8d4-discriminator-ckpt.pt | | f16d32 | VA-VAE (LightningDiT) | pretrained/vavae/vavae-f16d32.pt, pretrained/vavae/vavae-f16d32-discriminator-ckpt.pt |

Training from scratch also works — drop --vae-ckpt and --disc-pretrained-ckpt.

Pretrained models

Generative models

50k-sample FID/IS against the ImageNet reference statistics in fid_stats/. The unguided columns are what the model does on its own; the guided ones use the sampling settings from [Evaluation](#evaluation) below. ImageNet 512x512 is reported with guidance only.

| Model | Resolution | gFID | IS | gFID (cfg) | IS (cfg) | Download | | -------------------------- | ---------- | -------- | ----- | ---------- | -------- | -------- | | EiT, 80 prior-only epochs | 256x256 | 2.79 | 175.4 | 1.38 | 271.3 | checkpoint · weak-20ep | | EiT, 480 prior-only epochs | 256x256 | 1.60 | 216.8 | 0.988 | 270.7 | checkpoint · weak-20ep | | EiT, 800 prior-only epochs | 256x256 | 1.45 | 226.7 | 0.969 | 283.4 | checkpoint · weak-20ep | | EiT, 80 prior-only epochs | 512x512 | – | – | 1.63 | 278.9 | checkpoint | | EiT, 400 prior-only epochs | 512x512 | – | – | 1.23 | 286.1 | checkpoint |

Text-to-image models

MMDiT-XL/2 with a frozen CLIP-L text encoder, on the frozen end-to-end FLUX VAE, ending at 512x512. GenEval and DPG-Bench overall scores, no prompt rewriting. The two variants differ only in the VAE they were given (see the next table).

| Model | Resolution | GenEval | DPG-Bench | Download | | ------------------ | ---------- | --------- | --------- | -------- | | EiT T2I, variant A | 512x512 | 0.8987 | 82.60 | checkpoint ·...

Excerpt shown — open the source for the full document.