Online Learning Modules#

SpikingJelly 的 在线学习模块 提供了用于在线学习的辅助类和操作。


SpikingJelly's online learning modules provide auxiliary classes and operations for online learning.

class spikingjelly.activation_based.layer.online_learning.ReplaceforGrad(*args, **kwargs)[源代码]#

基类:Function

API Language: 中文 | English


  • 中文

在 OTTT 在线训练中用于替换前向值与梯度路径的自定义自动求导函数。 前向返回 x_r,反向时梯度同时传播给 xx_r


  • English

Custom autograd Function for replacing forward values and gradient paths in OTTT online training. Forward returns x_r, backward passes gradients to both x and x_r.

static forward(ctx, x, x_r)[源代码]#
static backward(ctx, grad)[源代码]#
class spikingjelly.activation_based.layer.online_learning.GradwithTrace(module)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

用于随时间在线训练时,根据神经元的迹计算梯度 出处:'Online Training Through Time for Spiking Neural Networks <https://openreview.net/forum?id=Siv3nHYHheI>'

参数:

module (torch.nn.Module) -- 需要包装的模块


  • English

Used for online training through time, calculate gradients by the traces of neurons Reference: 'Online Training Through Time for Spiking Neural Networks <https://openreview.net/forum?id=Siv3nHYHheI>'

参数:

module (torch.nn.Module) -- the module that requires wrapping

forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

参数:

x (torch.Tensor) -- [spike, trace],其中 spike 用于前向值,trace 用于梯度路径

返回:

包装模块的输出,前向值来自 spike,反向梯度来自 trace

返回类型:

torch.Tensor


  • English

参数:

x (torch.Tensor) -- [spike, trace] where spike provides forward values and trace provides gradient paths

返回:

Wrapped-module output with forward value from spike and backward gradient from trace

返回类型:

torch.Tensor

class spikingjelly.activation_based.layer.online_learning.SpikeTraceOp(module)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

对脉冲和迹进行相同的运算,如Dropout,AvgPool等

参数:

module (torch.nn.Module) -- 需要包装的模块


  • English

perform the same operations for spike and trace, such as Dropout, Avgpool, etc.

参数:

module (torch.nn.Module) -- the module that requires wrapping

forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

参数:

x (torch.Tensor) -- [spike, trace] 输入对

返回:

spiketrace 施加相同算子后的结果 [spike, trace]

返回类型:

list[torch.Tensor]


  • English

参数:

x (torch.Tensor) -- [spike, trace] input pair

返回:

[spike, trace] after applying the same operator to both

返回类型:

list[torch.Tensor]

class spikingjelly.activation_based.layer.online_learning.OTTTSequential(*args)[源代码]#

基类:Sequential

API Language: 中文 | English


  • 中文

用于 OTTT(Online Training Through Time)的顺序容器,扩展自 nn.Sequential。 在 forward 中,若输入为 [spike, trace] 列表形式,则自动将有参数的模块包装为 GradwithTrace, 将无参数的模块包装为 SpikeTraceOp,以实现在线训练中的梯度传递。

参数:

args (nn.Module) -- 需要顺序执行的模块

返回:

None

返回类型:

None


  • English

Sequential container for OTTT (Online Training Through Time), extending nn.Sequential. During forward, if the input is a [spike, trace] list, modules with parameters are automatically wrapped by GradwithTrace, while parameter-free modules are wrapped by SpikeTraceOp, enabling gradient propagation for online training.

参数:

args (nn.Module) -- Modules to be executed sequentially

返回:

None

返回类型:

None

forward(input)[源代码]#

API Language: 中文 | English


  • 中文

参数:

input (Union[torch.Tensor, list[torch.Tensor]]) -- 常规张量输入,或 [spike, trace] 形式输入

返回:

顺序执行后的输出

返回类型:

Union[torch.Tensor, list[torch.Tensor]]


  • English

参数:

input (Union[torch.Tensor, list[torch.Tensor]]) -- Regular tensor input, or [spike, trace] style input

返回:

Output after sequential execution

返回类型:

Union[torch.Tensor, list[torch.Tensor]]