fangwei123456 / spikingjelly

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

当我使用lif作为激活函数时,会报一个反向传播的错误。 #419

Closed fade54188 closed 11 months ago

fade54188 commented 12 months ago

Issue type

当我使用lif替代Cross-vit中的nn.GELU作为激活函数时,会爆一个反向传播的错误。 Traceback (most recent call last): File "E:\WORK\CrossViT-main\main.py", line 359, in main(args) File "E:\WORK\CrossViT-main\main.py", line 309, in main train_stats = train_one_epoch( File "E:\WORK\CrossViT-main\engine.py", line 67, in train_one_epoch loss.backward(create_graph=is_second_order, retain_graph=True) File "E:\Anaconda\envs\swin_det\lib\site-packages\torch\tensor.py", line 245, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs) File "E:\Anaconda\envs\swin_det\lib\site-packages\torch\autograd__init__.py", line 145, in backward Variable._execution_engine.run_backward( RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [128]] is at version 5; expected version 3 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

我使用SpikingFlow或者Spikingjelly都报这个错误。

fangwei123456 commented 12 months ago

原始的网络中对某个变量进行了inplace操作导致报错,检查一下lif的输出是否被这样操作了

fangwei123456 commented 12 months ago

或者把lif的输出调用一次.clone再传递给下一层

Met4physics commented 11 months ago

我同样遇到了这个问题

Met4physics commented 11 months ago

检查一下你在每次训练结束后是否加上这一句functional.reset_net(model)

fade54188 commented 11 months ago

检查一下你在每次训练结束后是否加上这一句functional.reset_net(model)

兄弟,你是我的神! 么么叽

fade54188 commented 11 months ago

感谢大家!!!!!!!!!!