Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIR <> lava-dl support #218

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pillow = "^9.2.0"
pytest = "^7.2.0"
unittest2 = "^1.1.0"
torch = "^1.13.1"
nir = "^0.1.0"

[tool.poetry.dev-dependencies]
bandit = "1.7.4"
Expand Down Expand Up @@ -176,4 +177,3 @@ pylint = ["-*"] # Disable temporarily until lint fix
pycodestyle = ["-F401"] # Disable a check
flake8-bandit = ["-S101"] # Ignore asserts for tests
pyflakes = ["-*"] # Disable a plugin

22 changes: 22 additions & 0 deletions src/lava/lib/dl/netx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,25 @@ conv : {shape, type, neuron, inChannels, outChannels, kernelSize, stride,
|-> this is the description of the compartment parameters
|-> {iDecay, vDecay, vThMant, refDelay, ... (other additional params)}
```

## Connection to other frameworks via NIR

The neuromorphic intermediate representation (NIR) is a standard for representing neural networks that is supported by various neuromorphic simulators and hardware platforms. You can learn more about the NIR project and the supported frameworks [here](https://github.com/neuromorphs/NIR).

Converting your lava-dl stored using netx to NIR is simple:
```python
from lava.lib.dl.netx import nir_lava
# convert the lava-dl netx model to nir and save to file
nir_lava.convert_to_nir(net_config='network.net', path='network.nir')
```

Importing a NIR network into lava-dl works similarly:
```python
import nir
from lava.lib.dl.netx import nir_lava, hdf5
# import the NIR model
nir_graph = nir.read('network.nir')
net = nir_lava.nir_to_lavadl_net(nir_graph)
```

This enables you to train your network using other frameworks (e.g. snnTorch, Norse, and others - see the NIR project website) and easily import them into lava through lava-dl's netx.
3 changes: 2 additions & 1 deletion src/lava/lib/dl/netx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from . import hdf5
from . import blocks
from . import utils
from . import nir_lava

__all__ = ['hdf5', 'blocks', 'utils']
__all__ = ['hdf5', 'blocks', 'utils', 'nir_lava']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer just nir, but its up to you. Anyway it needs to be consistent with README which says nir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nir is also the name of the NIR library itself, so I thought nir_lava makes it easier to avoid conflicts (rather than import ... as ...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Then lets make it consistent in the README.

Loading
Loading