Describe the bug
Calling the leaky-spike-operator surrogate as documented — surrogate.LSO()(x) —
raises a TypeError, so LSO is unusable.
To reproduce
import torch
from snntorch import surrogate
surrogate.LSO()(torch.randn(3))
# TypeError: StochasticSpikeOperator.forward() missing 1 required
# positional argument: 'variance'
Root cause
In snntorch/surrogate.py, LSO() applies the wrong autograd Function:
def LSO(slope=0.1):
def inner(x):
return StochasticSpikeOperator.apply(x, slope) # wrong class
return inner
StochasticSpikeOperator.forward(ctx, input_, mean, variance) requires two
parameters (mean, variance), so slope binds to mean and variance is
missing → TypeError. The intended class is LeakySpikeOperator, whose
forward(ctx, input_, slope) matches — and whose own docstring even shows
surrogate.LSO(slope=0.1).
Suggested fix
def inner(x):
return LeakySpikeOperator.apply(x, slope)
Verified this makes LSO() work (and preserves input dtype once the .float()
fix in the related dtype issue is applied). Happy to include it in the same PR.
Environment
- snnTorch 1.0.0 (also reproduced on 0.9.4)
- PyTorch 2.11.0 · Python 3.12
Describe the bug
Calling the leaky-spike-operator surrogate as documented —
surrogate.LSO()(x)—raises a
TypeError, soLSOis unusable.To reproduce
Root cause
In
snntorch/surrogate.py,LSO()applies the wrong autograd Function:StochasticSpikeOperator.forward(ctx, input_, mean, variance)requires twoparameters (
mean,variance), soslopebinds tomeanandvarianceismissing →
TypeError. The intended class isLeakySpikeOperator, whoseforward(ctx, input_, slope)matches — and whose own docstring even showssurrogate.LSO(slope=0.1).Suggested fix
Verified this makes
LSO()work (and preserves input dtype once the.float()fix in the related dtype issue is applied). Happy to include it in the same PR.
Environment