BrainAI Spiking Core (LIF Family) + Surrogate Gradient Training

Implement explicit state contracts for LIF-family spiking neurons with surrogate gradients.

Updated Feb 28, 2026
One-click install
npx skills add https://github.com/sovr610/refffiy --skill brainai-spiking-core-lif-family-surrogate-gradient-training
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: BrainAI Spiking Core (LIF Family) + Surrogate Gradient Training
Source: https://github.com/sovr610/refffiy/tree/main/brain-ai-dev/skills/spiking-core
Command: npx skills add https://github.com/sovr610/refffiy --skill brainai-spiking-core-lif-family-surrogate-gradient-training

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, pytest, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

Explicitly manage spiking neuron state to prevent hidden leakage and to enable stable, testable training with surrogate gradients, aligning behavior across CPU/GPU and research experiments.

Core Features & Use Cases

  • Explicit state contract for LIF-family neurons (LIF, AdaptiveLIF, RecurrentLIF, AdvancedLIF) to support deterministic resets, carry, and clean sequence processing.
  • Time-unrolled SNN support with a unified snn_unroll utility for truncated BPTT, plus surrogate gradient options (ATan, FastSigmoid, STE) and diagnostics.
  • Extensibility and debugging aids: references, assets templates, and scripts for testing and validation.

Quick Start

Create a tiny network using LIFNeuron with a short input sequence and run it through snn_unroll to observe spikes and state transitions.

Frequently Asked Questions about BrainAI Spiking Core (LIF Family) + Surrogate Gradient Training

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent hidden state leakage when training spiking neural networks in PyTorch?

To prevent hidden state leakage in spiking neural networks, implement an explicit state contract for LIF-family neurons using reset_state, detach_state, and forward with carry_state, ensuring deterministic resets and clean sequence processing across CPU and GPU.

What surrogate gradient options are available for training LIF neurons?

Surrogate gradient options available for training LIF neurons include ATan, FastSigmoid, and Straight-Through Estimator (STE), which stabilize gradient flow through non-differentiable spike generation functions during backpropagation.

How do I implement truncated BPTT for time-unrolled SNNs?

Implement truncated BPTT for time-unrolled SNNs by using the unified snn_unroll utility, which processes sequential data while explicitly managing neuron state carry and detachment to enable stable surrogate gradient training.

Does this explicit state management approach support AdaptiveLIF and RecurrentLIF neurons?

Yes, the explicit state management approach supports AdaptiveLIF and RecurrentLIF neurons, covering the full LIF-family to provide deterministic state resets, state carry, and robust debugging across various spiking neural network architectures.

Why does my spiking neural network training destabilize across different sequence lengths?

Spiking neural network training destabilizes across sequence lengths due to hidden state leakage and unmanaged state carry, which can be resolved by applying an explicit state contract with deterministic resets and surrogate gradients.