snntorch.export_nir

snntorch.export_nir is a module that enables cross-compatibility with other SNN libraries by converting snntorch models to a Neuromorphic Intermediate Representation (NIR)

snntorch.export_nir.export_to_nir(module: Module, sample_data: Tensor, model_name: str = 'snntorch', model_fwd_args=[], ignore_dims=[]) NIRNode[source]

Convert an snnTorch module to the Neuromorphic Intermediate Representation (NIR). This function uses nirtorch to extract the computational graph of the torch module, and the _extract_snntorch_module method is used to convert each module in the graph to the corresponding NIR module.

The NIR is a graph-based representation of a spiking neural network, which can be used to port the network to different neuromorphic hardware and software platforms.

Missing features: - RLeaky

Example:

import snntorch as snn
import torch
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)

net = 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_graph = export_to_nir(net, sample_data)
Parameters:
  • module (torch.nn.Module) – Network model (either wrapped in Sequential container or as a class)

  • sample_data (torch.Tensor) – Sample input data to the network

  • model_name (str, optional) – Name of the model

  • model_fwd_args (list, optional) – Arguments to pass to the forward function of the model

  • ignore_dims (list, optional) – List of dimensions to ignore when extracting the NIR

Returns:

return the NIR graph

Return type:

nir.NIRNode