Skip to main content

Rectified Flow - Pytorch

Implementation of rectified flow and some of its followup research / improvements in Pytorch

Tutorial from Dr. Scott Hawley

Youtube AI Educators - Yannic | Outlier

32 batch size, 11k steps oxford flowers

Appreciation

  • Lucas for the LSD flow, SoFlow, and Split Mean Flow implementations!

  • Pranoy for the Unconstrained Alignment (UA) Flow implementation, Laplacian multiscale flow matching, as well as various bug fixes!

Install

$ pip install rectified-flow-pytorch

Usage

import torch
from rectified_flow_pytorch import RectifiedFlow, Unet

model = Unet(dim = 64)

rectified_flow = RectifiedFlow(model)

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 rectified_flow_pytorch import RectifiedFlow, Reflow, Unet

model = Unet(dim = 64)

rectified_flow = RectifiedFlow(model)

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:]

With a Trainer based on accelerate

import torch
from rectified_flow_pytorch import RectifiedFlow, ImageDataset, Unet, Trainer

model = Unet(dim = 64)

rectified_flow = RectifiedFlow(model)

img_dataset = ImageDataset(
    folder = './path/to/your/images',
    image_size = 256
)

trainer = Trainer(
    rectified_flow,
    dataset = img_dataset,
    num_train_steps = 70_000,
    results_folder = './results'   # samples will be saved periodically to this folder
)

trainer()

Examples

Quick test on oxford flowers

$ pip install .[examples]

Then

$ python train_oxford.py

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}
}
@article{Li2024ImmiscibleDA,
    title   = {Immiscible Diffusion: Accelerating Diffusion Training with Noise Assignment},
    author  = {Yiheng Li and Heyang Jiang and Akio Kodaira and Masayoshi Tomizuka and Kurt Keutzer and Chenfeng Xu},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2406.12303},
    url     = {https://api.semanticscholar.org/CorpusID:270562607}
}
@article{Yang2024ConsistencyFM,
    title   = {Consistency Flow Matching: Defining Straight Flows with Velocity Consistency},
    author  = {Ling Yang and Zixiang Zhang and Zhilong Zhang and Xingchao Liu and Minkai Xu and Wentao Zhang and Chenlin Meng and Stefano Ermon and Bin Cui},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2407.02398},
    url     = {https://api.semanticscholar.org/CorpusID:270878436}
}
@article{Zhu2024HyperConnections,
    title   = {Hyper-Connections},
    author  = {Defa Zhu and Hongzhi Huang and Zihao Huang and Yutao Zeng and Yunyao Mao and Banggu Wu and Qiyang Min and Xun Zhou},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2409.19606},
    url     = {https://api.semanticscholar.org/CorpusID:272987528}
}
@inproceedings{Sun2025F5RTTSIF,
    title   = {F5R-TTS: Improving Flow-Matching based Text-to-Speech with Group Relative Policy Optimization},
    author  = {Xiaohui Sun and Ruitong Xiao and Jianye Mo and Bowen Wu and Qun Yu and Baoxun Wang},
    year    = {2025},
    url     = {https://api.semanticscholar.org/CorpusID:277510064}
}
@inproceedings{Geng2025MeanFF,
    title   = {Mean Flows for One-step Generative Modeling},
    author  = {Zhengyang Geng and Mingyang Deng and Xingjian Bai and J. Zico Kolter and Kaiming He},
    year    = {2025},
    url     = {https://api.semanticscholar.org/CorpusID:278769814}
}
@article{Sun2025IsNC,
    title   = {Is Noise Conditioning Necessary for Denoising Generative Models?},
    author  = {Qiao Sun and Zhicheng Jiang and Hanhong Zhao and Kaiming He},
    journal = {ArXiv},
    year    = {2025},
    volume  = {abs/2502.13129},
    url     = {https://api.semanticscholar.org/CorpusID:276421559}
}
@article{Park2025FlowQ,
    title   = {Flow Q-Learning},
    author  = {Seohong Park and Qiyang Li and Sergey Levine},
    journal = {ArXiv},
    year    = {2025},
    volume  = {abs/2502.02538},
    url     = {https://api.semanticscholar.org/CorpusID:276107180}
}
@misc{mcallister2025flowmatchingpolicygradients,
    title   = {Flow Matching Policy Gradients},
    author  = {David McAllister and Songwei Ge and Brent Yi and Chung Min Kim and Ethan Weber and Hongsuk Choi and Haiwen Feng and Angjoo Kanazawa},
    year    = {2025},
    eprint  = {2507.21053},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2507.21053},
}
@misc{li2025basicsletdenoisinggenerative,
    title   = {Back to Basics: Let Denoising Generative Models Denoise},
    author  = {Tianhong Li and Kaiming He},
    year    = {2025},
    eprint  = {2511.13720},
    archivePrefix = {arXiv},
    primaryClass = {cs.CV},
    url     = {https://arxiv.org/abs/2511.13720},
}
@misc{clavier2024bootstrappingexpectilesreinforcementlearning,
    title   = {Bootstrapping Expectiles in Reinforcement Learning},
    author  = {Pierre Clavier and Emmanuel Rachelson and Erwan Le Pennec and Matthieu Geist},
    year    = {2024},
    eprint  = {2406.04081},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2406.04081},
}
@inproceedings{anonymous2025flow,
    title   = {Flow Policy Gradients for Legged Robots},
    author  = {Anonymous},
    booktitle = {Submitted to The Fourteenth International Conference on Learning Representations},
    year    = {2025},
    url     = {https://openreview.net/forum?id=BA6n0nmagi},
    note    = {under review}
}
@misc{luo2025soflowsolutionflowmodels,
    title   = {SoFlow: Solution Flow Models for One-Step Generative Modeling},
    author  = {Tianze Luo and Haotian Yuan and Zhuang Liu},
    year    = {2025},
    eprint  = {2512.15657},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2512.15657},
}
@misc{wang2025equilibriummatchinggenerativemodeling,
    title   = {Equilibrium Matching: Generative Modeling with Implicit Energy-Based Models},
    author  = {Runqian Wang and Yilun Du},
    year    = {2025},
    eprint  = {2510.02300},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2510.02300},
}
@misc{boffi2025buildconsistencymodellearning,
    title   = {How to build a consistency model: Learning flow maps via self-distillation},
    author  = {Nicholas M. Boffi and Michael S. Albergo and Eric Vanden-Eijnden},
    year    = {2025},
    eprint  = {2505.18825},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2505.18825},
}
@misc{chefer2026self,
    title   = {Self-Supervised Flow Matching for Scalable Multi-Modal Synthesis},
    author  = {Hila Chefer and Patrick Esser and Dominik Lorenz and Dustin Podell and Vikash Raja and Vinh Tong and Antonio Torralba and Robin Rombach},
    year    = {2026},
    url     = {https://bfl.ai/research/self-flow},
    note    = {Preprint}
}
@misc{farebrother2025temporaldifferenceflows,
    title   = {Temporal Difference Flows},
    author  = {Jesse Farebrother and Matteo Pirotta and Andrea Tirinzoni and Rémi Munos and Alessandro Lazaric and Ahmed Touati},
    year    = {2025},
    eprint  = {2503.09817},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2503.09817},
}
@misc{farebrother2026compositionalplanningjumpyworld,
    title   = {Compositional Planning with Jumpy World Models},
    author  = {Jesse Farebrother and Matteo Pirotta and Andrea Tirinzoni and Marc G. Bellemare and Alessandro Lazaric and Ahmed Touati},
    year    = {2026},
    eprint  = {2602.19634},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2602.19634},
}
@inproceedings{dong2026valueflows,
    title   = {Value Flows},
    author  = {Perry Dong and Chongyi Zheng and Chelsea Finn and Dorsa Sadigh and Benjamin Eysenbach},
    booktitle = {International Conference on Learning Representations},
    year    = {2026},
    url     = {https://pd-perry.github.io/value-flows}
}
@misc{curvo2026followmeanreferenceguidedflow,
    title   = {Follow the Mean: Reference-Guided Flow Matching},
    author  = {Pedro M. P. Curvo and Maksim Zhdanov and Floor Eijkelboom and Jan-Willem van de Meent},
    year    = {2026},
    eprint  = {2605.10302},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2605.10302},
}
@misc{shin2026adaptiveactionchunkingmultichunk,
    title   = {Adaptive Action Chunking via Multi-Chunk Q Value Estimation},
    author  = {Yongjae Shin and Jongseong Chae and Seongmin Kim and Jongeui Park and Youngchul Sung},
    year    = {2026},
    eprint  = {2605.10044},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2605.10044},
}
@misc{zhao2026laplacianmultiscaleflowmatching,
    title   = {Laplacian Multi-scale Flow Matching for Generative Modeling},
    author  = {Zelin Zhao and Petr Molodyk and Haotian Xue and Yongxin Chen},
    year    = {2026},
    eprint  = {2602.19461},
    archivePrefix = {arXiv},
    primaryClass = {cs.CV},
    url     = {https://arxiv.org/abs/2602.19461},
}
@misc{huang2026recursiveflowmatching,
    title   = {Recursive Flow Matching},
    author  = {Jiahe Huang and Sihan Xu and Sharvaree Vadgama and Rose Yu},
    year    = {2026},
    eprint  = {2605.26535},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2605.26535},
}
@misc{gladstone2026explorativemodelingunlockingpretraining,
    title   = {Explorative Modeling: Unlocking a Third Pretraining Axis and End-to-End Generation},
    author  = {Alexi Gladstone and Heng Ji and Yilun Du},
    year    = {2026},
    eprint  = {2607.27372},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2607.27372},
}

Metadata

Release files for rectified-flow-pytorch 0.12.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rectified-flow-pytorch 0.12.1
File Size Uploaded
rectified_flow_pytorch-0.12.1.tar.gz 48.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rectified-flow-pytorch 0.12.1
File Interpreter ABI Platform
rectified_flow_pytorch-0.12.1-py3-none-any.whl Python 3 none any Details

Total release size: 111.9 kB

Release files / rectified_flow_pytorch-0.12.1.tar.gz

Download URL rectified_flow_pytorch-0.12.1.tar.gz
Size 48.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0a9eac99fc3494c52353cffc450771288339a4a4a73a54ce1ce8e1198dacace9
BLAKE2b-256 checksum
How to use checksums
b2dee600776ab4ca64719daa0b5476ec6409fc9ec85a0c683ca053bcc302e3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / rectified_flow_pytorch-0.12.1-py3-none-any.whl

Download URL rectified_flow_pytorch-0.12.1-py3-none-any.whl
Size 63.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc6e5b28fb163fce63b4a705d0fcbbeefb24853ece75519d2f628badec554c53
BLAKE2b-256 checksum
How to use checksums
e96c8d79b1584bd03324d70e343cfb09834e2bfc7d4c50bfcbba75bf83893305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.12.1 This release

2 release files

0.11.5

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.8

2 release files

0.10.7

2 release files

0.10.4

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.19

2 release files

0.9.18

2 release files

0.9.17

2 release files

0.9.16

2 release files

0.9.14

2 release files

0.9.12

2 release files

0.9.11

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.6.6

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.20

2 release files

0.4.19

2 release files

0.4.18

2 release files

0.4.17

2 release files

0.4.16

2 release files

0.4.15

2 release files

0.4.14

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.29

2 release files

0.3.27

2 release files

0.3.26

2 release files

0.3.25

2 release files

0.3.24

2 release files

0.3.23

2 release files

0.3.22

2 release files

0.3.21

2 release files

0.3.20

2 release files

0.3.19

2 release files

0.3.17

2 release files

0.3.15

2 release files

0.3.14

2 release files

0.3.12

2 release files

0.3.11

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.12

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page