autoregressive-diffusion-pytorch


Nameautoregressive-diffusion-pytorch JSON
Version 0.2.7 PyPI version JSON
download
home_pageNone
SummaryAutoregressive Diffusion - Pytorch
upload_time2024-09-26 18:18:29
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT 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 denoising diffusion transformers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./ar-diffusion.png" width="400px"></img>

## Autoregressive Diffusion - Pytorch

Implementation of the architecture behind <a href="https://arxiv.org/abs/2406.11838">Autoregressive Image Generation without Vector Quantization</a> in Pytorch

Official repository has been released <a href="https://github.com/LTH14/mar">here</a>

<a href="https://github.com/lucidrains/transfusion-pytorch">Alternative route</a>

<img src="./images/results.96600.png" width="400px"></img>

*oxford flowers at 96k steps*

## Install

```bash
$ pip install autoregressive-diffusion-pytorch
```

## Usage

```python
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)

```python
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

```python
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.

```python
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

```bibtex
@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}
}
```

```bibtex
@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}
}
```

```bibtex
@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}
}
```

```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{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}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "autoregressive-diffusion-pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, denoising diffusion, transformers",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8e/93/e182bff78bf2b2c718a4b064b1ec6aaf091e874189f373ae9ce8ecb1bce8/autoregressive_diffusion_pytorch-0.2.7.tar.gz",
    "platform": null,
    "description": "<img src=\"./ar-diffusion.png\" width=\"400px\"></img>\n\n## Autoregressive Diffusion - Pytorch\n\nImplementation of the architecture behind <a href=\"https://arxiv.org/abs/2406.11838\">Autoregressive Image Generation without Vector Quantization</a> in Pytorch\n\nOfficial repository has been released <a href=\"https://github.com/LTH14/mar\">here</a>\n\n<a href=\"https://github.com/lucidrains/transfusion-pytorch\">Alternative route</a>\n\n<img src=\"./images/results.96600.png\" width=\"400px\"></img>\n\n*oxford flowers at 96k steps*\n\n## Install\n\n```bash\n$ pip install autoregressive-diffusion-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom autoregressive_diffusion_pytorch import AutoregressiveDiffusion\n\nmodel = AutoregressiveDiffusion(\n    dim_input = 512,\n    dim = 1024,\n    max_seq_len = 32,\n    depth = 8,\n    mlp_depth = 3,\n    mlp_width = 1024\n)\n\nseq = torch.randn(3, 32, 512)\n\nloss = model(seq)\nloss.backward()\n\nsampled = model.sample(batch_size = 3)\n\nassert sampled.shape == seq.shape\n\n```\n\nFor images treated as a sequence of tokens (as in paper)\n\n```python\nimport torch\nfrom autoregressive_diffusion_pytorch import ImageAutoregressiveDiffusion\n\nmodel = ImageAutoregressiveDiffusion(\n    model = dict(\n        dim = 1024,\n        depth = 12,\n        heads = 12,\n    ),\n    image_size = 64,\n    patch_size = 8\n)\n\nimages = torch.randn(3, 3, 64, 64)\n\nloss = model(images)\nloss.backward()\n\nsampled = model.sample(batch_size = 3)\n\nassert sampled.shape == images.shape\n\n```\n\nAn images trainer\n\n```python\nimport torch\n\nfrom autoregressive_diffusion_pytorch import (\n    ImageDataset,\n    ImageAutoregressiveDiffusion,\n    ImageTrainer\n)\n\ndataset = ImageDataset(\n    '/path/to/your/images',\n    image_size = 128\n)\n\nmodel = ImageAutoregressiveDiffusion(\n    model = dict(\n        dim = 512\n    ),\n    image_size = 128,\n    patch_size = 16\n)\n\ntrainer = ImageTrainer(\n    model = model,\n    dataset = dataset\n)\n\ntrainer()\n```\n\nFor an improvised version using flow matching, just import `ImageAutoregressiveFlow` and `AutoregressiveFlow` instead\n\nThe rest is the same\n\nex.\n\n```python\nimport torch\n\nfrom autoregressive_diffusion_pytorch import (\n    ImageDataset,\n    ImageTrainer,\n    ImageAutoregressiveFlow,\n)\n\ndataset = ImageDataset(\n    '/path/to/your/images',\n    image_size = 128\n)\n\nmodel = ImageAutoregressiveFlow(\n    model = dict(\n        dim = 512\n    ),\n    image_size = 128,\n    patch_size = 16\n)\n\ntrainer = ImageTrainer(\n    model = model,\n    dataset = dataset\n)\n\ntrainer()\n```\n\n## Citations\n\n```bibtex\n@article{Li2024AutoregressiveIG,\n    title   = {Autoregressive Image Generation without Vector Quantization},\n    author  = {Tianhong Li and Yonglong Tian and He Li and Mingyang Deng and Kaiming He},\n    journal = {ArXiv},\n    year    = {2024},\n    volume  = {abs/2406.11838},\n    url     = {https://api.semanticscholar.org/CorpusID:270560593}\n}\n```\n\n```bibtex\n@article{Wu2023ARDiffusionAD,\n    title     = {AR-Diffusion: Auto-Regressive Diffusion Model for Text Generation},\n    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},\n    journal   = {ArXiv},\n    year      = {2023},\n    volume    = {abs/2305.09515},\n    url       = {https://api.semanticscholar.org/CorpusID:258714669}\n}\n```\n\n```bibtex\n@article{Karras2022ElucidatingTD,\n    title   = {Elucidating the Design Space of Diffusion-Based Generative Models},\n    author  = {Tero Karras and Miika Aittala and Timo Aila and Samuli Laine},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs/2206.00364},\n    url     = {https://api.semanticscholar.org/CorpusID:249240415}\n}\n```\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{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",
    "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": "Autoregressive Diffusion - Pytorch",
    "version": "0.2.7",
    "project_urls": {
        "Homepage": "https://pypi.org/project/autoregressive-diffusion-pytorch/",
        "Repository": "https://github.com/lucidrains/autoregressive-diffusion-pytorch"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " denoising diffusion",
        " transformers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "423ea2b30e849cd722956a52394f0202a7090d3dd5889f9c0efcbccb01cb5248",
                "md5": "2850ba43029644cb36b69508524893ac",
                "sha256": "33b427947c43db424899c5a706fc41aeb5d625f1ae1e3b6f6520f5c74fb3bc93"
            },
            "downloads": -1,
            "filename": "autoregressive_diffusion_pytorch-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2850ba43029644cb36b69508524893ac",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4378,
            "upload_time": "2024-09-26T18:18:27",
            "upload_time_iso_8601": "2024-09-26T18:18:27.756786Z",
            "url": "https://files.pythonhosted.org/packages/42/3e/a2b30e849cd722956a52394f0202a7090d3dd5889f9c0efcbccb01cb5248/autoregressive_diffusion_pytorch-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e93e182bff78bf2b2c718a4b064b1ec6aaf091e874189f373ae9ce8ecb1bce8",
                "md5": "bb0d2bc7d7cb5f13e98a4258dd803de9",
                "sha256": "24a98e2257c94b7e5955376bd1ad04d541f54aa2a3b0884dba82b42b5d907dc9"
            },
            "downloads": -1,
            "filename": "autoregressive_diffusion_pytorch-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "bb0d2bc7d7cb5f13e98a4258dd803de9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 682712,
            "upload_time": "2024-09-26T18:18:29",
            "upload_time_iso_8601": "2024-09-26T18:18:29.641524Z",
            "url": "https://files.pythonhosted.org/packages/8e/93/e182bff78bf2b2c718a4b064b1ec6aaf091e874189f373ae9ce8ecb1bce8/autoregressive_diffusion_pytorch-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 18:18:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "autoregressive-diffusion-pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "autoregressive-diffusion-pytorch"
}
        
Elapsed time: 0.71103s