synsense / sinabs

A deep learning library for spiking neural networks which is based on PyTorch, focuses on fast training and supports inference on neuromorphic hardware.
https://sinabs.readthedocs.io
GNU Affero General Public License v3.0
77 stars 8 forks source link

Transition from SNNAnalyzer to hooks #200

Closed bauerfe closed 7 months ago

bauerfe commented 9 months ago

The SNNAnalyer is a useful tool in sinabs to collect various statistics on SNN dynamics. However, it has become somewhat clunky over time and it is hard to collect customized statistics. The approach of hard-coding which data is collected and processed makes the SNNAnalyzer quite rigid and limits its scope. For instance, it is currently not possible to be used when samples of different batches have different dimensions (e.g. different number of frames).

A leaner and more flexible approach might therefore be to provide a range of hooks that can be added to the model. These can be applied selectively and if needed, users can define custom hooks easily. This approach may also reduce memory overhead. Currently the SNNAnalyzer stores all input and output data for (almost) all layers in a model. Individual hooks could instead just store the relevant statistics (such as firing rates), which are often more compact.

An open question that still needs to be discussed: The SNNAnalyzer had a "global" view over a given SNN and was therefore able to take pooling layers into account when calculating synaptic operations. How can this be solved when using hooks that operate on a per-layer level?

To do:

bauerfe commented 9 months ago

One approach to solve the issue about average pooling in synops calculation could be to have a hook that is registered with the network, rather than individual layers. It would probably need some sort of helper hooks that then are registered with the weight layers.

bauerfe commented 9 months ago

Added the hooks. Still need unit tests and documentation to make sure they work properly.

bauerfe commented 8 months ago

Unit tests and docstrings are in place now. Also the how-tos about synops have been updated. Still missing: A how to on using the hooks in general, and mentioning the firing rate hook somewhere.

bauerfe commented 7 months ago

I added a how-to about using custom hooks and included the firing rate in the how-to about snns and synops. Furthermore I added deprecation warnings to the SNNAnalyzer and SynOpsCounter classes.

PR #208 is ready for review

bauerfe commented 7 months ago

Merged through #208