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.detach_net(net)[源代码]#
-
中文
将
net中各有状态模块与之前时间步的计算图断开。该函数会遍历
net.modules()中的所有子模块;若某个子模块实现了detach()方法,则调用该方法。对于不是MemoryModule但实现了detach()的模块,此函数仍会调用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.
- spikingjelly.activation_based.functional.net_config.invalidate_reset_cache(net)[源代码]#
-
中文
清除
net的 reset 模块缓存。当模型结构发生变化后调用 (如torch.compile或模块替换)。- 参数:
net (Module) -- 目标网络
- 返回类型:
None
English
Clear the reset module cache for
net. Call after model structure changes (e.g.torch.compileor module swaps).- 参数:
net (Module) -- Target network
- 返回类型:
None
- spikingjelly.activation_based.functional.net_config.reset_net(net)[源代码]#
-
中文
重置
net中所有可重置模块的状态。该函数会遍历
net.modules()中的所有子模块;若某个子模块实现了reset()方法,则调用该方法。对于不是MemoryModule但实现了reset()的模块,此函数仍会调用reset(),同时记录告警。首次调用时收集并缓存可重置模块列表,后续调用直接复用缓存。 若模型结构发生变化(如
torch.compile或模块替换), 请调用invalidate_reset_cache()清除缓存。
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.On the first call, the resettable module list is collected and cached; subsequent calls reuse the cache. If the model structure changes (e.g.
torch.compileor module swaps), callinvalidate_reset_cache()to clear the cache.
- spikingjelly.activation_based.functional.net_config.set_backend(net, backend, instance=None)[源代码]#
-
中文
将
net中所有满足isinstance(m, instance)且具有backend属性的模块后端设置为backend。仅当目标模块的
supported_backends包含给定backend时才会实际更新; 否则会记录告警并保留原有后端。若instance为None,则会检查所有具有backend属性的模块。- 参数:
- 抛出:
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 (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
- 抛出:
Exception -- Propagated if a target module raises while exposing
supported_backendsor assigningbackend
- spikingjelly.activation_based.functional.net_config.set_step_mode(net, step_mode)[源代码]#
-
中文
将
net中所有具有step_mode属性的模块的步进模式设置为step_mode。备注
StepModeContainer,ElementWiseRecurrentContainer,LinearRecurrentContainer的子模块(不包含包装器本身)的step_mode不会被改变。若某个模块具有
step_mode属性但不是StepModule,则该函数仍会尝试赋值, 同时记录告警。- 参数:
- 抛出:
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)
- 抛出:
ValueError -- Propagated if a module rejects the provided
step_modein its setter