nirtorch

PyTorch helper module to translate to and from NIR

https://github.com/neuromorphs/nirtorch

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: nature.com, zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.6%) to scientific vocabulary

Keywords

intermediate-representation machine-learning neuromorphic
Last synced: 6 months ago · JSON representation ·

Repository

PyTorch helper module to translate to and from NIR

Basic Info
  • Host: GitHub
  • Owner: neuromorphs
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Homepage: https://neuroir.org/docs
  • Size: 188 KB
Statistics
  • Stars: 13
  • Watchers: 8
  • Forks: 7
  • Open Issues: 6
  • Releases: 13
Topics
intermediate-representation machine-learning neuromorphic
Created over 2 years ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

NIR Logo

NIRTorch - Torch for the Neuromorphic Intermediate Representation

Nature Communications Paper PyPi Downloads GitHub Tag Discord Neuromorphic Computing

PyTorch helpers for the Neuromorphic Intermediate Representation (NIR). This is a no frills python package to enable torch based libraries to translate to NIR.

Installation

shell pip install nirtorch

Usage

[!TIP] Read the full documentation at neuroir.org/docs.

NIRTorch is typically only interfaced by library/hardwarae developers. NIRTorch provides two functions nir_to_torch and torch_to_nir that maps NIR graphs to Torch and vice versa.

Translating from NIR to Torch

NIRTorch automatically creates the Torch graph and module behind the scenes. The only thing you have to do as a developer is to provide a mapping between NIR nodes to PyTorch modules. That 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. Here is one example taken from the Norse library:

```python

Define NIR -> Norse mapping

mynodedictionary = {} def maplinear(linear: nir.Linear) -> torch.nn.Module: outputshape, inputshape = linear.weight.shape[-2:] l = torch.nn.Linear(inputshape, outputshape, bias=False) l.weight.data = linear.weight return l mynodedictionary[nir.Linear] = _maplinear ... # And so on for other modules

Declare a user-facing function to output Norse modules

def fromnir(module: nir.NIRGraph) -> torch.nn.Module: return nirtorch.nirtotorch( module, # The NIR Graph to map _mynode_dictionary # The dictionary used to map modules to Norse ) ```

Translating from Torch to NIR

NIRTorch helps construct a NIR graph by tracing through the PyTorch graph module by module. Our 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. That is, a Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]]. Note that the output node may be a subgraph.

def torchtonir( module: torch.nn.Module, modulemap: Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]], defaultdict: Optional[ Dict[torch.nn.Module, Callable[[torch.nn.Module], nir.NIRNode]] ] = None, ) -> nir.NIRGraph:

```python

Define Norse -> NIR mapping

mymoduledict = {} def _extractlifmodule(module: norse.LIFBoxCell) -> Optional[nir.NIRNode]: return nir.LIF( tau=module.p.taumeminv, vth=module.p.vth, vleak=module.p.vleak, r=torch.oneslike(module.p.vleak), ) _mymoduledict[norse.LIFBoxcell] =extractlifmodule

Declare a user-facing function to output NIR graphs

def tonir(module: torch.nn.Module) -> nir.NIRNode: return nirtorch.torchtonir( module, # The Norse/Torch module to parse _mymodule_dict # The dictionary that maps Norse module to NIR ) ``` Read the full documentation at neuroir.org/docs.

Acknowledgements

If you use NIRTorch in your work, please cite the our work in Nature Communications

article{NIR2024, title={Neuromorphic intermediate representation: A unified instruction set for interoperable brain-inspired computing}, 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.}, rights={2024 The Author(s)}, DOI={10.1038/s41467-024-52259-9}, number={1}, journal={Nature Communications}, volume={15}, year={2024}, month=sep, pages={8122}, }

For developers

If you want to make sure that your code is linted correctly on your local machine, use pre-commit 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!

Owner

  • Name: Institute of Neuromorphic Engineering
  • Login: neuromorphs
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
title: 'Neuromorphic Intermediate Representation: A Unified Instruction Set for Interoperable Brain-Inspired Computing'
doi: arXiv:2311.14641
message: If you use this software in your work, please cite it as follows.
date-released: 2023-11-23
authors:
  - given-names: Jens E.
    family-names: Pedersen
  - given-names: Steven
    family-names: Abreu
  - given-names: Matthias
    family-names: Jobst
  - given-names: Gregor
    family-names: Lenz
  - given-names: Vittorio
    family-names: Fra
  - given-names: Felix C.
    family-names: Bauer
  - given-names: Dylan R.
    family-names: Muir
  - given-names: Peng
    family-names: Zhou
  - given-names: Bernhard
    family-names: Vogginger
  - given-names: Kade
    family-names: Heckel
  - given-names: Gianvito
    family-names: Urgese
  - given-names: Sadasivan
    family-names: Shankar
  - given-names: Terrence C.
    family-names: Stewart
  - given-names: Jason K.
    family-names: Eshraghian
  - given-names: Sadique
    family-names: Sheik
abstract: 'This repository contains the source code of the paper Neuromorphic Intermediate Representation: A Unified Instruction Set for Interoperable Brain-Inspired Computing by Jens E. Pedersen, Steven Abreu, Matthias Jobst, Gregor Lenz, Vittorio Fra, Felix C. Bauer, Dylan R. Muir, Peng Zhou, Bernhard Vogginger, Kade Heckel, Gianvito Urgese, Sadasivan Shankar, Terrence C. Stewart, Jason K. Eshraghian and Sadique Sheik, from Arxiv'
version: 1.0.0

GitHub Events

Total
  • Create event: 16
  • Release event: 6
  • Issues event: 7
  • Watch event: 8
  • Delete event: 8
  • Issue comment event: 15
  • Member event: 2
  • Push event: 38
  • Pull request review event: 27
  • Pull request review comment event: 23
  • Pull request event: 24
  • Fork event: 3
Last Year
  • Create event: 16
  • Release event: 6
  • Issues event: 7
  • Watch event: 8
  • Delete event: 8
  • Issue comment event: 15
  • Member event: 2
  • Push event: 38
  • Pull request review event: 27
  • Pull request review comment event: 23
  • Pull request event: 24
  • Fork event: 3

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 15
  • Total pull requests: 33
  • Average time to close issues: 5 months
  • Average time to close pull requests: 25 days
  • Total issue authors: 7
  • Total pull request authors: 6
  • Average comments per issue: 0.67
  • Average comments per pull request: 0.52
  • Merged pull requests: 26
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 18
  • Average time to close issues: 3 months
  • Average time to close pull requests: 13 days
  • Issue authors: 2
  • Pull request authors: 3
  • Average comments per issue: 0.25
  • Average comments per pull request: 0.39
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Jegp (5)
  • sheiksadique (4)
  • biphasic (2)
  • Tobias-Fischer (1)
  • stevenabreu7 (1)
  • benkroehs (1)
  • bvogginger (1)
Pull Request Authors
  • Jegp (18)
  • sheiksadique (6)
  • fabio-innatera (5)
  • stevenabreu7 (1)
  • biphasic (1)
  • benkroehs (1)
Top Labels
Issue Labels
enhancement (2) help wanted (1)
Pull Request Labels
enhancement (1)