Network Configuration Functions#
这些函数帮助用户统一设置网络中每个 子模块的配置 ,如步进模式、后端等。
These functions help users set configurations for each submodule in a network, such as step mode and backend.
- spikingjelly.activation_based.functional.net_config.collect_reset_modules(net: Module) tuple[Module, ...][源代码]#
- spikingjelly.activation_based.functional.net_config.detach_net(net: Module)[源代码]#
-
中文
将
net中各有状态模块与之前时间步的计算图断开。该函数会遍历
net.modules()中的所有子模块;若某个子模块实现了detach()方法,则调用该方法。对于不是MemoryModule但实现了detach()的模块,此函数仍会调用detach(),同时记录告警。- 参数:
net (torch.nn.Module) -- 任何属于
nn.Module子类的网络- 返回:
None- 返回类型:
None
- 抛出:
Exception -- 任何子模块
detach()在执行过程中抛出的异常都会原样向上传播
English
Detach stateful modules in
netfrom the computation graphs of previous time steps.This function iterates over
net.modules()and callsdetach()on each submodule that implements it. If a submodule is not an instance ofMemoryModulebut still definesdetach(), the function will still call it and emit a warning.- 参数:
net (torch.nn.Module) -- Any network inherits from
nn.Module- 返回:
None- 返回类型:
None
- 抛出:
Exception -- Any exception raised by a submodule
detach()call is propagated unchanged
- spikingjelly.activation_based.functional.net_config.reset_collected_modules(modules: tuple[Module, ...]) None[源代码]#
- spikingjelly.activation_based.functional.net_config.reset_net(net: Module)[源代码]#
-
中文
重置
net中所有可重置模块的状态。该函数会遍历
net.modules()中的所有子模块;若某个子模块实现了reset()方法,则调用该方法。对于不是MemoryModule但实现了reset()的模块,此函数仍会调用reset(),同时记录告警。- 参数:
net (torch.nn.Module) -- 任何属于
nn.Module子类的网络- 返回:
None- 返回类型:
None
- 抛出:
Exception -- 任何子模块
reset()在执行过程中抛出的异常都会原样向上传播
English
Reset the states of all resettable modules in
net.This function iterates over
net.modules()and callsreset()on each submodule that implements it. If a submodule is not an instance ofMemoryModulebut still definesreset(), the function will still call it and emit a warning.- 参数:
net (torch.nn.Module) -- Any network inherits from
nn.Module- 返回:
None- 返回类型:
None
- 抛出:
Exception -- Any exception raised by a submodule
reset()call is propagated unchanged
- spikingjelly.activation_based.functional.net_config.set_backend(net: Module, backend: str, instance: Module | tuple[Module] | None = None)[源代码]#
-
中文
将
net中所有满足isinstance(m, instance)且具有backend属性的模块后端设置为backend。仅当目标模块的
supported_backends包含给定backend时才会实际更新; 否则会记录告警并保留原有后端。若instance为None,则会检查所有具有backend属性的模块。- 参数:
net (torch.nn.Module) -- 一个神经网络
backend (str) -- 使用哪个后端
instance (Optional[Union[nn.Module, tuple[nn.Module]]]) -- 传给
isinstance的筛选类型。满足该筛选且具有backend属性的模块后端会被检查。 若为None,则所有具有backend属性的模块都会被检查
- 返回:
None- 返回类型:
None
- 抛出:
Exception -- 若目标模块在访问
supported_backends或设置backend时抛出异常,则该异常会原样向上传播
English
Set
backendfor all modules innetwhose type matchesinstanceand that expose abackendattribute.The backend is updated only when
backendis listed in the module'ssupported_backends. Otherwise, a warning is logged and the existing backend is kept unchanged. IfinstanceisNone, all modules with abackendattribute are checked.- 参数:
net (torch.nn.Module) -- a network
backend (str) -- the backend to be set
instance (Optional[Union[nn.Module, tuple[nn.Module]]]) -- the type filter passed to
isinstance. Modules that match this filter and have abackendattribute will be checked. IfNone, all modules with abackendattribute will be checked
- 返回:
None- 返回类型:
None
- 抛出:
Exception -- Propagated if a target module raises while exposing
supported_backendsor assigningbackend
- spikingjelly.activation_based.functional.net_config.set_step_mode(net: Module, step_mode: str)[源代码]#
-
中文
将
net中所有具有step_mode属性的模块的步进模式设置为step_mode。备注
StepModeContainer,ElementWiseRecurrentContainer,LinearRecurrentContainer的子模块(不包含包装器本身)的step_mode不会被改变。若某个模块具有
step_mode属性但不是StepModule,则该函数仍会尝试赋值, 同时记录告警。- 参数:
net (torch.nn.Module) -- 一个神经网络
step_mode (str) -- 's' (单步模式) 或 'm' (多步模式)
- 返回:
None- 返回类型:
None
- 抛出:
ValueError -- 若某个模块的
step_modesetter 不接受给定的step_mode,则该异常会原样向上传播
English
Set
step_modetostep_modefor all modules innetthat expose astep_modeattribute.Note
The submodule (not including the container itself) of
StepModeContainer,ElementWiseRecurrentContainer,LinearRecurrentContainerwill not be changed.If a module has a
step_modeattribute but is not an instance ofStepModule, the function still attempts to assign the new value and emits a warning.- 参数:
net (nn.Module) -- a network
step_mode (str) -- 's' (single-step) or 'm' (multi-step)
- 返回:
None- 返回类型:
None
- 抛出:
ValueError -- Propagated if a module rejects the provided
step_modein its setter