Name | nirtorch JSON |
Version | 1.0 JSON |
download | |
home_page | |
Summary | Neuromorphic Intermediate Representation |
upload_time | 2023-12-06 14:32:04 |
maintainer | |
docs_url | None |
author | |
requires_python | |
license | |
keywords | neuromorphic intermediate representation |
VCS | |
bugtrack_url | |
requirements | No requirements were recorded. |
Travis-CI | No Travis. |
coveralls test coverage | No coveralls. |
# NIRTorch PyTorch helpers for the [Neuromorphic Intermediate Representation (NIR)](https://github.com/neuromorphs/nir). This is a no frills python package to enable torch based libraries to translate to NIR. ## Installation ```shell pip install nirtorch ``` ## Usage NIRTorch is typically only interfaced by library/hardwarae developers. NIRTorch provides the `extract_nir_graph` function that takes as input a `torch.nn.Module` and a means to map Torch modules into NIR nodes. An NIR node is an element in the NIR compute graph, corresponding to neuromorphic ODEs. Here is an example from the [Norse](https://github.com/norse/norse) library: ```python def _extract_norse_module(module: torch.nn.Module) -> Optional[nir.NIRNode]: if isinstance(module, LIFBoxCell): return nir.LIF( tau=module.p.tau_mem_inv, v_th=module.p.v_th, v_leak=module.p.v_leak, r=torch.ones_like(module.p.v_leak), ) elif isinstance(module, torch.nn.Linear): return nir.Linear(module.weight, module.bias) elif ... return None def to_nir( module: torch.nn.Module, sample_data: torch.Tensor, model_name: str = "norse" ) -> nir.NIRNode: return extract_nir_graph( module, _extract_norse_module, sample_data, model_name=model_name ) ``` ## Acknowledgements If you use NIR torch in your work, please cite the [following Zenodo reference](https://zenodo.org/record/8105042) ``` @software{nir2023, author = {Abreu, Steven and Bauer, Felix and Eshraghian, Jason and Jobst, Matthias and Lenz, Gregor and Pedersen, Jens Egholm and Sheik, Sadique}, title = {Neuromorphic Intermediate Representation}, month = jul, year = 2023, publisher = {Zenodo}, version = {0.0.1}, doi = {10.5281/zenodo.8105042}, url = {https://doi.org/10.5281/zenodo.8105042} } ``` ## For developers If you want to make sure that your code is linted correctly on your local machine, use [pre-commit](https://pre-commit.com/) to automatically perform checks before every git commit. To use it, first install the package in your environment ``` pip install pre-commit ``` and then install the pre-commit hooks that are listed in the root of this repository ``` pre-commit install ``` Next time you commit some changes, all the checks will be run!
{ "_id": null, "home_page": "", "name": "nirtorch", "maintainer": "", "docs_url": null, "requires_python": "", "maintainer_email": "", "keywords": "neuromorphic,intermediate,representation", "author": "", "author_email": "Steven Abreu <s.abreu@rug.nl>, Felix Bauer <felix.bauer@synsen.ai>, Jason Eshraghian <jeshragh@ucsc.edu>, Matthias Jobst <matthias.jobst2@tu-dresden.de>, Gregor Lenz <mail@lenzgregor.com>, Jens Egholm Pedersen <jens@jepedersen.dk>, Sadique Sheik <sadique.sheik@synsense.ai>", "download_url": "https://files.pythonhosted.org/packages/fd/1b/27cb50acf5a0afcca55f238e32ea2a1ed9c5b58225346170682cd58fcfd6/nirtorch-1.0.tar.gz", "platform": null, "description": "# NIRTorch\n\nPyTorch helpers for the [Neuromorphic Intermediate Representation (NIR)](https://github.com/neuromorphs/nir).\nThis is a no frills python package to enable torch based libraries to translate to NIR.\n\n## Installation\n```shell\npip install nirtorch\n```\n\n## Usage\n\nNIRTorch is typically only interfaced by library/hardwarae developers.\nNIRTorch provides the `extract_nir_graph` function that takes as input a `torch.nn.Module` and a means to map Torch modules into NIR nodes.\nAn NIR node is an element in the NIR compute graph, corresponding to neuromorphic ODEs.\n\nHere is an example from the [Norse](https://github.com/norse/norse) library:\n\n```python\ndef _extract_norse_module(module: torch.nn.Module) -> Optional[nir.NIRNode]:\n if isinstance(module, LIFBoxCell):\n return nir.LIF(\n tau=module.p.tau_mem_inv,\n v_th=module.p.v_th,\n v_leak=module.p.v_leak,\n r=torch.ones_like(module.p.v_leak),\n )\n elif isinstance(module, torch.nn.Linear):\n return nir.Linear(module.weight, module.bias)\n elif ...\n\n return None\n\ndef to_nir(\n module: torch.nn.Module, sample_data: torch.Tensor, model_name: str = \"norse\"\n) -> nir.NIRNode:\n return extract_nir_graph(\n module, _extract_norse_module, sample_data, model_name=model_name\n )\n```\n\n## Acknowledgements\nIf you use NIR torch in your work, please cite the [following Zenodo reference](https://zenodo.org/record/8105042)\n\n```\n@software{nir2023,\n author = {Abreu, Steven and\n Bauer, Felix and\n Eshraghian, Jason and\n Jobst, Matthias and\n Lenz, Gregor and\n Pedersen, Jens Egholm and\n Sheik, Sadique},\n title = {Neuromorphic Intermediate Representation},\n month = jul,\n year = 2023,\n publisher = {Zenodo},\n version = {0.0.1},\n doi = {10.5281/zenodo.8105042},\n url = {https://doi.org/10.5281/zenodo.8105042}\n}\n```\n\n## For developers\nIf you want to make sure that your code is linted correctly on your local machine, use [pre-commit](https://pre-commit.com/) to automatically perform checks before every git commit. To use it, first install the package in your environment\n```\npip install pre-commit\n```\nand then install the pre-commit hooks that are listed in the root of this repository\n```\npre-commit install\n```\nNext time you commit some changes, all the checks will be run!\n", "bugtrack_url": null, "license": "", "summary": "Neuromorphic Intermediate Representation", "version": "1.0", "project_urls": null, "split_keywords": [ "neuromorphic", "intermediate", "representation" ], "urls": [ { "comment_text": "", "digests": { "blake2b_256": "cd7492cc684fd83636b072318693676877af0d80c4e136067237f147f9a18d6f", "md5": "3f352af0eee0e737f73057087161a15f", "sha256": "72f4898a18ceb91d5a9b66515db2bb4a5893a8d11a77b48d9bbe058228995b02" }, "downloads": -1, "filename": "nirtorch-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3f352af0eee0e737f73057087161a15f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13313, "upload_time": "2023-12-06T14:32:03", "upload_time_iso_8601": "2023-12-06T14:32:03.016806Z", "url": "https://files.pythonhosted.org/packages/cd/74/92cc684fd83636b072318693676877af0d80c4e136067237f147f9a18d6f/nirtorch-1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "blake2b_256": "fd1b27cb50acf5a0afcca55f238e32ea2a1ed9c5b58225346170682cd58fcfd6", "md5": "6887742a99149ad7b5c5644f8fefa571", "sha256": "a0a7c485c0cb523a257a68b881c83d3710a471ad896188879a1bb722d47db2bf" }, "downloads": -1, "filename": "nirtorch-1.0.tar.gz", "has_sig": false, "md5_digest": "6887742a99149ad7b5c5644f8fefa571", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18870, "upload_time": "2023-12-06T14:32:04", "upload_time_iso_8601": "2023-12-06T14:32:04.023389Z", "url": "https://files.pythonhosted.org/packages/fd/1b/27cb50acf5a0afcca55f238e32ea2a1ed9c5b58225346170682cd58fcfd6/nirtorch-1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "upload_time": "2023-12-06 14:32:04", "github": false, "gitlab": false, "bitbucket": false, "codeberg": false, "lcname": "nirtorch" }