Gradient Stabilisation

#exp015 · SNNSIM ·

Using the control

--v-grad-dampen changes the backward pass through the legacy biophysical neuron’s membrane increment. It is intended to reduce gradient amplification without intentionally changing the forward model. It does not divide the entire voltage gradient by a constant, repair a non-finite forward pass, or guarantee convergence.

In tools/snnsim/models.py, both lif_step and lif_step_expeuler apply _scale_grad(dv, 1.0 / v_grad_dampen) to the voltage increment dv. The legacy training CLI defaults to 80; the exp006Training explicitly uses 1000. Treat either value as a configuration choice, not a universal threshold. A value of 1 disables the scaling. Use positive values, and values at least 1 when the intention is damping rather than amplification.

Damping changes the optimization problem’s supplied gradients. Keep it fixed when reproducing a recipe; record it when comparing training runs. Graph-native training has its own recipe contract: see exp088Training recipes and graph-native learning.

Check the primitive

This small check exercises the actual helper without training a network or downloading data. Run it from the repository root:

import torch
from tools.snnsim.models import _scale_grad

x = torch.tensor([2.0], dtype=torch.float64, requires_grad=True)
y = _scale_grad(x, 0.01)
y.sum().backward()
torch.testing.assert_close(y, x)
torch.testing.assert_close(x.grad, torch.tensor([0.01], dtype=x.dtype))

Expected result: both assertions pass. The forward value is approximately 2 and its derivative is approximately 0.01. The helper is private; this is an implementation check, not a new public API.

The helper computes

𝐹𝑐(𝑥)=𝑐𝑥+(1𝑐)detach(𝑥).
(1)

Here 𝑥 is the input tensor, 𝑐 is a dimensionless gradient scale, and detach retains the value while removing its autograd dependency. In exact arithmetic 𝐹𝑐(𝑥)=𝑥, but autograd returns derivative 𝑐. Floating-point multiplication and addition can introduce rounding: this expression does not establish bitwise identity of full trajectories. PyTorch documents the dependency boundary in Tensor.detach.

The implemented update

The following equations describe the local exponential-Euler membrane update with noise and active voltage clamps excluded. They are an implementation derivation, not a proof of global network stability. The exp100COBANet page covers the surrounding dynamics.

The synapse helper decays the previous conductance and then adds the spike kick:

𝑔𝑘+1=𝛽syn𝑔𝑘+𝑠[𝑘]𝑊,𝛽syn=𝑒Δ𝑡sim𝜏syn.
(2)

Here 𝑔𝑘 is a row of conductances in μS at step 𝑘, 𝑠[𝑘] the supplied dimensionless presynaptic spike row, 𝑊 the stored weight matrix in μS, Δ𝑡sim the integration timestep in ms, and 𝜏syn the pathway’s synaptic decay time in ms. In particular, the new kick is not multiplied by 𝛽syn. Network scheduling determines which spike row reaches each pathway.

Using the updated excitatory and inhibitory conductances 𝑔𝑒 and 𝑔𝑖, define

𝑔tot=𝑔𝐿+𝑔𝑒+𝑔𝑖,𝑉=𝑔𝐿𝐸𝐿+𝑔𝑒𝐸𝑒+𝑔𝑖𝐸𝑖𝑔tot,𝛼mem=𝑒Δ𝑡sim𝑔tot𝐶𝑚.
(3)

Here 𝑔𝐿 is leak conductance, 𝐶𝑚 capacitance in nF, and 𝐸𝐿, 𝐸𝑒, 𝐸𝑖 the leak, excitatory, and inhibitory reversal potentials in mV. 𝑔tot is total conductance, 𝑉 the frozen-conductance equilibrium voltage, and 𝛼mem the dimensionless membrane decay.

For current voltage 𝑉𝑚, the increment and candidate voltage are

d𝑉𝑚=(𝑉𝑉𝑚)(1𝛼mem),𝑉candidate=𝑉𝑚+𝐹1𝑑grad(d𝑉𝑚).
(4)

Here 𝑑grad is the dimensionless damping divisor configured by v_grad_dampen, and 𝑉candidate is the candidate voltage before noise, clamps, thresholding, and reset. The implementation advances the voltage before testing its spike threshold. On a spiking or refractory neuron, torch.where replaces the retained voltage with the reset value; the emitted spike remains a separate output with its surrogate derivative.

What the derivatives say

Holding conductances fixed, the backward derivative of the candidate voltage is

𝜕𝑉candidate𝜕𝑉𝑚=11𝛼mem𝑑grad.
(5)

Thus damping the increment preserves the direct 𝑉𝑚 pathway; it does not replace the full derivative by 𝛼mem𝑑grad. For 𝑑grad1 and positive conductances this local derivative lies between 𝛼mem and 1.

Define the undamped conductance sensitivity for channel 𝑞{𝑒,𝑖} as

𝜅𝑞=(1𝛼mem)𝐸𝑞𝑉𝑔tot(Δ𝑡sim𝐶𝑚)𝛼mem(𝑉𝑚𝑉).
(6)

𝐸𝑞 is that channel’s reversal potential. The damped candidate-voltage derivative is 𝜕𝑉candidate𝜕𝑔𝑞=𝜅𝑞𝑑grad. At small timesteps, 𝜅𝑞(Δ𝑡sim𝐶𝑚)(𝐸𝑞𝑉𝑚). This is where the control reduces sensitivity to both recurrent and feedforward conductance inputs.

These are local derivatives before reset and active clamps. Reset gates every derivative of the retained reset voltage, not just its membrane self-term. Gradients through the emitted spike can still propagate along other paths. The full backward pass combines these paths across cells and time; time-accumulated readouts also inject gradients at multiple steps.

A scalar loop-gain estimate can be a heuristic, but does not prove that gradients grow once per gamma cycle or that dividing an estimated gain by 𝑑grad2 makes the entire network contractive. Such claims require the actual trajectory, stored fan-in-scaled weights, surrogate normalization, gates, and full coupled Jacobians. Neither successful forward simulation nor removal of the inhibitory loop guarantees stable learning.

Diagnosing a training failure

  1. Locate the first non-finite value. Check inputs, forward states, loss, and then gradients. If the forward pass is invalid, changing the backward derivative is not the repair.
  2. Inspect the optimizer diagnostics. The legacy trainer records gradient norms and skipped updates. It clips the assembled gradient to norm 1 and skips an update if that norm is non-finite. Clipping cannot make an already invalid gradient informative.
  3. Change one control at a time. Compare positive damping values while keeping the seed, input, duration, timestep, initialization, and optimizer settings fixed. Lower learning rate and stronger damping are different interventions.
  4. Check learning as well as finiteness. Stronger damping also reduces useful conductance-input sensitivities. A finite loss with negligible learning is not sufficient evidence of a good setting.
  5. Keep the scope of the check explicit. The helper assertion verifies its local derivative. Establishing training stability or accuracy requires a separately authorized experiment, with recorded diagnostics and validation results.

exp006Training · exp003SNNSIM API Reference