Rectified Flow in Pytorch
Project description
Rectified Flow - Pytorch (wip)
Implementation of rectified flow and some of its followup research / improvements in Pytorch
Install
$ pip install rectified-flow-pytorch
Usage
import torch
from torch import nn
from rectified_flow_pytorch import RectifiedFlow
model = nn.Conv2d(3, 3, 1)
rectified_flow = RectifiedFlow(model, time_cond_kwarg = None)
images = torch.randn(1, 3, 256, 256)
loss = rectified_flow(images)
loss.backward()
sampled = rectified_flow.sample()
assert sampled.shape[1:] == images.shape[1:]
For reflow as described in the paper
import torch
from torch import nn
from rectified_flow_pytorch import RectifiedFlow, Reflow
model = nn.Conv2d(3, 3, 1)
rectified_flow = RectifiedFlow(model, time_cond_kwarg = None)
images = torch.randn(1, 3, 256, 256)
loss = rectified_flow(images)
loss.backward()
# do the above for many real images
reflow = Reflow(rectified_flow)
reflow_loss = reflow()
reflow_loss.backward()
# then do the above in a loop many times for reflow - you can reflow multiple times by redefining Reflow(reflow.model) and looping again
sampled = reflow.sample()
assert sampled.shape[1:] == images.shape[1:]
Citations
@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{Lee2024ImprovingTT,
title = {Improving the Training of Rectified Flows},
author = {Sangyun Lee and Zinan Lin and Giulia Fanti},
journal = {ArXiv},
year = {2024},
volume = {abs/2405.20320},
url = {https://api.semanticscholar.org/CorpusID:270123378}
}
@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
Close
Hashes for rectified_flow_pytorch-0.0.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168ef9ec9343475e90626fe97680f07195afe48eca9b8900e9e347d14e6c8f0c |
|
MD5 | 8ac17f43fcbdba4938c69d82a3a8aceb |
|
BLAKE2b-256 | 84d5b1626d7ab44295626b92176ddfc064dd806a15e097f5457f27bcc539d855 |
Close
Hashes for rectified_flow_pytorch-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7105e118de0280607e6ceab6aac76497ebdbb8b2c2e252e755225e3f18ee3e92 |
|
MD5 | f3d3a1c4684588fb460ded5bad6c7b2f |
|
BLAKE2b-256 | 7bdc27a4e68b8b9df9da108160f12d6d7da34c94bbb07bfe4b81eb0fa31f0ef5 |