Choosing from the built-in layers
Now that we’ve seen the state updates, we can connect them to the public layer names. The SNN families share a feature-wise interface, so we can choose their memory and firing behavior independently of the projections around them. The conventional RNN layers include their own feature projections and gates.
SNN output families and histories
The end of an SNN name describes its output. LI returns the continuous
membrane, LIB fires in one direction, LIT can fire in either direction,
and LITS also scales those signed outputs. The firing families use hard
deterministic events by default, but accept smooth or stochastic firing functions.
The prefixes describe additional histories: S filters input through a
synapse, R filters earlier output through a recurrent trace, and D
separates positive and negative histories. For example, SRLIB combines
synaptic and recurrent histories with one-sided firing. The continuous family
also offers EMA variants for an averaged membrane update.
Family |
Available layers |
|---|---|
Continuous membrane |
|
One-sided firing |
|
Signed firing |
|
Scaled signed firing |
|
In the patch-MNIST tutorial, LIB hidden layers turn accumulated image information into firing events, while the final LI retains continuous class scores. The custom-neuron tutorial changes the synaptic histories while keeping the same membrane and readout ideas, which shows how these choices can be composed.
Features and parameter constraints
For built-in SNN layers, num_features is the size of the final input axis.
tt.snn.LIB(64) therefore accepts [..., 64] and gives each leading position
its own states. A preceding nn.Linear can change the number of features or
mix them; the neuron then applies its dynamics to those projected values.
The decay names follow the history they control: alpha belongs to the
synapse, beta to the membrane, and gamma to recurrent output memory.
Their effective values stay in \((0,1)\) because the layer transforms
unconstrained raw parameters:
The inverse transformation lets us request an effective initial value such as 0.9, while the optimizer works on \(b\). Thresholds and output scales use softplus to stay positive:
We access these effective values through names such as layer.beta and
layer.threshold. Their raw tensors are registered PyTorch parameters, so
ordinary optimizers and weight checkpoints already include them.
A *_rank of 0 creates a shared scalar, while 1 creates one value per neuron.
We can also provide a scalar tensor or a vector with num_features elements
directly, in which case that tensor supplies the parameter shape. The generic
tt.Layer base supports other shapes too; tt.snn.Layer(num_features) adds
the scalar/per-neuron conveniences used by built-in neurons.
The learn_* arguments let us hold a parameter fixed. For example,
learn_beta=False keeps the selected membrane decay while other weights
train. If we change that choice later, set_parameter_learnable("beta", True)
updates the intended setting, including across compilation and decompilation.
Conventional recurrent layers
tt.rnn.SimpleRNN, GRU and LSTM have the same one-timestep state
interface, but learn projections that mix the input and previous hidden features
inside the recurrent layer. Their constructors take in_features and
out_features, and the output size also sets the hidden feature count.
For a SimpleRNN, concatenating the previous hidden vector \(h_{t-1}\) with the input gives the update
The brackets mean concatenation along the feature axis. Unlike a fixed LI decay, this update mixes hidden features and applies a nonlinear function at every step.
A GRU adds reset and update gates, whose values depend on both the input and the previous state. In traceTorch’s convention:
Here \(\sigma\) is sigmoid, and \(\odot\) means element-wise multiplication. The matrices \(W_g\), \(W_c\) and biases \(b_g\), \(b_c\) are learned projections. The reset gate \(r_t\) selects how much old state enters the candidate, while \(z_t\) selects how much of that candidate replaces the old state. This gives the model input-dependent control over memory. These gated layers use the same state operations as the SNN layers, so they can be used with the same explicit sequence loops even though their internal updates differ.
An LSTM keeps a cell state \(c_t\) as well as its hidden output \(h_t\). Its learned input, forget and output gates \(i_t\), \(f_t\), \(o_t\) control a candidate \(\tilde c_t\) and the updates
Both cell and hidden state take part in the same model-level reset, detach and save operations. We don’t need a separate training interface for each kind of recurrent memory.
Extending the library
When the existing updates don’t describe the states we need, tt.Layer lets
us declare those states and their tensor shapes directly. We can then define
transformed parameters and write one timestep of the update in forward.
The Building a neuron with several synaptic memories tutorial does this with a matrix of synaptic
histories, rather than assuming every state is a vector.
The remaining helpers support these updates: tt.inverse_fn supplies inverse
initialization transforms, tt.snn.spike_fn supplies firing functions, and
tt.utils provides decay conversion and explicit axis movement. The
Reference gives their signatures when you need exact arguments.