fangwei123456 / spikingjelly

SpikingJelly is an open-source deep learning framework for Spiking Neural Network (SNN) based on PyTorch.
https://spikingjelly.readthedocs.io
Other
1.35k stars 239 forks source link

Cannot run IF neurons with CuPy backend when using reset-by-substraction #322

Open CloudyDory opened 1 year ago

CloudyDory commented 1 year ago

@fangwei123456 Issue type

SpikingJelly version

0.0.0.0.13

Description Cannot run IF neurons with CuPy backend when using reset-by-substraction (v_reset=None). The error originates from line 425 of neuron_kernel.py, where NeuronATGBase.pre_forward(py_dict) removes the key 'v_reset' when v_reset is None, and then later in line 429 function NeuronATGBase.ctx_save is using py_dict['v_reset'], causing the following error:

    numel=py_dict['numel'], N=py_dict['N'], v_th=py_dict['v_th'], v_reset=py_dict['v_reset'],
KeyError: 'v_reset'

Minimal code to reproduce the error/bug

import torch
from spikingjelly.activation_based import neuron, functional

IF = neuron.IFNode(v_reset=None)
functional.set_step_mode(IF, step_mode='m')
functional.set_backend(IF, backend='cupy')

x = torch.ones((2,10,10), device=torch.device("cuda"))
y = IF(x)
fangwei123456 commented 1 year ago

Hi, I just fix this bug. You can try again.