Home

Awesome

<p align="center"> <img src="asset/logo-sigma.png" height=120> </p>

<div align="center">πŸ‘‰ PixArt-Ξ£: Weak-to-Strong Training of Diffusion Transformer for 4K Text-to-Image Generation<div>

<div align="center"> <a href="https://pixart-alpha.github.io/PixArt-sigma-project/"><img src="https://img.shields.io/static/v1?label=Project%20Page&message=Github&color=blue&logo=github-pages"></a> &ensp; <a href="https://arxiv.org/abs/2403.04692"><img src="https://img.shields.io/static/v1?label=Paper&message=Arxiv:Sigma&color=red&logo=arxiv"></a> &ensp; <a href="https://huggingface.co/spaces/PixArt-alpha/PixArt-Sigma"><img src="https://img.shields.io/static/v1?label=Demo&message=HuggingFace&color=yellow"></a> &ensp; <a href="https://discord.gg/rde6eaE5Ta"><img src="https://img.shields.io/static/v1?label=Discuss&message=Discord&color=purple&logo=discord"></a> &ensp; </div>

This repo contains PyTorch model definitions, pre-trained weights and inference/sampling code for our paper exploring Weak-to-Strong Training of Diffusion Transformer for 4K Text-to-Image Generation. You can find more visualizations on our project page.

PixArt-Ξ£: Weak-to-Strong Training of Diffusion Transformer for 4K Text-to-Image Generation<br> Junsong Chen*, Chongjian Ge*, Enze Xie*†, Yue Wu*, Lewei Yao, Xiaozhe Ren, Zhongdao Wang, Ping Luo, Huchuan Lu, Zhenguo Li <br>Huawei Noah’s Ark Lab, DLUT, HKU, HKUST<br>


Welcome everyone to contributeπŸ”₯πŸ”₯!!

Learning from the previous PixArt-Ξ± project, we will try to keep this repo as simple as possible so that everyone in the PixArt community can use it.


Breaking News πŸ”₯πŸ”₯!!


Contents

-Main

-Guidance

-Others


πŸ†š Compare with PixArt-Ξ±

ModelT5 token lengthVAE2K/4K
PixArt-Ξ£300SDXLβœ…
PixArt-α120SD1.5❌
ModelSample-1Sample-2Sample-3
PixArt-Ξ£<img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample1%CE%A3.webp" width=256><img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample2%CE%A3.webp" width=512><img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample3%CE%A3.webp" width=512>
PixArt-Ξ±<img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample1%CE%B1.webp" width=256><img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample2%CE%B1.webp" width=512><img src="https://raw.githubusercontent.com/PixArt-alpha/PixArt-sigma-project/master/static/images/samples/compare_simga_alpha/sample3%CE%B1.webp" width=512>
PromptClose-up, gray-haired, bearded man in 60s, observing passersby, in wool coat and brown beret, glasses, cinematic.Body shot, a French woman, Photography, French Streets background, backlight, rim light, Fujifilm.Photorealistic closeup video of two pirate ships battling each other as they sail inside a cup of coffee.
<details><summary>Prompt Details</summary>Sample-1 full prompt: An extreme close-up of an gray-haired man with a beard in his 60s, he is deep in thought pondering the history of the universe as he sits at a cafe in Paris, his eyes focus on people offscreen as they walk as he sits mostly motionless, he is dressed in a wool coat suit coat with a button-down shirt , he wears a **brown beret** and glasses and has a very professorial appearance, and the end he offers a subtle closed-mouth smile as if he found the answer to the mystery of life, the lighting is very cinematic with the golden light and the Parisian streets and city in the background, depth of field, cinematic 35mm film.</details>

πŸ”§ Dependencies and Installation

conda create -n pixart python==3.9.0
conda activate pixart
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia

git clone https://github.com/PixArt-alpha/PixArt-sigma.git
cd PixArt-sigma
pip install -r requirements.txt

πŸ”₯ How to Train

1. PixArt Training

First of all.

We start a new repo to build a more user friendly and more compatible codebase. The main model structure is the same as PixArt-Ξ±, you can still develop your function base on the original repo. lso, This repo will support PixArt-alpha in the future.

[!TIP]
Now you can train your model without prior feature extraction. We reform the data structure in PixArt-Ξ± code base, so that everyone can start to train & inference & visualize at the very beginning without any pain.

1.1 Downloading the toy dataset

Download the toy dataset first. The dataset structure for training is:

cd ./pixart-sigma-toy-dataset

Dataset Structure
β”œβ”€β”€InternImgs/  (images are saved here)
β”‚  β”œβ”€β”€000000000000.png
β”‚  β”œβ”€β”€000000000001.png
β”‚  β”œβ”€β”€......
β”œβ”€β”€InternData/
β”‚  β”œβ”€β”€data_info.json    (meta data)
Optional(πŸ‘‡)
β”‚  β”œβ”€β”€img_sdxl_vae_features_1024resolution_ms_new    (run tools/extract_caption_feature.py to generate caption T5 features, same name as images except .npz extension)
β”‚  β”‚  β”œβ”€β”€000000000000.npy
β”‚  β”‚  β”œβ”€β”€000000000001.npy
β”‚  β”‚  β”œβ”€β”€......
β”‚  β”œβ”€β”€caption_features_new
β”‚  β”‚  β”œβ”€β”€000000000000.npz
β”‚  β”‚  β”œβ”€β”€000000000001.npz
β”‚  β”‚  β”œβ”€β”€......
β”‚  β”œβ”€β”€sharegpt4v_caption_features_new    (run tools/extract_caption_feature.py to generate caption T5 features, same name as images except .npz extension)
β”‚  β”‚  β”œβ”€β”€000000000000.npz
β”‚  β”‚  β”œβ”€β”€000000000001.npz
β”‚  β”‚  β”œβ”€β”€......

1.2 Download pretrained checkpoint

# SDXL-VAE, T5 checkpoints
git lfs install
git clone https://huggingface.co/PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers output/pretrained_models/pixart_sigma_sdxlvae_T5_diffusers

# PixArt-Sigma checkpoints
python tools/download.py # environment eg. HF_ENDPOINT=https://hf-mirror.com can use for HuggingFace mirror

1.3 You are ready to train!

Selecting your desired config file from config files dir.

python -m torch.distributed.launch --nproc_per_node=1 --master_port=12345 \
          train_scripts/train.py \
          configs/pixart_sigma_config/PixArt_sigma_xl2_img512_internalms.py \
          --load-from output/pretrained_models/PixArt-Sigma-XL-2-512-MS.pth \
          --work-dir output/your_first_pixart-exp \
          --debug

πŸ’» How to Test

1. Quick start with Gradio

To get started, first install the required dependencies. Make sure you've downloaded the checkpoint files from models(coming soon) to the output/pretrained_models folder, and then run on your local machine:

# SDXL-VAE, T5 checkpoints
git lfs install
git clone https://huggingface.co/PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers output/pixart_sigma_sdxlvae_T5_diffusers

# PixArt-Sigma checkpoints
python tools/download.py

# demo launch
python scripts/interface.py --model_path output/pretrained_models/PixArt-Sigma-XL-2-512-MS.pth --image_size 512 --port 11223

2. Integration in diffusers

[!IMPORTANT]
Upgrade your diffusers to make the PixArtSigmaPipeline available!

pip install git+https://github.com/huggingface/diffusers

For diffusers<0.28.0, check this script for help.

import torch
from diffusers import Transformer2DModel, PixArtSigmaPipeline

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
weight_dtype = torch.float16

transformer = Transformer2DModel.from_pretrained(
    "PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", 
    subfolder='transformer', 
    torch_dtype=weight_dtype,
    use_safetensors=True,
)
pipe = PixArtSigmaPipeline.from_pretrained(
    "PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers",
    transformer=transformer,
    torch_dtype=weight_dtype,
    use_safetensors=True,
)
pipe.to(device)

# Enable memory optimizations.
# pipe.enable_model_cpu_offload()

prompt = "A small cactus with a happy face in the Sahara desert."
image = pipe(prompt).images[0]
image.save("./catcus.png")

3. PixArt Demo

pip install git+https://github.com/huggingface/diffusers

# PixArt-Sigma 1024px
DEMO_PORT=12345 python app/app_pixart_sigma.py

# PixArt-Sigma One step Sampler(DMD)
DEMO_PORT=12345 python app/app_pixart_dmd.py

Let's have a look at a simple example using the http://your-server-ip:12345.

4. Convert .pth checkpoint into diffusers version

Directly download from Hugging Face

or run with:

pip install git+https://github.com/huggingface/diffusers

python tools/convert_pixart_to_diffusers.py --orig_ckpt_path output/pretrained_models/PixArt-Sigma-XL-2-1024-MS.pth --dump_path output/pretrained_models/PixArt-Sigma-XL-2-1024-MS --only_transformer=True --image_size=1024 --version sigma

⏬ Available Models

All models will be automatically downloaded here. You can also choose to download manually from this url.

Model#ParamsCheckpoint pathDownload in OpenXLab
T5 & SDXL-VAE4.5BDiffusers: pixart_sigma_sdxlvae_T5_diffuserscoming soon
PixArt-Ξ£-2560.6Bpth: PixArt-Sigma-XL-2-256x256.pth <br/> Diffusers: PixArt-Sigma-XL-2-256x256coming soon
PixArt-Ξ£-5120.6Bpth: PixArt-Sigma-XL-2-512-MS.pth <br/> Diffusers: PixArt-Sigma-XL-2-512-MScoming soon
PixArt-Ξ±-512-DMD0.6BDiffusers: PixArt-Alpha-DMD-XL-2-512x512coming soon
PixArt-Ξ£-10240.6Bpth: PixArt-Sigma-XL-2-1024-MS.pth <br/> Diffusers: PixArt-Sigma-XL-2-1024-MScoming soon
PixArt-Ξ£-2K0.6Bpth: PixArt-Sigma-XL-2-2K-MS.pth <br/> Diffusers: PixArt-Sigma-XL-2-2K-MScoming soon

πŸ’ͺTo-Do List

We will try our best to release


πŸ€—Acknowledgements

πŸ“–BibTeX

@misc{chen2024pixartsigma,
  title={PixArt-\Sigma: Weak-to-Strong Training of Diffusion Transformer for 4K Text-to-Image Generation},
  author={Junsong Chen and Chongjian Ge and Enze Xie and Yue Wu and Lewei Yao and Xiaozhe Ren and Zhongdao Wang and Ping Luo and Huchuan Lu and Zhenguo Li},
  year={2024},
  eprint={2403.04692},
  archivePrefix={arXiv},
  primaryClass={cs.CV}

Star History

Star History Chart