Name | rectified-flow-pytorch JSON |
Version |
0.1.11
JSON |
| download |
home_page | None |
Summary | Rectified Flow in Pytorch |
upload_time | 2024-11-05 15:09:42 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2024 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
artificial intelligence
deep learning
rectified flow
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img src="./rf.png" width="400px"></img>
## Rectified Flow - Pytorch
Implementation of <a href="https://www.cs.utexas.edu/~lqiang/rectflow/html/intro.html">rectified flow</a> and some of its followup research / improvements in Pytorch
<img src="./images/oxford-flowers.sample.png" width="350px"></img>
*32 batch size, 11k steps oxford flowers*
## Install
```bash
$ pip install rectified-flow-pytorch
```
## Usage
```python
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
```python
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`
```python
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()
```
## Citations
```bibtex
@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}
}
```
```bibtex
@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}
}
```
```bibtex
@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}
}
```
```bibtex
@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}
}
```
```bibtex
@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}
}
```
```bibtex
@inproceedings{Yao2024FasterDiTTF,
title = {FasterDiT: Towards Faster Diffusion Transformers Training without Architecture Modification},
author = {Jingfeng Yao and Wang Cheng and Wenyu Liu and Xinggang Wang},
year = {2024},
url = {https://api.semanticscholar.org/CorpusID:273346237}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "rectified-flow-pytorch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "artificial intelligence, deep learning, rectified flow",
"author": null,
"author_email": "Phil Wang <lucidrains@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/cc/43/713c0b9a570a4209fadda54e844ef9f72c5e7b749af451538e68c7aa0abb/rectified_flow_pytorch-0.1.11.tar.gz",
"platform": null,
"description": "<img src=\"./rf.png\" width=\"400px\"></img>\n\n## Rectified Flow - Pytorch\n\nImplementation of <a href=\"https://www.cs.utexas.edu/~lqiang/rectflow/html/intro.html\">rectified flow</a> and some of its followup research / improvements in Pytorch\n\n<img src=\"./images/oxford-flowers.sample.png\" width=\"350px\"></img>\n\n*32 batch size, 11k steps oxford flowers*\n\n## Install\n\n```bash\n$ pip install rectified-flow-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom rectified_flow_pytorch import RectifiedFlow, Unet\n\nmodel = Unet(dim = 64)\n\nrectified_flow = RectifiedFlow(model)\n\nimages = torch.randn(1, 3, 256, 256)\n\nloss = rectified_flow(images)\nloss.backward()\n\nsampled = rectified_flow.sample()\nassert sampled.shape[1:] == images.shape[1:]\n```\n\nFor reflow as described in the paper\n\n```python\nimport torch\nfrom rectified_flow_pytorch import RectifiedFlow, Reflow, Unet\n\nmodel = Unet(dim = 64)\n\nrectified_flow = RectifiedFlow(model)\n\nimages = torch.randn(1, 3, 256, 256)\n\nloss = rectified_flow(images)\nloss.backward()\n\n# do the above for many real images\n\nreflow = Reflow(rectified_flow)\n\nreflow_loss = reflow()\nreflow_loss.backward()\n\n# then do the above in a loop many times for reflow - you can reflow multiple times by redefining Reflow(reflow.model) and looping again\n\nsampled = reflow.sample()\nassert sampled.shape[1:] == images.shape[1:]\n```\n\nWith a `Trainer` based on `accelerate`\n\n```python\nimport torch\nfrom rectified_flow_pytorch import RectifiedFlow, ImageDataset, Unet, Trainer\n\nmodel = Unet(dim = 64)\n\nrectified_flow = RectifiedFlow(model)\n\nimg_dataset = ImageDataset(\n folder = './path/to/your/images',\n image_size = 256\n)\n\ntrainer = Trainer(\n rectified_flow,\n dataset = img_dataset,\n num_train_steps = 70_000,\n results_folder = './results' # samples will be saved periodically to this folder\n)\n\ntrainer()\n```\n\n## Citations\n\n```bibtex\n@article{Liu2022FlowSA,\n title = {Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow},\n author = {Xingchao Liu and Chengyue Gong and Qiang Liu},\n journal = {ArXiv},\n year = {2022},\n volume = {abs/2209.03003},\n url = {https://api.semanticscholar.org/CorpusID:252111177}\n}\n```\n\n```bibtex\n@article{Lee2024ImprovingTT,\n title = {Improving the Training of Rectified Flows},\n author = {Sangyun Lee and Zinan Lin and Giulia Fanti},\n journal = {ArXiv},\n year = {2024},\n volume = {abs/2405.20320},\n url = {https://api.semanticscholar.org/CorpusID:270123378}\n}\n```\n\n```bibtex\n@article{Esser2024ScalingRF,\n title = {Scaling Rectified Flow Transformers for High-Resolution Image Synthesis},\n 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},\n journal = {ArXiv},\n year = {2024},\n volume = {abs/2403.03206},\n url = {https://api.semanticscholar.org/CorpusID:268247980}\n}\n```\n\n```bibtex\n@article{Li2024ImmiscibleDA,\n title = {Immiscible Diffusion: Accelerating Diffusion Training with Noise Assignment},\n author = {Yiheng Li and Heyang Jiang and Akio Kodaira and Masayoshi Tomizuka and Kurt Keutzer and Chenfeng Xu},\n journal = {ArXiv},\n year = {2024},\n volume = {abs/2406.12303},\n url = {https://api.semanticscholar.org/CorpusID:270562607}\n}\n```\n\n```bibtex\n@article{Yang2024ConsistencyFM,\n title = {Consistency Flow Matching: Defining Straight Flows with Velocity Consistency},\n 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},\n journal = {ArXiv},\n year = {2024},\n volume = {abs/2407.02398},\n url = {https://api.semanticscholar.org/CorpusID:270878436}\n}\n```\n\n```bibtex\n@inproceedings{Yao2024FasterDiTTF,\n title = {FasterDiT: Towards Faster Diffusion Transformers Training without Architecture Modification},\n author = {Jingfeng Yao and Wang Cheng and Wenyu Liu and Xinggang Wang},\n year = {2024},\n url = {https://api.semanticscholar.org/CorpusID:273346237}\n}\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Rectified Flow in Pytorch",
"version": "0.1.11",
"project_urls": {
"Homepage": "https://pypi.org/project/rectified-flow-pytorch/",
"Repository": "https://github.com/lucidrains/rectified-flow-pytorch"
},
"split_keywords": [
"artificial intelligence",
" deep learning",
" rectified flow"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2372872f6f4cd2f286c8f6d80b71d62037a4b138991c18969ee6a2bfee98ca46",
"md5": "079d612e022b7e35b7ba60357c4121bc",
"sha256": "c46e53b18d999521b7292b1dbb853de321fecb274507c15a8128e8bd418b8a53"
},
"downloads": -1,
"filename": "rectified_flow_pytorch-0.1.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "079d612e022b7e35b7ba60357c4121bc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14854,
"upload_time": "2024-11-05T15:09:40",
"upload_time_iso_8601": "2024-11-05T15:09:40.474695Z",
"url": "https://files.pythonhosted.org/packages/23/72/872f6f4cd2f286c8f6d80b71d62037a4b138991c18969ee6a2bfee98ca46/rectified_flow_pytorch-0.1.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cc43713c0b9a570a4209fadda54e844ef9f72c5e7b749af451538e68c7aa0abb",
"md5": "5b2ddcde44a88707d462dc81334553af",
"sha256": "cd35451609933ee5df3fd778b708e7ca601f10ef9880914dc489a93c5277b959"
},
"downloads": -1,
"filename": "rectified_flow_pytorch-0.1.11.tar.gz",
"has_sig": false,
"md5_digest": "5b2ddcde44a88707d462dc81334553af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 2115636,
"upload_time": "2024-11-05T15:09:42",
"upload_time_iso_8601": "2024-11-05T15:09:42.668759Z",
"url": "https://files.pythonhosted.org/packages/cc/43/713c0b9a570a4209fadda54e844ef9f72c5e7b749af451538e68c7aa0abb/rectified_flow_pytorch-0.1.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-05 15:09:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lucidrains",
"github_project": "rectified-flow-pytorch",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rectified-flow-pytorch"
}