pi-zero-pytorch


Namepi-zero-pytorch JSON
Version 0.0.49 PyPI version JSON
download
home_pageNone
Summaryπ0 in Pytorch
upload_time2024-12-18 18:49:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
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 flow policy robotic foundation model transformers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./fig3.png" width="400px"></img>

## pi-zero-pytorch (wip)

Implementation of <a href="https://www.physicalintelligence.company/blog/pi0">π₀</a> the robotic foundation model architecture proposed by Physical Intelligence

Summary of this work would be that it is a simplified <a href="https://github.com/lucidrains/transfusion-pytorch">Transfusion</a> (Zhou et al.) with influence from <a href="https://arxiv.org/abs/2403.03206">Stable Diffusion 3</a> (Esser et al.), mainly the adoption of flow matching instead of diffusion for policy generation, as well as the separation of parameters (<a href="https://github.com/lucidrains/mmdit/blob/main/mmdit/mmdit_pytorch.py#L43">Joint Attention</a> from mmDIT). They build on top of a pretrained vision language model, PaliGemma 2B.

### Appreciation

- [Einops](https://github.com/arogozhnikov/einops) for the amazing [pack and unpack](https://einops.rocks/4-pack-and-unpack/), used extensively here for managing various token sets

- [Flex Attention](https://pytorch.org/blog/flexattention/) for allowing for easy mixture of autoregressive and bidirectional attention

- [@Wonder1905](https://github.com/Wonder1905) for the code review and identifying issues

- You? maybe a phd student who wants to contribute to the latest SOTA architecture for behavioral cloning?

### Install

```bash
$ pip install pi-zero-pytorch
```

### Usage

```python
import torch
from pi_zero_pytorch import π0

model = π0(
    dim = 512,
    dim_action_input = 6,
    dim_joint_state = 12,
    num_tokens = 20_000
)

vision = torch.randn(1, 1024, 512)
commands = torch.randint(0, 20_000, (1, 1024))
joint_state = torch.randn(1, 12)
actions = torch.randn(1, 32, 6)

loss, _ = model(vision, commands, joint_state, actions)
loss.backward()

# after much training

sampled_actions = model(vision, commands, joint_state, trajectory_length = 32) # (1, 32, 6)
```

### Contributing

At the project root, run

```bash
$ pip install '.[test]' # or `uv pip install '.[test]'`
```

Then add your tests to `tests/test_pi_zero.py` and run

```bash
$ pytest tests/
```

That's it

### Citation

```bibtex
@misc{Black2024,
    author  = {Kevin Black, Noah Brown, Danny Driess, Adnan Esmail, Michael Equi, Chelsea Finn, Niccolo Fusai, Lachy Groom, Karol Hausman, Brian Ichter, Szymon Jakubczak, Tim Jones, Liyiming Ke, Sergey Levine, Adrian Li-Bell, Mohith Mothukuri, Suraj Nair, Karl Pertsch, Lucy Xiaoyang Shi, James Tanner, Quan Vuong, Anna Walling, Haohuan Wang, Ury Zhilinsky},
    url     = {https://www.physicalintelligence.company/download/pi0.pdf}
}
```

```bibtex
@inproceedings{Zhou2024ValueRL,
    title   = {Value Residual Learning For Alleviating Attention Concentration In Transformers},
    author  = {Zhanchao Zhou and Tianyi Wu and Zhiyun Jiang and Zhenzhong Lan},
    year    = {2024},
    url     = {https://api.semanticscholar.org/CorpusID:273532030}
}
```

```bibtex
@inproceedings{Darcet2023VisionTN,
    title   = {Vision Transformers Need Registers},
    author  = {Timoth'ee Darcet and Maxime Oquab and Julien Mairal and Piotr Bojanowski},
    year    = {2023},
    url     = {https://api.semanticscholar.org/CorpusID:263134283}
}
```

```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
@inproceedings{Sadat2024EliminatingOA,
    title   = {Eliminating Oversaturation and Artifacts of High Guidance Scales in Diffusion Models},
    author  = {Seyedmorteza Sadat and Otmar Hilliges and Romann M. Weber},
    year    = {2024},
    url     = {https://api.semanticscholar.org/CorpusID:273098845}
}
```

```bibtex
@article{Bulatov2022RecurrentMT,
    title   = {Recurrent Memory Transformer},
    author  = {Aydar Bulatov and Yuri Kuratov and Mikhail S. Burtsev},
    journal = {ArXiv},
    year    = {2022},
    volume  = {abs/2207.06881},
    url     = {https://api.semanticscholar.org/CorpusID:250526424}
}
```

```bibtex
@inproceedings{Bessonov2023RecurrentAT,
    title   = {Recurrent Action Transformer with Memory},
    author  = {A. B. Bessonov and Alexey Staroverov and Huzhenyu Zhang and Alexey K. Kovalev and D. Yudin and Aleksandr I. Panov},
    year    = {2023},
    url     = {https://api.semanticscholar.org/CorpusID:259188030}
}
```

[*dear alice*](https://www.youtube.com/watch?v=z-Ng5ZvrDm4)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pi-zero-pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, flow policy, robotic foundation model, transformers",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/40/29/e6b5e83b94a347fdd59d84357222bd48bebb34f34e9fd4ce61da31e7bf21/pi_zero_pytorch-0.0.49.tar.gz",
    "platform": null,
    "description": "<img src=\"./fig3.png\" width=\"400px\"></img>\n\n## pi-zero-pytorch (wip)\n\nImplementation of <a href=\"https://www.physicalintelligence.company/blog/pi0\">\u03c0\u2080</a> the robotic foundation model architecture proposed by Physical Intelligence\n\nSummary of this work would be that it is a simplified <a href=\"https://github.com/lucidrains/transfusion-pytorch\">Transfusion</a> (Zhou et al.) with influence from <a href=\"https://arxiv.org/abs/2403.03206\">Stable Diffusion 3</a> (Esser et al.), mainly the adoption of flow matching instead of diffusion for policy generation, as well as the separation of parameters (<a href=\"https://github.com/lucidrains/mmdit/blob/main/mmdit/mmdit_pytorch.py#L43\">Joint Attention</a> from mmDIT). They build on top of a pretrained vision language model, PaliGemma 2B.\n\n### Appreciation\n\n- [Einops](https://github.com/arogozhnikov/einops) for the amazing [pack and unpack](https://einops.rocks/4-pack-and-unpack/), used extensively here for managing various token sets\n\n- [Flex Attention](https://pytorch.org/blog/flexattention/) for allowing for easy mixture of autoregressive and bidirectional attention\n\n- [@Wonder1905](https://github.com/Wonder1905) for the code review and identifying issues\n\n- You? maybe a phd student who wants to contribute to the latest SOTA architecture for behavioral cloning?\n\n### Install\n\n```bash\n$ pip install pi-zero-pytorch\n```\n\n### Usage\n\n```python\nimport torch\nfrom pi_zero_pytorch import \u03c00\n\nmodel = \u03c00(\n    dim = 512,\n    dim_action_input = 6,\n    dim_joint_state = 12,\n    num_tokens = 20_000\n)\n\nvision = torch.randn(1, 1024, 512)\ncommands = torch.randint(0, 20_000, (1, 1024))\njoint_state = torch.randn(1, 12)\nactions = torch.randn(1, 32, 6)\n\nloss, _ = model(vision, commands, joint_state, actions)\nloss.backward()\n\n# after much training\n\nsampled_actions = model(vision, commands, joint_state, trajectory_length = 32) # (1, 32, 6)\n```\n\n### Contributing\n\nAt the project root, run\n\n```bash\n$ pip install '.[test]' # or `uv pip install '.[test]'`\n```\n\nThen add your tests to `tests/test_pi_zero.py` and run\n\n```bash\n$ pytest tests/\n```\n\nThat's it\n\n### Citation\n\n```bibtex\n@misc{Black2024,\n    author  = {Kevin Black, Noah Brown, Danny Driess, Adnan Esmail, Michael Equi, Chelsea Finn, Niccolo Fusai, Lachy Groom, Karol Hausman, Brian Ichter, Szymon Jakubczak, Tim Jones, Liyiming Ke, Sergey Levine, Adrian Li-Bell, Mohith Mothukuri, Suraj Nair, Karl Pertsch, Lucy Xiaoyang Shi, James Tanner, Quan Vuong, Anna Walling, Haohuan Wang, Ury Zhilinsky},\n    url     = {https://www.physicalintelligence.company/download/pi0.pdf}\n}\n```\n\n```bibtex\n@inproceedings{Zhou2024ValueRL,\n    title   = {Value Residual Learning For Alleviating Attention Concentration In Transformers},\n    author  = {Zhanchao Zhou and Tianyi Wu and Zhiyun Jiang and Zhenzhong Lan},\n    year    = {2024},\n    url     = {https://api.semanticscholar.org/CorpusID:273532030}\n}\n```\n\n```bibtex\n@inproceedings{Darcet2023VisionTN,\n    title   = {Vision Transformers Need Registers},\n    author  = {Timoth'ee Darcet and Maxime Oquab and Julien Mairal and Piotr Bojanowski},\n    year    = {2023},\n    url     = {https://api.semanticscholar.org/CorpusID:263134283}\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@inproceedings{Sadat2024EliminatingOA,\n    title   = {Eliminating Oversaturation and Artifacts of High Guidance Scales in Diffusion Models},\n    author  = {Seyedmorteza Sadat and Otmar Hilliges and Romann M. Weber},\n    year    = {2024},\n    url     = {https://api.semanticscholar.org/CorpusID:273098845}\n}\n```\n\n```bibtex\n@article{Bulatov2022RecurrentMT,\n    title   = {Recurrent Memory Transformer},\n    author  = {Aydar Bulatov and Yuri Kuratov and Mikhail S. Burtsev},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs/2207.06881},\n    url     = {https://api.semanticscholar.org/CorpusID:250526424}\n}\n```\n\n```bibtex\n@inproceedings{Bessonov2023RecurrentAT,\n    title   = {Recurrent Action Transformer with Memory},\n    author  = {A. B. Bessonov and Alexey Staroverov and Huzhenyu Zhang and Alexey K. Kovalev and D. Yudin and Aleksandr I. Panov},\n    year    = {2023},\n    url     = {https://api.semanticscholar.org/CorpusID:259188030}\n}\n```\n\n[*dear alice*](https://www.youtube.com/watch?v=z-Ng5ZvrDm4)\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": "\u03c00 in Pytorch",
    "version": "0.0.49",
    "project_urls": {
        "Homepage": "https://pypi.org/project/pi-zero-pytorch/",
        "Repository": "https://github.com/lucidrains/pi-zero-pytorch"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " flow policy",
        " robotic foundation model",
        " transformers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71f33ac6b0acf877750cf7f8570ecd77589e8ab5f59e7c3dd56b0dd53c8c62c9",
                "md5": "53c4fa0af38447cfacd3a122ed695059",
                "sha256": "bf7bb4d33f7bb3ca8aec9ebfd04003bf4fefe2336bf59af89ebf5e7b8666180f"
            },
            "downloads": -1,
            "filename": "pi_zero_pytorch-0.0.49-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "53c4fa0af38447cfacd3a122ed695059",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14937,
            "upload_time": "2024-12-18T18:49:23",
            "upload_time_iso_8601": "2024-12-18T18:49:23.531056Z",
            "url": "https://files.pythonhosted.org/packages/71/f3/3ac6b0acf877750cf7f8570ecd77589e8ab5f59e7c3dd56b0dd53c8c62c9/pi_zero_pytorch-0.0.49-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4029e6b5e83b94a347fdd59d84357222bd48bebb34f34e9fd4ce61da31e7bf21",
                "md5": "ae0be7b0884677a5eef6f15778610e1c",
                "sha256": "809895fee43036aeef343e40bae68c956f3b0ef211675eb59742ca7b6d7ebd08"
            },
            "downloads": -1,
            "filename": "pi_zero_pytorch-0.0.49.tar.gz",
            "has_sig": false,
            "md5_digest": "ae0be7b0884677a5eef6f15778610e1c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1191137,
            "upload_time": "2024-12-18T18:49:25",
            "upload_time_iso_8601": "2024-12-18T18:49:25.920211Z",
            "url": "https://files.pythonhosted.org/packages/40/29/e6b5e83b94a347fdd59d84357222bd48bebb34f34e9fd4ce61da31e7bf21/pi_zero_pytorch-0.0.49.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 18:49:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "pi-zero-pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pi-zero-pytorch"
}
        
Elapsed time: 9.82615s