Clip v_mem to min_v_mem before generating the layer output (fixes #236) - #336
Draft
tritsystem wants to merge 1 commit into
Draft
tritsystem wants to merge 1 commit into
tritsystem wants to merge 1 commit into
Conversation
In lif_forward_single the min_v_mem clip ran *after* v_mem had already been cloned into the output on the no-spike-function branch, so ExpLeak and LIF/IAF built with spike_fn=None returned outputs below min_v_mem even though the stored state was correctly clipped (synsense#236). Move the clip ahead of the spike / no-spike branch, and re-apply it after reset_fn on the spiking branch so the stored state on that path is unchanged for every documented configuration (min_v_mem is None by default and always <= 0 < spike_threshold when set). min_v_mem is a lower bound and spikes are triggered by v_mem crossing the upper spike_threshold, so clipping earlier cannot change which neurons spike. Adds tests/test_layers/test_lif.py::test_min_v_mem_clips_the_output_without_spike_fn (fails on develop) and ::test_min_v_mem_does_not_change_the_spiking_path. Fixes synsense#236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Docs: no user-facing doc change — the
min_v_memdocstring ("Lower bound for membrane potential v_mem, clipped at every time step") already describes the intended behaviour; this PR just makes the code match it. Release notes are maintained per the tag-based release process, happy to add a line if you'd like one.Fixes #236.
Bug fix.
When a
LIForIAFlayer is built without a spike function (spike_fn=None) — which is also exactly what the publicExpLeak/ExpLeakSqueezelayers do internally — the layer output is the membrane potentialv_mem. Whenmin_v_memis set, the stored state is clipped to that floor but the returned output is not, because infunctional/lif.py::lif_forward_singlethe clip runs afterv_memhas already been cloned into the output tensor:Reproduction (
develop@ 904eb89):The existing
test_min_v_memdoes not catch this: it uses a spikingLIFand only asserts onlayer.v_mem, never on the returned output.v_memis clipped tomin_v_membefore the spike / no-spike branch, so the no-spike-fn output respects the floor. On the spiking branch the clip is also re-applied afterreset_fnso the stored state on that path is byte-for-byte identical to before for every documented configuration (min_v_memisNoneby default and always<= 0 < spike_thresholdwhen set).min_v_memis a lower bound and a spike is triggered byv_memcrossing the upperspike_threshold, so clipping earlier cannot change which neurons spike — a new test asserts the spike train is bit-identical with and without the floor on a spiking input.After the fix, every path above reports
output min = -0.5000,0/72below the floor.ALIFis not affected: itsforwardunconditionally dereferencesspike_fn.required_states, so it cannot be run withspike_fn=None, and its output is always spikes, neverv_mem.No. Default
min_v_memisNone(no-op). For spiking layers the stored state and spike output are unchanged. The only behavioural change is that non-spiking layers (ExpLeak,LIF/IAFwithspike_fn=None) now return outputs>= min_v_mem, which is what themin_v_memdocstring already promises.Diff:
sinabs/layers/functional/lif.py+19 / −4 (mostly the moved block + comments),tests/test_layers/test_lif.py+41.New tests in
tests/test_layers/test_lif.py:test_min_v_mem_clips_the_output_without_spike_fn—ExpLeak/LIF(spike_fn=None)/IAF(spike_fn=None)output>= min_v_mem. Fails ondevelop(output -1.48 fell below min_v_mem=-0.5), passes here.test_min_v_mem_does_not_change_the_spiking_path— spike train bit-identical with and withoutmin_v_memon a spiking input.black --check sinabs/ tests/→ 135 files unchanged.pytest tests/(non-hardware modules) → 197 → 199 passed, no regressions.Before (
develop, #236 present)After (this branch)