Autoregressive Diffusion - Pytorch
Project description
Autoregressive Diffusion - Pytorch
Implementation of the architecture behind Autoregressive Image Generation without Vector Quantization in Pytorch
Official repository has been released here
oxford flowers at 96k steps
Install
$ pip install autoregressive-diffusion-pytorch
Usage
import torch
from autoregressive_diffusion_pytorch import AutoregressiveDiffusion
model = AutoregressiveDiffusion(
dim_input = 512,
dim = 1024,
max_seq_len = 32,
depth = 8,
mlp_depth = 3,
mlp_width = 1024
)
seq = torch.randn(3, 32, 512)
loss = model(seq)
loss.backward()
sampled = model.sample(batch_size = 3)
assert sampled.shape == seq.shape
For images treated as a sequence of tokens (as in paper)
import torch
from autoregressive_diffusion_pytorch import ImageAutoregressiveDiffusion
model = ImageAutoregressiveDiffusion(
model = dict(
dim = 1024,
depth = 12,
heads = 12,
),
image_size = 64,
patch_size = 8
)
images = torch.randn(3, 3, 64, 64)
loss = model(images)
loss.backward()
sampled = model.sample(batch_size = 3)
assert sampled.shape == images.shape
An images trainer
import torch
from autoregressive_diffusion_pytorch import (
ImageDataset,
ImageAutoregressiveDiffusion,
ImageTrainer
)
dataset = ImageDataset(
'/path/to/your/images',
image_size = 128
)
model = ImageAutoregressiveDiffusion(
model = dict(
dim = 512
),
image_size = 128,
patch_size = 16
)
trainer = ImageTrainer(
model = model,
dataset = dataset
)
trainer()
For an improvised version using flow matching, just import ImageAutoregressiveFlow
and AutoregressiveFlow
instead
The rest is the same
ex.
import torch
from autoregressive_diffusion_pytorch import (
ImageDataset,
ImageTrainer,
ImageAutoregressiveFlow,
)
dataset = ImageDataset(
'/path/to/your/images',
image_size = 128
)
model = ImageAutoregressiveFlow(
model = dict(
dim = 512
),
image_size = 128,
patch_size = 16
)
trainer = ImageTrainer(
model = model,
dataset = dataset
)
trainer()
Citations
@article{Li2024AutoregressiveIG,
title = {Autoregressive Image Generation without Vector Quantization},
author = {Tianhong Li and Yonglong Tian and He Li and Mingyang Deng and Kaiming He},
journal = {ArXiv},
year = {2024},
volume = {abs/2406.11838},
url = {https://api.semanticscholar.org/CorpusID:270560593}
}
@article{Wu2023ARDiffusionAD,
title = {AR-Diffusion: Auto-Regressive Diffusion Model for Text Generation},
author = {Tong Wu and Zhihao Fan and Xiao Liu and Yeyun Gong and Yelong Shen and Jian Jiao and Haitao Zheng and Juntao Li and Zhongyu Wei and Jian Guo and Nan Duan and Weizhu Chen},
journal = {ArXiv},
year = {2023},
volume = {abs/2305.09515},
url = {https://api.semanticscholar.org/CorpusID:258714669}
}
@article{Karras2022ElucidatingTD,
title = {Elucidating the Design Space of Diffusion-Based Generative Models},
author = {Tero Karras and Miika Aittala and Timo Aila and Samuli Laine},
journal = {ArXiv},
year = {2022},
volume = {abs/2206.00364},
url = {https://api.semanticscholar.org/CorpusID:249240415}
}
@article{Liu2022FlowSA,
title = {Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow},
author = {Xingchao Liu and Chengyue Gong and Qiang Liu},
journal = {ArXiv},
year = {2022},
volume = {abs/2209.03003},
url = {https://api.semanticscholar.org/CorpusID:252111177}
}
@article{Esser2024ScalingRF,
title = {Scaling Rectified Flow Transformers for High-Resolution Image Synthesis},
author = {Patrick Esser and Sumith Kulal and A. Blattmann and Rahim Entezari and Jonas Muller and Harry Saini and Yam Levi and Dominik Lorenz and Axel Sauer and Frederic Boesel and Dustin Podell and Tim Dockhorn and Zion English and Kyle Lacey and Alex Goodwin and Yannik Marek and Robin Rombach},
journal = {ArXiv},
year = {2024},
volume = {abs/2403.03206},
url = {https://api.semanticscholar.org/CorpusID:268247980}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file autoregressive_diffusion_pytorch-0.2.8.tar.gz
.
File metadata
- Download URL: autoregressive_diffusion_pytorch-0.2.8.tar.gz
- Upload date:
- Size: 682.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b644ed792b1e6a7bc5d4efa6dee82302aae60bfe00d5c40a418494665d06c839 |
|
MD5 | 08972ccf0bcf1f9d10d4a5eddacb79de |
|
BLAKE2b-256 | 704f6247f2a8e0cb6ed4d4c8ec214b1b1f96e6ebca56b53edc605ed309ed3b2d |
File details
Details for the file autoregressive_diffusion_pytorch-0.2.8-py3-none-any.whl
.
File metadata
- Download URL: autoregressive_diffusion_pytorch-0.2.8-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16adbb8018476fb32cd095de235043f660d22b874e671ac18ccd83be6d2d10a1 |
|
MD5 | d905acb7c3e62996779d563129fa5957 |
|
BLAKE2b-256 | 02d8d2f487d9049eacdecae810a9f1f8c0f37e4b06984dac076f2497ae00a0db |