Skip to content

Commit

Permalink
Run black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
bauerfe committed Nov 12, 2024
1 parent 10e1bab commit 205077d
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 34 deletions.
1 change: 1 addition & 0 deletions sinabs/backend/dynapcnn/chips/speck2cmini.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import samna
from samna.speck2cMini.configuration import SpeckConfiguration

from sinabs.backend.dynapcnn.dynapcnn_layer import DynapcnnLayer
from sinabs.backend.dynapcnn.mapping import LayerConstraints

Expand Down
1 change: 1 addition & 0 deletions sinabs/backend/dynapcnn/chips/speck2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import samna
from samna.speck2e.configuration import SpeckConfiguration

from sinabs.backend.dynapcnn.dynapcnn_layer import DynapcnnLayer

from .dynapcnn import DynapcnnConfigBuilder
Expand Down
1 change: 1 addition & 0 deletions sinabs/backend/dynapcnn/chips/speck2f.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import samna
from samna.speck2f.configuration import SpeckConfiguration

from sinabs.backend.dynapcnn.dynapcnn_layer import DynapcnnLayer

from .dynapcnn import DynapcnnConfigBuilder
Expand Down
3 changes: 2 additions & 1 deletion sinabs/backend/dynapcnn/config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from typing import Dict, List

import samna
from samna.dynapcnn.configuration import DynapcnnConfiguration

import sinabs
import sinabs.backend
import sinabs.backend.dynapcnn
from samna.dynapcnn.configuration import DynapcnnConfiguration

from .dvs_layer import DVSLayer
from .dynapcnn_layer import DynapcnnLayer
Expand Down
3 changes: 2 additions & 1 deletion sinabs/backend/dynapcnn/discretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from typing import Optional, Tuple
from warnings import warn

import sinabs.layers as sl
import torch
import torch.nn as nn

import sinabs.layers as sl

DYNAPCNN_WEIGHT_PRECISION_BITS = 8
DYNAPCNN_STATE_PRECISION_BITS = 16

Expand Down
1 change: 1 addition & 0 deletions sinabs/backend/dynapcnn/dvs_layer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Tuple

import torch.nn as nn

from sinabs.layers import SumPool2d
from sinabs.utils import expand_to_pair

Expand Down
14 changes: 5 additions & 9 deletions sinabs/backend/dynapcnn/dynapcnn_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
... and `dvs_input` is `None`, the `disable_pixel_array` attribute
of the layer will not be changed.
... and `dvs_input` is `True`, `disable_pixel_array` will be set
`False`, so that the DVS sensor data is sent to the network.
`False`, so that the DVS sensor data is sent to the network.
If no `DVSLayer` is part of `snn`...
... and `dvs_input` is `False` or `None`, no `DVSLayer` will be added
and the DVS sensor will not be configured upon deployment.
Expand Down Expand Up @@ -138,9 +138,7 @@ def dynapcnn_module(self):

@property
def exit_layers(self):
return [
self.all_layers[i] for i in self._dynapcnn_module.get_exit_layers()
]
return [self.all_layers[i] for i in self._dynapcnn_module.get_exit_layers()]

@property
def exit_layer_ids(self):
Expand Down Expand Up @@ -525,8 +523,8 @@ def has_dvs_layer(self) -> bool:
return self.dvs_layer is not None

def zero_grad(self, set_to_none: bool = False) -> None:
""" Call `zero_grad` method of each DynapCNN layer
"""Call `zero_grad` method of each DynapCNN layer
Parameters
----------
- set_to_none (bool): This argument is passed directly to the
Expand Down Expand Up @@ -765,9 +763,7 @@ def __repr__(self):
class DynapcnnCompatibleNetwork(DynapcnnNetwork):
"""Deprecated class, use DynapcnnNetwork instead."""

def __init__(
self, *args, **kwargs
):
def __init__(self, *args, **kwargs):
from warnings import warn

warn(
Expand Down
1 change: 0 additions & 1 deletion sinabs/backend/dynapcnn/nir_graph_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def get_dynapcnn_network_module(
"destinations": None,
}


# build `DynapcnnLayer` instances from mapper.
dynapcnn_layers, destination_map, entry_points = (
construct_dynapcnnlayers_from_mapper(
Expand Down
3 changes: 2 additions & 1 deletion sinabs/backend/dynapcnn/specksim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import numpy as np
import samna
import sinabs.layers as sl
import torch.nn as nn
from samna.specksim.nodes import SpecksimConvolutionalFilterNode as ConvFilter
from samna.specksim.nodes import SpecksimIAFFilterNode as IAFFilter
from samna.specksim.nodes import SpecksimSumPoolingFilterNode as SumPoolFilter

import sinabs.layers as sl
from sinabs.backend.dynapcnn import DynapcnnCompatibleNetwork, DynapcnnNetwork
from sinabs.backend.dynapcnn.dynapcnn_layer import DynapcnnLayer

Expand Down
3 changes: 2 additions & 1 deletion tests/test_dynapcnn/test_discover_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from sinabs.backend.dynapcnn import io


pytest.mark.skip("Not suitable for automated testing. Depends on available devices")


def test_is_device_type():
devices = samna.device.get_all_devices()
print([io.is_device_type(d, "dynapcnndevkit") for d in devices])
Expand Down
6 changes: 5 additions & 1 deletion tests/test_dynapcnn/test_dvs_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def test_dvs_no_pooling(dvs_input):


args = product((True, False, None), (True, False))


@pytest.mark.parametrize("dvs_input,add_input_layer", args)
def test_dvs_pooling_2d(dvs_input, add_input_layer):
# - ANN and SNN generation
Expand All @@ -155,7 +157,9 @@ def test_dvs_pooling_2d(dvs_input, add_input_layer):
spn = DynapcnnNetwork(snn, dvs_input=dvs_input)

# - Compare snn and spn outputs. - Always add DVS so that pooling layer is properly handled
spn_float = DynapcnnNetwork(snn, dvs_input=True, discretize=False, input_shape=INPUT_SHAPE)
spn_float = DynapcnnNetwork(
snn, dvs_input=True, discretize=False, input_shape=INPUT_SHAPE
)
snn_out = snn(input_data).squeeze()
spn_out = spn_float(input_data).squeeze()
assert torch.equal(snn_out.detach(), spn_out)
Expand Down
8 changes: 2 additions & 6 deletions tests/test_dynapcnn/test_speckmini_config_making.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ def test_auto_mapping():

for test_device in devices:
# test weights/kernel memory mapping
_ = SNN_KERNEL_MEM_TEST.make_config(
layer2core_map="auto", device=test_device
)
_ = SNN_KERNEL_MEM_TEST.make_config(layer2core_map="auto", device=test_device)
assert SNN_KERNEL_MEM_TEST.layer2core_map == {0: 0, 1: 1, 2: 3, 3: 2, 4: 4}

# test neuron memory mapping
_ = SNN_NEURON_MEM_TEST.make_config(
layer2core_map="auto", device=test_device
)
_ = SNN_NEURON_MEM_TEST.make_config(layer2core_map="auto", device=test_device)
assert SNN_NEURON_MEM_TEST.layer2core_map == {0: 2, 1: 0, 2: 1, 3: 4, 4: 3}


Expand Down
4 changes: 1 addition & 3 deletions tests/test_dynapcnn/test_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def get_demo_dynapcnn_network():
ann = nn.Sequential(nn.Conv2d(2, 8, (3, 3)), nn.ReLU(), nn.AvgPool2d((2, 2)))
snn = sinabs.from_model(ann, input_shape=(2, 64, 64), batch_size=1)

dynapcnn_network = DynapcnnNetwork(
snn=snn, input_shape=(2, 64, 64), dvs_input=True
)
dynapcnn_network = DynapcnnNetwork(snn=snn, input_shape=(2, 64, 64), dvs_input=True)
return dynapcnn_network


Expand Down
8 changes: 4 additions & 4 deletions tests/test_dynapcnnlayer/conftest_dynapcnnlayer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# author : Willian Soares Girao
# contact : [email protected]

from .model_dummy_1 import expected_output_1, dcnnl_map_1
from .model_dummy_2 import expected_output_2, dcnnl_map_2
from .model_dummy_3 import expected_output_3, dcnnl_map_3
from .model_dummy_4 import expected_output_4, dcnnl_map_4
from .model_dummy_1 import dcnnl_map_1, expected_output_1
from .model_dummy_2 import dcnnl_map_2, expected_output_2
from .model_dummy_3 import dcnnl_map_3, expected_output_3
from .model_dummy_4 import dcnnl_map_4, expected_output_4

# Args: dcnnl_map, discretize, expected_output
args_DynapcnnLayer = [
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dynapcnnlayer/test_dynapcnnlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# contact : [email protected]

import pytest
from .conftest_dynapcnnlayer import args_DynapcnnLayer

from sinabs.backend.dynapcnn.dynapcnn_layer_utils import (
construct_dynapcnnlayers_from_mapper,
)

from .conftest_dynapcnnlayer import args_DynapcnnLayer


@pytest.mark.parametrize(
"dcnnl_map, discretize, expected_output",
Expand Down
5 changes: 2 additions & 3 deletions tests/test_dynapcnnnetwork/conftest_dynapcnnnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
from .model_dummy_4 import expected_output as expected_output_4
from .model_dummy_4 import input_shape as input_shape_4
from .model_dummy_4 import snn as snn_4
from .model_dummy_4 import snn as snn_4
from .model_dummy_seq import (
expected_seq_1,
expected_seq_2,
input_shape_seq,
seq_1,
seq_2,
expected_seq_1,
expected_seq_2,
)

args_DynapcnnNetworkTest = [
Expand Down
1 change: 0 additions & 1 deletion tests/test_dynapcnnnetwork/model_dummy_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from sinabs.layers import IAFSqueeze, SumPool2d


input_shape_seq = (2, 30, 30)

seq_1 = nn.Sequential(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dynapcnnnetwork/test_dynapcnnnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import pytest
import torch
from .conftest_dynapcnnnetwork import args_DynapcnnNetworkTest

from sinabs.backend.dynapcnn.dynapcnn_network import DynapcnnNetwork

from .conftest_dynapcnnnetwork import args_DynapcnnNetworkTest


@pytest.mark.parametrize(
"snn, input_shape, batch_size, expected_output", args_DynapcnnNetworkTest
Expand Down

0 comments on commit 205077d

Please sign in to comment.