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

Persistent delay buffer to correctly run slayer blocks one timestep at a time #169

Merged
merged 38 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
ba0c2db
Delay buffer added
bamsumit Mar 2, 2023
830d2c4
Merge branch 'main' into persistent_delay
bamsumit Mar 2, 2023
485f385
Fixed quantization range
bamsumit Mar 2, 2023
88813f0
Dummy change
bamsumit Mar 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 35 additions & 8 deletions src/lava/lib/dl/slayer/block/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@
from lava.lib.dl.slayer.utils import recurrent


def step_delay(module, x):
"""Step delay computation. This simulates the 1 timestep delay needed
for communication between layers.

Parameters
----------
module: module
python module instance
x : torch.tensor
Tensor data to be delayed.
"""
if hasattr(module, 'delay_buffer') is False:
module.delay_buffer = None
persistent_state = hasattr(module, 'neuron') \
and module.neuron.persistent_state is True
if module.delay_buffer is not None:
if module.delay_buffer.shape[0] != x.shape[0]: # batch mismatch
module.delay_buffer = None
if persistent_state:
delay_buffer = 0 if module.delay_buffer is None else module.delay_buffer
module.delay_buffer = x[..., -1]
x = delay(x, 1)
if persistent_state:
x[..., 0] = delay_buffer
return x


class AbstractInput(torch.nn.Module):
"""Abstract input block class. This should never be instantiated on its own.

Expand Down Expand Up @@ -88,7 +115,7 @@ def forward(self, x):
x = self.neuron(z)

if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)

if self.input_shape is None:
if self.neuron is not None:
Expand Down Expand Up @@ -515,7 +542,7 @@ def forward(self, x):
z = self.synapse(x)
x = self.neuron(z)
if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down Expand Up @@ -670,7 +697,7 @@ def forward(self, x):
z = self.synapse(x)
x = self.neuron(z)
if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down Expand Up @@ -822,7 +849,7 @@ def forward(self, x):
z = self.synapse(x)
x = self.neuron(z)
if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down Expand Up @@ -962,7 +989,7 @@ def forward(self, x):
z = self.synapse(x)
x = self.neuron(z)
if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down Expand Up @@ -1114,7 +1141,7 @@ def forward(self, x):
z = self.synapse(x)
x = self.neuron(z)
if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down Expand Up @@ -1320,7 +1347,7 @@ def forward(self, x):
# self.spike_state = spike.clone().detach().reshape(z.shape[:-1])

if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)

if self.count_log is True:
return x, torch.mean(x > 0)
Expand Down Expand Up @@ -1442,7 +1469,7 @@ def forward(self, x):
self.spike_state = spike.clone().detach().reshape(z.shape[:-1])

if self.delay_shift is True:
x = delay(x, 1)
x = step_delay(self, x)
if self.delay is not None:
x = self.delay(x)

Expand Down
4 changes: 2 additions & 2 deletions src/lava/lib/dl/slayer/neuron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ def quantize_8bit(self, weight, descale=False):
if descale is False:
return quantize(
weight, step=2 / self.w_scale
).clamp(-256 / self.w_scale, 255 / self.w_scale)
).clamp(-256 / self.w_scale, 254 / self.w_scale)
else:
return quantize(
weight, step=2 / self.w_scale
).clamp(-256 / self.w_scale, 255 / self.w_scale) * self.w_scale
).clamp(-256 / self.w_scale, 254 / self.w_scale) * self.w_scale

@property
def weight_exponent(self):
Expand Down