nGPT-pytorch


NamenGPT-pytorch JSON
Version 0.2.6 PyPI version JSON
download
home_pageNone
SummarynGPT
upload_time2024-11-03 01:52:14
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 attention mechanism deep learning hypersphere transformer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./ngpt-table1.png" width="350px"></img>

## nGPT (normalized GPT) - Pytorch

Quick implementation of <a href="https://arxiv.org/abs/2410.01131">nGPT</a>, learning entirely on the hypersphere, from NvidiaAI. The question is whether there is any loss of expressivity they swept under the rug, but I'll take it with good faith.

This type of network should also be studied in the context of continual learning and <a href="https://www.nature.com/articles/s41586-024-07711-7">loss of plasticity</a>

Adaptation to vision transformers is [here](https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/normalized_vit.py)

## Install

```bash
$ pip install nGPT-pytorch
```

## Usage

```python
import torch
from nGPT_pytorch import nGPT

model = nGPT(
    num_tokens = 256,
    dim = 512,
    depth = 4,
    attn_norm_qk = True
)

x = torch.randint(0, 256, (2, 2048))

loss = model(x, return_loss = True)
loss.backward()

logits = model(x) # (2, 2048, 256)
```

## Test

Enwik8

```bash
$ python train.py
```

## Citations

```bibtex
@inproceedings{Loshchilov2024nGPTNT,
    title   = {nGPT: Normalized Transformer with Representation Learning on the Hypersphere},
    author  = {Ilya Loshchilov and Cheng-Ping Hsieh and Simeng Sun and Boris Ginsburg},
    year    = {2024},
    url     = {https://api.semanticscholar.org/CorpusID:273026160}
}
```

```bibtex
@article{Luo2017CosineNU,
    title     = {Cosine Normalization: Using Cosine Similarity Instead of Dot Product in Neural Networks},
    author    = {Chunjie Luo and Jianfeng Zhan and Lei Wang and Qiang Yang},
    journal   = {ArXiv},
    year      = {2017},
    volume    = {abs/1702.05870},
    url       = {https://api.semanticscholar.org/CorpusID:1505432}
}
```

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nGPT-pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "artificial intelligence, attention mechanism, deep learning, hypersphere, transformer",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ba/ec/ba7ba424bbc3f2eecda45619b8f59871098d11c9ad2b1695ca9ac4642ce3/ngpt_pytorch-0.2.6.tar.gz",
    "platform": null,
    "description": "<img src=\"./ngpt-table1.png\" width=\"350px\"></img>\n\n## nGPT (normalized GPT) - Pytorch\n\nQuick implementation of <a href=\"https://arxiv.org/abs/2410.01131\">nGPT</a>, learning entirely on the hypersphere, from NvidiaAI. The question is whether there is any loss of expressivity they swept under the rug, but I'll take it with good faith.\n\nThis type of network should also be studied in the context of continual learning and <a href=\"https://www.nature.com/articles/s41586-024-07711-7\">loss of plasticity</a>\n\nAdaptation to vision transformers is [here](https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/normalized_vit.py)\n\n## Install\n\n```bash\n$ pip install nGPT-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom nGPT_pytorch import nGPT\n\nmodel = nGPT(\n    num_tokens = 256,\n    dim = 512,\n    depth = 4,\n    attn_norm_qk = True\n)\n\nx = torch.randint(0, 256, (2, 2048))\n\nloss = model(x, return_loss = True)\nloss.backward()\n\nlogits = model(x) # (2, 2048, 256)\n```\n\n## Test\n\nEnwik8\n\n```bash\n$ python train.py\n```\n\n## Citations\n\n```bibtex\n@inproceedings{Loshchilov2024nGPTNT,\n    title   = {nGPT: Normalized Transformer with Representation Learning on the Hypersphere},\n    author  = {Ilya Loshchilov and Cheng-Ping Hsieh and Simeng Sun and Boris Ginsburg},\n    year    = {2024},\n    url     = {https://api.semanticscholar.org/CorpusID:273026160}\n}\n```\n\n```bibtex\n@article{Luo2017CosineNU,\n    title     = {Cosine Normalization: Using Cosine Similarity Instead of Dot Product in Neural Networks},\n    author    = {Chunjie Luo and Jianfeng Zhan and Lei Wang and Qiang Yang},\n    journal   = {ArXiv},\n    year      = {2017},\n    volume    = {abs/1702.05870},\n    url       = {https://api.semanticscholar.org/CorpusID:1505432}\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",
    "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": "nGPT",
    "version": "0.2.6",
    "project_urls": {
        "Homepage": "https://pypi.org/project/nGPT-pytorch/",
        "Repository": "https://github.com/lucidrains/nGPT-pytorch"
    },
    "split_keywords": [
        "artificial intelligence",
        " attention mechanism",
        " deep learning",
        " hypersphere",
        " transformer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "739769071cef9b6ed42544fd966e1e0ccc736e0b059b9ece1cad9a07661443b4",
                "md5": "9bd3d56b9f75ffb93e03379d95d0914d",
                "sha256": "25b448fb6f00bae1ab68e8387906778de63737bc11ba4aab36a792a0f438ceae"
            },
            "downloads": -1,
            "filename": "ngpt_pytorch-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9bd3d56b9f75ffb93e03379d95d0914d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 15012,
            "upload_time": "2024-11-03T01:52:12",
            "upload_time_iso_8601": "2024-11-03T01:52:12.201054Z",
            "url": "https://files.pythonhosted.org/packages/73/97/69071cef9b6ed42544fd966e1e0ccc736e0b059b9ece1cad9a07661443b4/ngpt_pytorch-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "baecba7ba424bbc3f2eecda45619b8f59871098d11c9ad2b1695ca9ac4642ce3",
                "md5": "098688bf0a194c28bf011ae899dc827c",
                "sha256": "6948c5403abfcdae38fcdd916702047f0aacfbda13e2a7f19876149acc4d92f5"
            },
            "downloads": -1,
            "filename": "ngpt_pytorch-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "098688bf0a194c28bf011ae899dc827c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 36894157,
            "upload_time": "2024-11-03T01:52:14",
            "upload_time_iso_8601": "2024-11-03T01:52:14.152693Z",
            "url": "https://files.pythonhosted.org/packages/ba/ec/ba7ba424bbc3f2eecda45619b8f59871098d11c9ad2b1695ca9ac4642ce3/ngpt_pytorch-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-03 01:52:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "nGPT-pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ngpt-pytorch"
}
        
Elapsed time: 0.65401s