Skip to content

NIR export of LIF node might be out of date, v_reset parameter is missing #384

@jeromehue

Description

@jeromehue

Trying to run the following code snippet

import snntorch as snn
import torch
import nir

from snntorch.export_nir import export_to_nir

lif1 = snn.Leaky(beta=0.9, init_hidden=True)
lif2 = snn.Leaky(beta=0.9, init_hidden=True, output=True)

# Create a network
snntorch_network = torch.nn.Sequential(
    torch.nn.Flatten(),
    torch.nn.Linear(784, 500),
    lif1,
    torch.nn.Linear(500, 10),
    lif2
)

sample_data = torch.randn(1, 784)
nir_model = export_to_nir(snntorch_network, sample_data)
nir.write("nir_model.nir", nir_model)

with nir 1.0.6, nirtorch 2.0.4 and snntorch built from sources (commit a2ce8cd) results in the following error :

Traceback (most recent call last):
  File "/home/Tasks/task-nir/true.py", line 20, in <module>
    nir_model = export_to_nir(snntorch_network, sample_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nobackup/documents/jenv/lib/python3.12/site-packages/snntorch/export_nir.py", line 244, in export_to_nir
    nir_graph = nirtorch.extract_nir_graph(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nobackup/documents/jenv/lib/python3.12/site-packages/nirtorch/to_nir.py", line 79, in extract_nir_graph
    mapped_node = model_map(node.elem)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/nobackup/documents/jenv/lib/python3.12/site-packages/snntorch/export_nir.py", line 77, in _extract_snntorch_module
    return nir.LIF(
           ^^^^^^^^
TypeError: LIF.__init__() missing 1 required positional argument: 'v_reset'

It seems indeed that the function export_nir does not take into account the addition of the v_reset parameter in nir (added in commit neuromorphs/NIR@6189cac).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions