spikingjelly.activation_based.functional package#

警告

卷积-批归一化融合函数已弃用。用户可以使用 PyTorch的fuse_conv_bn_eval 来实现相同的功能。

Functions for conv-bn fusion have been deprecated. Use PyTorch's fuse_conv_bn_eval to achieve the same functionality.

备注

API稳定性说明

SpikingJelly 0.0.0.1.0functional 模块的内部实现进行了重构:原来的 functional.py 文件已被拆分并重组为 functional/ 包,以提升代码的模块化程度和可维护性。

该改动不会影响对外公开的 API。 我们强烈建议用户仍然通过 functional 这一顶层命名空间来访问相关功能,而不是从具体的内部子模块中进行导入。 functional 层级下的导入路径被视为稳定的公共接口;更深层的子模块仅作为内部实现细节,未来可能发生变化。

from spikingjelly.activation_based.functional import reset_net # 推荐 ✅
from spikingjelly.activation_based.functional.net_config import reset_net # 不推荐 ❌

API Stability Notice

We have refactored the internal implementation of the functional module. The original functional.py file has been reorganized into a package ( functional/ ) for better modularity and maintainability.

This change does not affect the public API. Users are strongly encouraged to continue accessing layers directly from the functional namespace, rather than importing from specific internal submodules. Import paths under functional are considered part of the stable public API, while deeper submodule paths are treated as implementation details and may change in future releases.

from spikingjelly.activation_based.functional import reset_net # recommended ✅
from spikingjelly.activation_based.functional.net_config import reset_net # not recommended ❌

Network Configuration Functions#

这些函数帮助用户统一设置网络中每个 子模块的配置 ,如步进模式、后端等。


These functions help users set configurations for each submodule in a network, such as step mode and backend.

reset_net

Reset the state of a network.

set_step_mode

Set the step mode for a network.

set_backend

Set the computational backend for a network.

detach_net

Detach the network's parameters from the computation graph.

Forward Functions#

SpikingJelly 的 前向传播函数 实现了 SNN 的多步前向传播逻辑。


SpikingJelly's forward functions provide multi-step forward propagation logic for SNNs.

multi_step_forward

Forward pass for stateful modules in multi-step mode.

t_last_multi_step_forward

Multi-step forward. The time dimension is placed at the last.

chunk_multi_step_forward

Multi-step forward pass with chunked processing.

seq_to_ann_forward

Forward pass for stateless modules in multi-step mode.

t_last_seq_to_ann_forward

Seq-to-ann forward. The time dimension is placed at the last.

Neuron State Updates#

这些函数显式接收并返回神经元状态。*_step 表示一个时间步的完整更新; *_multi_step 表示具有独立实现的时间序列更新,而不是对 *_step 的 Python 循环包装。backend 仍由 MemoryModule 选择,因此 backend 专用函数在名称中 标出 cupytriton


These functions receive and return neuron states explicitly. *_step denotes one complete time-step update. *_multi_step denotes an independently implemented sequence update, not a Python-loop wrapper around *_step. Backend selection remains a MemoryModule responsibility, so backend-specific functions identify cupy or triton in their names.

if_step

One IF state update.

qif_step

One QIF state update.

eif_step

One EIF state update.

lif_step

One LIF state update.

plif_step

One ParametricLIF state update.

izhikevich_step

One Izhikevich voltage and adaptation-current update.

klif_step

One KLIF state update.

cuba_lif_step

One current-based LIF state update.

lava_cuba_lif_step

One Lava-compatible quantized CUBA-LIF state update.

activation_aware_if_step

One ActivationAwareIF state update.

sliding_psn_step

One SlidingPSN queue update.

gated_lif_step

One GatedLIF state update.

stbif_step

One SpikeZIP STBIF state update.

if_step_cupy

One IF update with caller-selected CuPy kernels.

lif_step_cupy

One LIF update with caller-selected CuPy kernels.

if_multi_step_cupy

IF sequence update with CuPy.

lif_multi_step_cupy

LIF sequence update with CuPy.

plif_multi_step_cupy

ParametricLIF sequence update with CuPy.

qif_multi_step_cupy

QIF sequence update with CuPy.

eif_multi_step_cupy

EIF sequence update with CuPy.

izhikevich_multi_step_cupy

Izhikevich sequence update with CuPy.

if_multi_step_triton

IF sequence update with Triton.

lif_multi_step_triton

LIF sequence update with Triton.

plif_multi_step_triton

ParametricLIF sequence update with Triton.

activation_aware_if_multi_step_triton

ActivationAwareIF sequence update with Triton.

Stateful Layer Updates#

这些函数显式接收并返回 stateful layer 的局部状态,不读取 MemoryModule 的隐式 memory。


These functions receive and return local state for stateful layers explicitly. They do not read implicit MemoryModule memory.

delay_step

One Delay queue update.

synapse_filter_step

One SynapseFilter state update.

Loss Functions#

适用于 SNN 的 损失函数 实现。


Loss functions suitable for SNNs.

kernel_dot_product

Kernel dot product implementation.

spike_similar_loss

Spike similarity loss.

temporal_efficient_training_cross_entropy

TET loss.

Learning State Transition Functions#

这些函数显式接收 STDP/mSTDP/mSTDP-ET 的 trace、eligibility、reward 和 raw 权重 tensor,不读取 monitor、MemoryModule memory,也不负责 step_modetraining/eval 或梯度写入。


These functions receive STDP/mSTDP/mSTDP-ET traces, eligibility, reward, and raw weight tensors explicitly. They do not read monitors or MemoryModule memory, and do not manage step_mode, training/eval, or gradient writes.

stdp_linear_step

Tensor-only linear STDP single-step update.

stdp_conv1d_step

Tensor-only Conv1d STDP single-step update.

stdp_conv2d_step

Tensor-only Conv2d STDP single-step update.

mstdp_linear_step

Tensor-only linear mSTDP eligibility update.

mstdpet_linear_step

Tensor-only linear mSTDP-ET eligibility update.

mstdpet_reward_step

Eligibility-trace decay and reward modulation for mSTDP-ET.

Online Learning Pipelines#

在线学习 的辅助函数。


Auxiliary functions for online learning .

fptt_online_training_init_w_ra

Initialize weight for FPTT.

fptt_online_training

Online training with FPTT.

ottt_online_training

Online training with OTTT or SLTT.

Miscellaneous#

其他辅助 工具函数


Other auxiliary tool functions .

set_threshold_margin

Set the threshold margin for classification layers.

redundant_one_hot

Convert labels to redundant one-hot encoding.

first_spike_index

Find the index of the first spike in a spike train.

kaiming_normal_conv_linear_weight

Initialize weights with Kaiming Normal initialization.

delay

y[t] = x[t - delay_steps] .