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

torch.jit.script fails on (time unrolled) norse modules #303

Open
cpehle opened this issue Mar 23, 2022 · 2 comments
Open

torch.jit.script fails on (time unrolled) norse modules #303

cpehle opened this issue Mar 23, 2022 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@cpehle
Copy link
Member

cpehle commented Mar 23, 2022

Describe the bug

This is not strictly speaking a bug, but at the moment torch.jit.script fails on the following
network with

RuntimeError: 
Module 'LIF' has no attribute 'state_fallback' (This attribute exists on the Python module, but we failed to convert Python type: 'method' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type method.. Its type was inferred; try adding a type annotation for the attribute.):
  File "/home/cpehle/work/norse/norse/torch/module/snn.py", line 210
    def forward(self, input_tensor: torch.Tensor, state: Optional[Any] = None):
        state = state if state is not None else self.state_fallback(input_tensor)
                                                ~~~~~~~~~~~~~~~~~~~ <--- HERE

I think it is worthwhile changing the API so that this goes through. I will potentially need this in the near future to support hardware backends via this mechanism.

To Reproduce

import torch
from norse.torch import LIF, LI

model = torch.nn.Sequential(
    torch.nn.Conv2d(1, 20, 5, 1),
    LIF(),
    torch.nn.Conv2d(20, 50, 5, 1),
    LIF(),
    torch.nn.Flatten(),
    torch.nn.Linear(800, 10),
    LI(),
)

torch.jit.script(model)

Expected behavior

The module can be jitted.

@cpehle cpehle self-assigned this Mar 23, 2022
@cpehle cpehle added bug Something isn't working enhancement New feature or request labels Mar 23, 2022
@Jegp
Copy link
Member

Jegp commented Mar 24, 2022

Did you try to provide the state? This should only happen if the state is undefined.

@cpehle
Copy link
Member Author

cpehle commented Jan 6, 2023

We should have tests for this and document how to jit.

@cpehle cpehle added this to the Release 0.1 milestone Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants