Import
snn.Sequential
A temporally-unrolled SNN container. Applies layers in order across allT timesteps. Owns and threads LIF state across timesteps — callers do not manage membrane tensors directly.
Input / Output shape
- Input:
[T, batch, in_features]— time-first - Output:
[T, batch, out_features]— time-first, spike raster of the last layer
Sequentialis atorch.nn.Module..parameters(),.state_dict(),.to(device), and all standard PyTorch optimizer integrations work as expected.- LIF state is reset to zero at the start of every
forwardcall. It is not persistent across batches. - Non-LIF layers (Dense, Conv2d, standard
torch.nnmodules) are called without state at each timestep.
snn.Dense
A linear (fully-connected) layer.
Weight initialization
Kaiming uniform (fan-in mode), matching
torch.nn.Linear.
Notes
- Equivalent to
torch.nn.Linear. No temporal state. - Applied at every timestep independently.
snn.LIF
A layer of leaky integrate-and-fire neurons.
Computed constants
The simulation timestep is fixed at
dt = 1.0 ms. It is a class constant (LIF.DT), not a constructor parameter.
Per-timestep update
"subtract"— membrane potential is reduced bythresholdon each spike. Gradients flow through the subtraction path."zero"— membrane potential is reset to zero on each spike. The reset mask is detached from the gradient graph.
- LIF has no weight parameters. Its size is inferred from the output of the preceding layer.
tau_memmust be strictly greater than1.0 ms. A time constant at or below the timestep loses all membrane history within a single step.- Surrogate gradient: fast-sigmoid. See Surrogate Gradients and E0101.
snn.Conv2d
A 2D convolutional layer for spatial spike inputs (event-camera data, 2D feature maps).
Input / Output shapes
- Input per timestep:
[batch, C_in, H, W] - Output per timestep:
[batch, C_out, H_out, W_out]
Sequential, the container calls it at each of the T timesteps.
Training
All THRINDEX layers aretorch.nn.Module subclasses. A standard PyTorch training loop works without modification:
FastSigmoid) handles the non-differentiable spike function during loss.backward(). BPTT gradients flow through all T timesteps automatically via PyTorch autograd.