Skip to content

Commit

Permalink
Merge pull request #221 from NeuroBench/dev
Browse files Browse the repository at this point in the history
1.0.5 bugfix
  • Loading branch information
jasonlyik authored Jun 5, 2024
2 parents bb872c9 + d2e690d commit 7bb222f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
regex = false
current_version = "1.0.4"
current_version = "1.0.5"
ignore_missing_version = false
search = "{current_version}"
replace = "{new_version}"
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = "NeuroBench"
copyright = "2024, Jason Yik, Noah Pacik-Nelson, Korneel Van Den Berghe"
author = "Jason Yik, Noah Pacik-Nelson, Korneel Van Den Berghe"
release = "1.0.4"
release = "1.0.5"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
1 change: 1 addition & 0 deletions docs/metrics/workload_metrics/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Workload Metrics
activation_sparsity
synaptic_operations
classification_accuracy
membrane_updates
coco_map
smape
r2
Expand Down
37 changes: 37 additions & 0 deletions docs/metrics/workload_metrics/membrane_updates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
===================
Membrane Updates
===================

Definition
----------

During the execution of spiking neural networks (SNNs), the average number of updates to the neurons membrane potential is calculated over all neurons in the network, for all timesteps of all tested samples. This metric is specifically designed for spiking neural network implemented with SNNTorch.

The number of membrane updates is calculated by accumulating the number of changes in membrane potential (i.e., the difference between pre- and post-spike membrane potentials) across all neuron layers, timesteps, and input samples, and then normalizing by the number of samples processed.

Implementation Notes
--------------------

When the NeuroBench model is instatiated, certain layers can be recognized automatically for membrane updates calculation.

.. Note::
The use of this metric are only available for neurons that, when initialized, have the ``init_hidden`` option set to ``True``.

Example:

.. code-block::
import snntorch as snn
# Initializing a Leaky neuron with init_hidden set to True
leaky_neuron = snn.Leaky(beta=0.5, output=True, init_hidden=True)
These layers are:

- snn.SpikingNeuron layers (this is the parent class for all spiking neuron models)

The membrane updates are calculated using hooks that save the pre- and post-spike membrane potentials of the neurons.
At the end of the workload, the total number of membrane potential updates is summed over all layers and batches, and then divided by the number of samples to provide a normalized metric.

5 changes: 3 additions & 2 deletions neurobench/benchmarks/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pre_hook_fn(self, layer, input):
"""
self.activation_inputs.append(input)
if self.spiking:
if self.spiking and hasattr(layer, "mem"):
self.pre_fire_mem_potential.append(layer.mem)

def hook_fn(self, layer, input, output):
Expand All @@ -66,7 +66,8 @@ def hook_fn(self, layer, input, output):
"""
if self.spiking:
self.activation_outputs.append(output[0])
self.post_fire_mem_potential.append(layer.mem)
if hasattr(layer, "mem"):
self.post_fire_mem_potential.append(layer.mem)

else:
self.activation_outputs.append(output)
Expand Down
7 changes: 4 additions & 3 deletions neurobench/benchmarks/workload_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def __call__(self, model, preds, data):
post_fire_mem = hook.post_fire_mem_potential[index_mem + 1]
nr_updates = torch.count_nonzero(pre_fire_mem - post_fire_mem)
self.neuron_membrane_updates[str(type(hook.layer))] += int(nr_updates)
self.neuron_membrane_updates[str(type(hook.layer))] += int(
torch.numel(hook.post_fire_mem_potential[0])
)
if len(hook.post_fire_mem_potential) > 0:
self.neuron_membrane_updates[str(type(hook.layer))] += int(
torch.numel(hook.post_fire_mem_potential[0])
)
self.total_samples += data[0].size(0)
return self.compute()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "neurobench"
version = "1.0.4"
version = "1.0.5"
description = "Collaborative, Fair, and Representative Benchmarks for Neuromorphic Computing"
authors = ["NeuroBench Team <[email protected]>"]
readme = "README.rst"
Expand Down

0 comments on commit 7bb222f

Please sign in to comment.