jeshraghian / snntorch

Deep and online learning with spiking neural networks in Python
https://snntorch.readthedocs.io/en/latest/
MIT License
1.17k stars 202 forks source link

Question about tutorial 2 #306

Closed realbb closed 2 months ago

realbb commented 3 months ago

Description

Hello. I'm trying your tutorial 2, which is about Lapicque's LIF neuron model. I was following your directions but this kind of error has occurred.

code: image

err: image

Actually, I have done this tutorial at Nov.2023. At then there was no error. Can you tell me what is wrong?

Thanks for reading.

realbb commented 3 months ago

When I check parameter mem_rec, here's what I got: Tensor 0: tensor([0.9000]) Tensor 1: tensor(0.) Tensor 2: tensor(0.) ....

It seems the code from for statement spk_out, mem = lif1(cur_in[step], mem) is giving mem a empty tensor.

jeshraghian commented 3 months ago

It seems like the latest update of pytorch has caused torch.stack() to behave differently.

This can be overwritten by just setting mem_rec = [], but then I noticed the neuron behaviour is incorrect.

I'll need to go over this carefully to figure out what's going wrong.

Gabo-Tor commented 3 months ago

@realbb You can fix the problem by adding a dimension to the neuron input spk_out, mem = lif1(cur_in[step].reshape(1), mem) or directly to the input tensor when you create it cur_in = torch.zeros(num_steps,1) @jeshraghian If the Lapicque neuron implementation is working as expected and this is due to a change in the Torch implementation I volunteer to submit a PR with all the tutorials fixed so they work again.

jeshraghian commented 3 months ago

@Gabo-Tor that'd be great. Let's go via cur_in = torch.zeros(num_steps,1) because then the intuition could be that the dimension of '1' is like a batch dimension. We will need to update the notebook and the rst file in docs/tutorials/tutorial_2.rst

I haven't had a chance to check if other tutorials are affected by this, but I feel like they will be.

Gabo-Tor commented 3 months ago

@jeshraghian I'll fix those two files and check the other tutorials.

ahenkes1 commented 2 months ago

Is here still work to do, @Gabo-Tor ?

Gabo-Tor commented 2 months ago

Is here still work to do, @Gabo-Tor ?

@ahenkes1 Nope, it is fixed now, this issue should probably be closed