Skip to content

surrogate.LSO() raises TypeError — wraps the wrong autograd Function #430

Description

@tritsystem

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions