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
中文
在 OTTT 在线训练中用于替换前向值与梯度路径的自定义自动求导函数。 前向返回
x_r,反向时梯度同时传播给x和x_r。
English
Custom autograd Function for replacing forward values and gradient paths in OTTT online training. Forward returns
x_r, backward passes gradients to bothxandx_r.
- class spikingjelly.activation_based.layer.online_learning.GradwithTrace(module)[源代码]#
基类:
Module
中文
用于随时间在线训练时,根据神经元的迹计算梯度 出处:'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)[源代码]#
-
中文
- 参数:
x (torch.Tensor) --
[spike, trace],其中spike用于前向值,trace用于梯度路径- 返回:
包装模块的输出,前向值来自
spike,反向梯度来自trace- 返回类型:
English
- 参数:
x (torch.Tensor) --
[spike, trace]wherespikeprovides forward values andtraceprovides gradient paths- 返回:
Wrapped-module output with forward value from
spikeand backward gradient fromtrace- 返回类型:
- class spikingjelly.activation_based.layer.online_learning.SpikeTraceOp(module)[源代码]#
基类:
Module
中文
对脉冲和迹进行相同的运算,如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)[源代码]#
-
中文
- 参数:
x (torch.Tensor) --
[spike, trace]输入对- 返回:
对
spike与trace施加相同算子后的结果[spike, trace]- 返回类型:
English
- 参数:
x (torch.Tensor) --
[spike, trace]input pair- 返回:
[spike, trace]after applying the same operator to both- 返回类型:
- class spikingjelly.activation_based.layer.online_learning.OTTTSequential(*args)[源代码]#
基类:
Sequential
中文
用于 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. Duringforward, if the input is a[spike, trace]list, modules with parameters are automatically wrapped byGradwithTrace, while parameter-free modules are wrapped bySpikeTraceOp, enabling gradient propagation for online training.- 参数:
args (nn.Module) -- Modules to be executed sequentially
- 返回:
None- 返回类型:
None
- forward(input)[源代码]#
-
中文
- 参数:
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]]