Skip to content

Fix utils.reset() ignoring neurons in nested containers#414

Open
IonThief wants to merge 2 commits intojeshraghian:masterfrom
IonThief:fix-hidden-states-reset-util
Open

Fix utils.reset() ignoring neurons in nested containers#414
IonThief wants to merge 2 commits intojeshraghian:masterfrom
IonThief:fix-hidden-states-reset-util

Conversation

@IonThief
Copy link
Copy Markdown

@IonThief IonThief commented Jan 29, 2026

Description:

Currently, utils.reset(net) uses net._modules.values() to check for neurons.

This only looks at the first layer of the network.

If neurons are inside containers like nn.Sequential or nn.ModuleList, the function fails to detect them, and their hidden states are not reset.

Fix

I updated _layer_check to use net.modules() instead of net._modules.values().

This recursively searches the entire network, ensuring that all neurons are detected and reset correctly, no matter how deep they are nested.

Verification

I added unit tests that check reset() on different architectures with spiking Leaky neurons

Checklist

  • Applied Flake8 and Black
  • Implemented UnitTests and it all passed

…_modules.values() looks only at direct children of the net, i replaced it with net.modules() to look recursively for neurons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant