Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axonal delay as synaptic delay in NetX #173

Merged
merged 43 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4328af7
Merge branch 'lava-nc:main' into main
bamsumit May 18, 2022
1789ef9
Merge branch 'main' of github.com:bamsumit/lava-dl into main
bamsumit Jul 26, 2022
0174ac5
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Sep 29, 2022
c77d7b2
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Oct 5, 2022
4ae5d38
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Oct 24, 2022
45ed337
CI fix for poetry on windows error
bamsumit Oct 24, 2022
391ee3d
Merge branch 'main' of github.com:bamsumit/lava-dl into main
bamsumit Oct 24, 2022
0196460
removed a caching option
bamsumit Oct 24, 2022
8ac07b9
Reverted caching changes
bamsumit Oct 24, 2022
327392b
Reverted caching changes
bamsumit Oct 24, 2022
cd18e65
pipx intallation of poetry
bamsumit Oct 24, 2022
a506edd
removed cache in python installation
bamsumit Oct 24, 2022
19b66a6
Testing testing
bamsumit Oct 24, 2022
5d15056
Updated CI
bamsumit Oct 24, 2022
4d719c3
Change to python v4
bamsumit Oct 24, 2022
e3cb93b
Remove poetry cache
bamsumit Oct 24, 2022
982c656
comments cleanup
bamsumit Oct 24, 2022
f4beb58
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Oct 24, 2022
7dfec3e
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Nov 29, 2022
721187c
Updated Readme to point to lava-dl decolle
bamsumit Nov 29, 2022
d2b82c1
language update
bamsumit Nov 29, 2022
5c94b6a
Updated illustration image
bamsumit Nov 29, 2022
c3348b6
Updated readme
bamsumit Nov 29, 2022
6922b21
Merge branch 'main' into main
bamsumit Dec 1, 2022
f825a07
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Jan 11, 2023
d08ee6b
Merge branch 'main' of github.com:bamsumit/lava-dl into main
bamsumit Jan 11, 2023
6b752b7
Updated benchmarking notebooks to use new callback_fxs api
bamsumit Jan 11, 2023
bd40deb
Fixed netx.hdf5 to handle scale dimensions on input.
bamsumit Jan 13, 2023
24a0892
Linting fixes
bamsumit Jan 13, 2023
bb478da
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Jan 13, 2023
1b9abcf
Restore data from lfs
bamsumit Jan 13, 2023
e37c45a
Temp removing file
bamsumit Jan 13, 2023
0d2bda6
added mnist network file
bamsumit Jan 13, 2023
25ca0f1
added lfs git attributes
bamsumit Jan 13, 2023
a2286c6
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Jan 19, 2023
006cbb2
Merge branch 'main' of github.com:lava-nc/lava-dl into main
bamsumit Mar 3, 2023
22ced7c
Merge branch 'main' of github.com:bamsumit/lava-dl into main
bamsumit Mar 3, 2023
c590409
axonal delay tested on ntidigits input
bamsumit Mar 7, 2023
e15bc49
git lfs files included
bamsumit Mar 7, 2023
a57530a
git lfs ground truths tracked
bamsumit Mar 7, 2023
a925af5
Added ntidigits
bamsumit Mar 7, 2023
5e192c8
added gts as git lfs
bamsumit Mar 7, 2023
f8368cf
Updated unittest description
bamsumit Mar 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions src/lava/lib/dl/netx/blocks/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lava.magma.core.process.ports.ports import InPort, OutPort
from lava.magma.core.process.process import AbstractProcess
from lava.proc.dense.process import Dense as DenseSynapse
from lava.proc.dense.process import DelayDense as DelayDenseSynapse
from lava.proc.conv.process import Conv as ConvSynapse


Expand Down Expand Up @@ -116,6 +117,8 @@ class Dense(AbstractBlock):
dictionary of neuron parameters. Defaults to None.
weight : np.ndarray
synaptic weight.
delay : np.ndarray
synaptic delay.
bias : np.ndarray or None
bias of neuron. None means no bias. Defaults to None.
has_graded_input : dict
Expand All @@ -133,15 +136,25 @@ def __init__(self, **kwargs: Union[dict, tuple, list, int, bool]) -> None:
super().__init__(**kwargs)

weight = kwargs.pop('weight')
delay = kwargs.pop('delay', None)
num_weight_bits = kwargs.pop('num_weight_bits', 8)
weight_exponent = kwargs.pop('weight_exponent', 0)

self.synapse = DenseSynapse(
weights=weight,
weight_exp=weight_exponent,
num_weight_bits=num_weight_bits,
num_message_bits=self.input_message_bits,
)
if delay is None:
self.synapse = DenseSynapse(
weights=weight,
weight_exp=weight_exponent,
num_weight_bits=num_weight_bits,
num_message_bits=self.input_message_bits,
)
else:
self.synapse = DelayDenseSynapse(
weights=weight,
delays=delay.astype(int),
max_delay=62,
num_weight_bits=num_weight_bits,
num_message_bits=self.input_message_bits,
)

if self.shape != self.synapse.a_out.shape:
raise RuntimeError(
Expand Down
41 changes: 32 additions & 9 deletions src/lava/lib/dl/netx/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Network(AbstractProcess):
reset_offset: int
determines the phase shift of network reset if enabled. Defaults to 0.
"""

def __init__(self,
net_config: str,
num_layers: Optional[int] = None,
Expand Down Expand Up @@ -326,12 +327,12 @@ def create_dense(layer_config: h5py.Group,
neuron_config = layer_config['neuron']
else:
# Non-leaky integrator by default
neuron_config = {'type' : 'CUBA',
'iDecay' : 0,
'vDecay' : 4096,
'vThMant' : 1 << 18 - 1,
'refDelay' : 1,
'gradedSpike' : False}
neuron_config = {'type': 'CUBA',
'iDecay': 0,
'vDecay': 4096,
'vThMant': 1 << 18 - 1,
'refDelay': 1,
'gradedSpike': False}
neuron_params = Network.get_neuron_params(neuron_config,
reset_interval=reset_interval,
reset_offset=reset_offset)
Expand Down Expand Up @@ -381,6 +382,27 @@ def create_dense(layer_config: h5py.Group,
'sign_mode': sign_mode,
'input_message_bits': input_message_bits}

if 'delay' in layer_config.keys():
delay = layer_config['delay']

if np.isscalar(delay):
delay = delay * np.ones_like(weight)
elif len(delay.shape) == 1: # delay is one dimensional
num_delays = np.prod(delay.shape)
if num_delays == weight.shape[0]: # axonal delays to syn
delay = np.repeat(delay.reshape(-1, 1),
weight.shape[1], axis=1)
elif num_delays == weight.shape[1]: # input delays
delay = np.repeat(delay.reshape(1, -1),
weight.shape[0], axis=0)
else:
raise RuntimeError(f'Found invalid delay of shape '
f'{delay.shape} to be incompatible '
f'with weight of shape '
f'{weight.shape}.')

params['delay'] = delay

# optional arguments
if 'bias' in layer_config.keys():
params['bias'] = layer_config['bias']
Expand Down Expand Up @@ -571,9 +593,10 @@ def _create(self) -> List[AbstractProcess]:
reset_offset += 1
input_message_bits = layer.output_message_bits
if flatten_next:
layers[-2].out.transpose([2, 1, 0]).flatten().connect(
layers[-1].inp
)
if len(layers) > 1:
layers[-2].out.transpose([2, 1, 0]).flatten().connect(
layers[-1].inp
)
flatten_next = False
else:
if len(layers) > 1:
Expand Down
3 changes: 3 additions & 0 deletions tests/lava/lib/dl/netx/gts/ntidigits/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input.npy filter=lfs diff=lfs merge=lfs -text
ntidigits.net filter=lfs diff=lfs merge=lfs -text
output.npy filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions tests/lava/lib/dl/netx/gts/ntidigits/input.npy
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/lava/lib/dl/netx/gts/ntidigits/ntidigits.net
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/lava/lib/dl/netx/gts/ntidigits/output.npy
Git LFS file not shown
48 changes: 48 additions & 0 deletions tests/lava/lib/dl/netx/test_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,54 @@ def test_pilotnet_sdnn(self) -> None:
f'Error was {error}.'
)

def test_axonal_delay_ntidigits(self) -> None:
"""Tests the output of ntidigits hdf5 description. This network
consists of axonal delay. So this tests specifically tests for
correctness of axonal delay."""
net_config = root + '/gts/ntidigits/ntidigits.net'
input = np.load(root + '/gts/ntidigits/input.npy')
gt = np.load(root + '/gts/ntidigits/output.npy')
num_steps = input.shape[1]

# skipping the last average layer which is not suppprted
net = netx.hdf5.Network(net_config=net_config, num_layers=5)

inp_gen = io.source.RingBuffer(data=input)
output_logger = io.sink.RingBuffer(shape=net.out_layer.shape,
buffer=num_steps)

inp_gen.s_out.connect(net.inp)
net.out.connect(output_logger.a_in)

run_condition = RunSteps(num_steps=num_steps)
run_config = TestRunConfig(select_tag='fixed_pt')
net.run(condition=run_condition, run_cfg=run_config)
output = output_logger.data.get()
net.stop()

out_ev = np.argwhere(output > 0)
gt_ev = np.argwhere(gt > 0)

error = np.abs(output[:, -1] - gt[:, 1]).sum()

if verbose:
if bool(os.environ.get('DISPLAY', None)):
plt.figure(figsize=(10, 5))
plt.plot(out_ev[:, 1], out_ev[:, 0], '.',
markersize=12, label='Output Spikes')
plt.plot(gt_ev[:, 1], gt_ev[:, 0], '.', label='GT Spikes')
plt.xlabel(f'time')
plt.ylabel('Neuron ID')
plt.legend()
plt.show()

self.assertTrue(
error == 0,
f'Output spike and ground truth do not match for NTIDIGITS network.'
f'Found {output[output != gt] = } and {gt[output != gt] = }. '
f'Error was {error}.'
)


if __name__ == '__main__':
unittest.main()