fangwei123456 / spikingjelly

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

The outputs of the same SCNN with different step mode (multi-step and single-step) are different. / 同一SCNN在不同的步进模式下的输出不同。 #474

Open yazhuoguo opened 7 months ago

yazhuoguo commented 7 months ago

我仿照VGG11的结构搭建了一个SCNN,采用多步步进模式训练了一个模型。之后我将模型部署到了同一个结构的SCNN上,只是将步进模式改成了单步。我发现测试精度和之前的不同。 为了找出问题,我将该模型参数同时部署到多步模式和单步模式的SCNN上,并且输入同样的测试图片,发现输出层神经元的脉冲发射数量有细微的差别:在两种步进模式下,极少数输出层神经元会有脉冲发放数量的不同,且差距极小,在一个脉冲左右。绝大部分的输出层神经元发出的脉冲数量在不同不仅模式下是相同的。 我应该如何保证在两种步进模式下同一套模型参数的SCNN输出一致?

I built an SCNN modeled after the structure of VGG11 and trained a model using multi-step mode. Afterwards, I deployed the model to the same SCNN structure, but changed the step mode to single-step. I found that the testing accuracy is different from before. In order to identify the problem, I deployed the model parameters to both multi-step and single-step SCNN, and inputted the same test images. I found that there was a slight difference in the number of spikes emitted by the output layer neurons: In the two step modes, a very small number of output layer neurons will have a difference in the number of spikes emitted, and the difference is extremely small, around one spike. The vast majority of output layer neurons emit the same number of spikes in different step modes. How can I ensure that the SCNN output of the same model parameters is consistent in two step modes?

fangwei123456 commented 7 months ago

首先确保你的网络工作在eval模式下 细微的差别可能是部分神经元导致的,有的神经元给多步模式的推理也做了加速(使用torch.jit),这种融合的内核可能与单步的内核有轻微区别 你可以通过继承神经元类,并覆写forward方法来强制多步模式来调用多次单步模式,确保他们的输出一样

另外,卷积层在多步和单步模式的输出也会有轻微区别,尽管它们在数学上应该完全等价,这个是pytorch本身的问题

https://discuss.pytorch.org/t/different-outputs-when-using-different-batch-size-only-on-cuda/155886

https://discuss.pytorch.org/t/why-the-output-is-different-when-batching/129285