{"id":26024777,"url":"https://github.com/neuromorphs/nirtorch","last_synced_at":"2026-01-23T21:01:13.265Z","repository":{"id":177959628,"uuid":"661145470","full_name":"neuromorphs/NIRTorch","owner":"neuromorphs","description":"PyTorch helper module to translate to and from NIR","archived":false,"fork":false,"pushed_at":"2025-07-25T14:09:20.000Z","size":191,"stargazers_count":13,"open_issues_count":7,"forks_count":6,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-07-25T20:40:21.465Z","etag":null,"topics":["intermediate-representation","machine-learning","neuromorphic"],"latest_commit_sha":null,"homepage":"https://neuroir.org/docs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuromorphs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-01T23:46:33.000Z","updated_at":"2025-07-25T14:09:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"e262f9e3-7a7a-489c-847d-cc067ad71bab","html_url":"https://github.com/neuromorphs/NIRTorch","commit_stats":null,"previous_names":["neuromorphs/nirtorch"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/neuromorphs/NIRTorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuromorphs%2FNIRTorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuromorphs%2FNIRTorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuromorphs%2FNIRTorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuromorphs%2FNIRTorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuromorphs","download_url":"https://codeload.github.com/neuromorphs/NIRTorch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuromorphs%2FNIRTorch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270183606,"owners_count":24541341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["intermediate-representation","machine-learning","neuromorphic"],"created_at":"2025-03-06T12:37:15.870Z","updated_at":"2026-01-23T21:01:13.253Z","avatar_url":"https://github.com/neuromorphs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cpicture\u003e\n\u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/neuromorphs/NIR/raw/main/docs/logo_dark.png\"\u003e\n\u003cimg alt=\"NIR Logo\" src=\"https://github.com/neuromorphs/NIR/raw/main/docs/logo_light.png\"\u003e\n\u003c/picture\u003e\n\n# NIRTorch - Torch for the Neuromorphic Intermediate Representation\n\n[![Nature Communications Paper](https://zenodo.org/badge/DOI/10.1038/s41467-024-52259-9.svg)](https://doi.org/10.1038/s41467-024-52259-9)\n[![PyPi Downloads](https://img.shields.io/pepy/dt/nirtorch)](https://pypi.org/project/nirtorch/)\n[![GitHub Tag](https://img.shields.io/github/v/tag/neuromorphs/nirtorch?logo=github)](https://github.com/neuromorphs/NIRTorch/releases)\n[![Discord](https://img.shields.io/discord/1209533869733453844?logo=discord)](https://discord.gg/JRMRGP9h3c)\n[![Neuromorphic Computing](https://img.shields.io/badge/Collaboration_Network-Open_Neuromorphic-blue)](https://open-neuromorphic.org/neuromorphic-computing/)\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\n\u003e [!TIP]\n\u003e Read the full documentation at [neuroir.org/docs](https://neuroir.org/docs/dev_pytorch.html).\n\n\nNIRTorch is typically only interfaced by library/hardwarae developers.\nNIRTorch provides two functions `nir_to_torch` and `torch_to_nir` that maps NIR graphs to Torch and vice versa.\n\n### Translating from NIR to Torch\nNIRTorch automatically creates the Torch graph and module behind the scenes.\nThe only thing you have to do as a developer is to provide a mapping between NIR nodes to PyTorch modules.\nThat is, a dictionary of nodes with associated functions that produces Torch modules, given a NIR Node (`Dict[nir.NIRNode, Callable[[nir.NIRNode], torch.nn.Module]]`), where a NIR node is an element in the NIR compute graph, corresponding to neuromorphic ODEs.\nHere is one example taken from the [Norse](https://github.com/norse/norse) library:\n\n```python\n# Define NIR -\u003e Norse mapping\nmy_node_dictionary = {}\ndef _map_linear(linear: nir.Linear) -\u003e torch.nn.Module:\n    output_shape, input_shape = linear.weight.shape[-2:]\n    l = torch.nn.Linear(input_shape, output_shape, bias=False)\n    l.weight.data = linear.weight\n    return l\n_my_node_dictionary[nir.Linear] = _map_linear\n... # And so on for other modules\n\n# Declare a user-facing function to output Norse modules\ndef from_nir(module: nir.NIRGraph) -\u003e torch.nn.Module:\n    return nirtorch.nir_to_torch(\n        module,              # The NIR Graph to map\n        _my_node_dictionary  # The dictionary used to map modules to Norse\n    )\n```\n\n### Translating from Torch to NIR\nNIRTorch helps construct a NIR graph by tracing through the PyTorch graph module by module.\nOur job as a developer is now to provide a mapping that helps translate PyTorch modules into NIR nodes, where a NIR node is an element in the NIR compute graph.\nThat is, a `Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]]`.\nNote that the output node may be a subgraph.\n\ndef torch_to_nir(\n    module: torch.nn.Module,\n    module_map: Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]],\n    default_dict: Optional[\n        Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]]\n    ] = None,\n) -\u003e nir.NIRGraph:\n\n```python\n# Define Norse -\u003e NIR mapping\n_my_module_dict = {}\ndef _extract_lif_module(module: norse.LIFBoxCell) -\u003e Optional[nir.NIRNode]:\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_my_module_dict[norse.LIFBoxcell] =_extract_lif_module\n\n# Declare a user-facing function to output NIR graphs\ndef to_nir(module: torch.nn.Module) -\u003e nir.NIRNode:\n    return nirtorch.torch_to_nir(\n        module,          # The Norse/Torch module to parse\n        _my_module_dict  # The dictionary that maps Norse module to NIR\n    )\n```\nRead the full documentation at [neuroir.org/docs](https://neuroir.org/docs/dev_pytorch.html).\n\n\n## Acknowledgements\nIf you use NIRTorch in your work, please cite the [our work in Nature Communications](https://www.nature.com/articles/s41467-024-52259-9)\n\n```\narticle{NIR2024, \n    title={Neuromorphic intermediate representation: A unified instruction set for interoperable brain-inspired computing}, \n    author={Pedersen, Jens E. and Abreu, Steven and Jobst, Matthias and Lenz, Gregor and Fra, Vittorio and Bauer, Felix Christian and Muir, Dylan Richard and Zhou, Peng and Vogginger, Bernhard and Heckel, Kade and Urgese, Gianvito and Shankar, Sadasivan and Stewart, Terrence C. and Sheik, Sadique and Eshraghian, Jason K.}, \n    rights={2024 The Author(s)},\n    DOI={10.1038/s41467-024-52259-9}, \n    number={1},\n    journal={Nature Communications}, \n    volume={15},\n    year={2024}, \n    month=sep, \n    pages={8122},\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuromorphs%2Fnirtorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuromorphs%2Fnirtorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuromorphs%2Fnirtorch/lists"}