spikingjelly.activation_based.op_counter package#

Base Classes and Context Managers#

class spikingjelly.activation_based.op_counter.base.ActiveModuleTracker[源代码]#

基类:ModuleTracker

API Language: 中文 | English


  • 中文

  • 中文

模块追踪器,用于在 PyTorch 的前向和反向传播过程中追踪模块的调用层次结构。 它通过在模块的前向和反向钩子上进行回调来记录当前活跃的模块 active_modules

active_modulesparents 的区别在于:前者是 nn.Module 的集合, 后者是 str (模块名)的集合。


  • English

  • English

Module tracker that tracks the module call hierarchy during PyTorch forward and backward passes. It records the currently executing module instances to active_modules through callbacks on module forward and backward hooks.

Attributes active_modules and parents are different: the former is a set of nn.Module instances, while the latter is a set of str (module names).

返回:

None

返回类型:

None

class spikingjelly.activation_based.op_counter.base.BaseCounter[源代码]#

基类:object

API Language: 中文 | English


  • 中文

  • 中文

操作计数器的基类。所有具体的计数器实现都继承自此类。

该基类提供了计数器的核心属性:

  • records: 存储计数记录,结构为 dict[scope][operation] = count

  • rules: 定义如何计算各个操作的计数的函数

  • ignore_modules: 需要忽略的模块列表,这些模块中的操作不会被计数

子类需要实现具体的规则 rules 来定义如何计算特定操作的计数。


  • English

  • English

Base class for operation counters. All concrete counter implementations inherit from this class.

This base class provides core attributes for counters:

  • records: stores count records, structured as dict[scope][operation] = count

  • rules: functions that define how to calculate counts for each operation

  • ignore_modules: list of modules to ignore. Operations within these modules will not be counted

Subclasses need to implement specific rule functions in rules to define how to calculate counts for particular operations.

返回:

None

返回类型:

None

has_rule(func) bool[源代码]#

API Language: 中文 | English


  • 中文

参数:

func (Any) -- 待判断的函数。其类型应与 rules 的键类型一致

返回:

func 是否有对应的计数规则

返回类型:

bool


  • English

参数:

func (Any) -- the function or operation to be checked. Its type should be the same as the keys in rules

返回:

whether func has a corresponding counting rule

返回类型:

bool

count(func, args: tuple, kwargs: dict, out, active_modules: set[Module] | None = None, parent_names: set[str] | None = None) int[源代码]#

API Language: 中文 | English


  • 中文

根据 rules ,计算一次函数或操作调用所产生的计数值。

参数:
  • func (Any) -- 待计算的函数或操作。其类型应与 rules 的键类型一致

  • args (tuple) -- func 的位置参数

  • kwargs (dict) -- func 的关键字参数

  • out (Any) -- func 输出

  • active_modules (Optional[set[nn.Module]]) -- 当前处于活跃状态的模块集合。大多数计数器可忽略该参数, 但需要结合模块上下文做语义统计的计数器可以使用它

  • parent_names (Optional[set[str]]) -- 当前活跃模块名称集合。大多数计数器可忽略该参数

返回:

计算得到的计数值

返回类型:

int


  • English

Calculate the count for a function or operation call according to rules.

参数:
  • func (Any) -- the function or operation to be calculated. Its type should be the same as the keys in rules

  • args (tuple) -- positional arguments of func

  • kwargs (dict) -- keyword arguments of func

  • out (Any) -- output of func

  • active_modules (Optional[set[nn.Module]]) -- currently active module instances. Most counters can ignore it, while context-aware counters may use it for semantic counting

  • parent_names (Optional[set[str]]) -- names of the currently active parent modules. Most counters can ignore it

返回:

the calculated count

返回类型:

int

record(scope, func, value)[源代码]#

API Language: 中文 | English


  • 中文

records 中添加记录。

参数:
  • scope (str) -- 模块作用域字符串,如 "SimpleNet.lif1"

  • func (Any) -- 待记录的函数或操作。其类型应与 rules 的键类型一致

  • value (int) -- 计数值


  • English

Record the calculated count to records.

参数:
  • scope (str) -- the module scope, e.g., "SimpleNet.lif1"

  • func (Any) -- the function or operation to be recorded. Its type should be the same as the keys in rules

  • value (int) -- the calculated count

get_counts() dict[str, dict[Any, int]][源代码]#

API Language: 中文 | English


  • 中文

返回:

所有计数记录 records

返回类型:

dict[str, dict[Any, int]]


  • English

返回:

all count records in records

返回类型:

dict[str, dict[Any, int]]

get_total() int[源代码]#

API Language: 中文 | English


  • 中文

返回:

顶层作用域 "Global" 下所有计数的总和。

返回类型:

int


  • English

返回:

the total count of all records in the "Global" scope.

返回类型:

int

reset()[源代码]#

API Language: 中文 | English


  • 中文

重置计数器,清空所有已记录的计数。

此方法会将 records 重新初始化为空的嵌套字典,移除之前累积的全部计数结果。 适用于开始新的计数会话之前显式清零计数器状态。

返回:

None

返回类型:

None


  • English

Reset the counter and clear all recorded counts.

This method reinitializes records to an empty nested dictionary, removing all previously accumulated count results. Call it before starting a new counting session when a counter instance is reused.

返回:

None

返回类型:

None

spikingjelly.activation_based.op_counter.base.is_binary_tensor(x: Tensor) bool[源代码]#

API Language: 中文 | English


  • 中文

判断输入张量 x 是否为二元张量(即所有元素都在 {0, 1} 中或 dtypebool)。

参数:

x (torch.Tensor) -- 输入张量

返回:

如果 x 是二元张量或 bool 张量则返回 True

返回类型:

bool


  • English

Check if the input tensor x is a binary tensor (all elements are in {0, 1} or its dtype is bool).

参数:

x (torch.Tensor) -- input tensor

返回:

True if x is a binary tensor or a bool tensor

返回类型:

bool

class spikingjelly.activation_based.op_counter.base.DispatchCounterMode(counters: list[BaseCounter], strict: bool = False, verbose: bool = False)[源代码]#

基类:TorchDispatchMode

API Language: 中文 | English


  • 中文

基于 PyTorch 的 Dispatch 机制的 上下文管理器 ,用于计算aten操作对应计数。

该类通过重写 __torch_dispatch__ 方法来捕捉所有 PyTorch aten 操作的调用,并使用注册的计数器 来统计这些操作的某些计数。

机制:

  1. 通过 ActiveModuleTracker 追踪当前执行所在的模块层级

  2. 对于每个被拦截的操作,检查是否有对应的计数规则

  3. 如果存在规则且不在被忽略的模块中,则调用规则函数计算计数值

  4. 将计数值记录到每一个父模块作用域中。

参数:
  • counters (list[BaseCounter]) -- 计数器列表

  • strict (bool) -- 如果为 True ,当遇到未定义规则的操作时会报错;否则,未定义的操作将被跳过。 默认为 False

  • verbose (bool) -- 如果为 True ,会在控制台打印每个被计数的操作及其计数值

返回:

上下文管理器对象

返回类型:

DispatchCounterMode


  • English

Context manager based on PyTorch's Dispatch mechanism for counting aten operations. It intercepts all PyTorch aten operations through overriding __torch_dispatch__ and uses registered counters to track these operations.

Working Mechanism:

  1. Tracks the current module hierarchy using ActiveModuleTracker

  2. For each intercepted operation, checks if there's a corresponding counting rule

  3. If a rule exists and the operation is not in an ignored module, calls the rule function to calculate the count

  4. Records the count to the parent module scope

参数:
  • counters (list[BaseCounter]) -- list of counters

  • strict (bool) -- if True, raises NotImplementedError when encountering operations without defined rules; if False, skip the operations without defined rules. Default to False.

  • verbose (bool) -- if True, prints each counted operation and its count to the console

返回:

Context manager object

返回类型:

DispatchCounterMode


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    FlopCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn


class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(100, 50)

    def forward(self, x):
        return self.linear(x)


model = SimpleNet()
x = torch.randn(32, 100)

# Initialize counter
flop_counter = FlopCounter()
with DispatchCounterMode([flop_counter], verbose=True):
    output = model(x)

# Get and print results
print("FLOP counts:", flop_counter.get_total())
class spikingjelly.activation_based.op_counter.base.FunctionCounterMode(counters: list[BaseCounter], strict: bool = False, verbose: bool = False)[源代码]#

基类:TorchFunctionMode

API Language: 中文 | English


  • 中文

基于 PyTorch Function 机制的 上下文管理器 ,用于计算函数的计数。

该类通过重写 __torch_function__ 方法来拦截所有 PyTorch 函数调用,并使用注册的计数器来统计这些 操作的某些计数。

工作原理与 DispatchCounterMode 类似。

参数:
  • counters (list[BaseCounter]) -- 计数器列表

  • strict (bool) -- 如果为 True,当遇到未定义规则的操作时会报错;否则,未定义的操作将被跳过。 默认为 False

  • verbose (bool) -- 如果为 True,会在控制台打印每个被计数的操作及其计数值

返回:

上下文管理器对象

返回类型:

FunctionCounterMode


  • English

Context manager based on PyTorch's Function mechanism for counting operations. It intercepts all PyTorch function calls through overriding __torch_function__ and uses registered counters to track these operations.

It has a similar working mechanism to DispatchCounterMode .

参数:
  • counters (list[BaseCounter]) -- list of counters

  • strict (bool) -- if True, raises NotImplementedError when encountering operations without defined rules; if False, skips operations without defined rules. Default to False

  • verbose (bool) -- if True, prints each counted operation and its count to the console

返回:

Context manager object

返回类型:

FunctionCounterMode

FLOP Counter#

class spikingjelly.activation_based.op_counter.flop.FlopCounter(extra_rules: dict[Any, Callable] = {}, extra_ignore_modules: list[Module] = [])[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

  • 中文

浮点运算次数(FLOPs)计数器。

该计数器统计前向与部分反向算子在算术层面的浮点运算数量,用于粗略估计计算开销。 具体构造参数见 __init__


  • English

  • English

Floating-point operation (FLOP) counter.

This counter tracks arithmetic FLOPs of forward operators and some backward operators as a coarse estimate of compute cost. See __init__ for constructor parameters.

API Language: 中文 | English


  • 中文

浮点运算计数器,用于计算深度神经网络中的浮点运算次数。

FLOP(Floating Point Operations) 是一个衡量计算复杂度的常用指标:

  • 1 次乘法 = 1 FLOP;1 次加法 = 1 FLOP;......

  • 逐元素操作的FLOP也会纳入考量。

FlopCounter 应与 DispatchCounterMode 搭配使用。

警告

目前,FlopCounter 支持的 aten 操作类型有限。查看源代码以获取操作列表。如需添加新操作, 可以使用 extra_rules 参数;也欢迎提交 pull request 来完善默认的 rules

参数:
  • extra_rules (dict[Any, Callable]) -- 额外的操作规则,格式为 {aten_op: func} , 其中 func 是一个函数,接受 (args, kwargs, out) 并返回计数值

  • extra_ignore_modules (list[torch.nn.Module]) -- 额外需要忽略的模块列表,这些模块中的操作不会被计数


  • English

FLOP counter for calculating the number of floating-point operations in deep networks.

FLOP (Floating Point Operations) is a common metric for measuring computational complexity:

  • 1 multiplication = 1 FLOP; 1 addition = 1 FLOP; ......

  • Element-wise operations are also considered.

FlopCounter should be used with DispatchCounterMode .

警告

Currently, FlopCounter supports a limited number of aten operations. See the source code for the operation list. If you want to add new operations, use the extra_rules parameter. Welcome to submit a pull request to improve the default rules !

参数:
  • extra_rules (dict[Any, Callable]) -- additional operation rules, format as {aten_op: func}, where func is a function that takes (args, kwargs, out) and returns the count value

  • extra_ignore_modules (list[torch.nn.Module]) -- additional list of modules to ignore. Operations within these modules will not be counted


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    FlopCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn

model = nn.Sequential(nn.Linear(100, 50), nn.ReLU(), nn.Linear(50, 10))
x = torch.randn(32, 100)

flop_counter = FlopCounter()

with DispatchCounterMode([flop_counter]):
    output = model(x)

# Get FLOP counts
total_flops = flop_counter.get_total()
print(f"Total FLOPs: {total_flops}")
返回:

None

返回类型:

None

Memory Access Counter#

class spikingjelly.activation_based.op_counter.memory_access.MemoryAccessCounter(extra_rules: dict[Any, Callable] = {}, extra_ignore_modules: list[Module] = [])[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

  • 中文

内存访问量估计计数器。

该计数器以输入/输出张量的字节数为基础,估计算子的内存访问下界, 适合用于粗略分析不同网络结构的访存压力。具体构造参数见 __init__


  • English

  • English

Memory-access estimation counter.

The counter estimates a lower bound of operator memory access from the byte size of input and output tensors, which is useful for coarse-grained memory traffic analysis across network structures. See __init__ for constructor parameters.

API Language: 中文 | English


  • 中文

内存访问计数器,用于粗略估计深度神经网络的内存访问量。

该计数器统计操作所需的输入、输出张量的 字节 数,作为对内存访问量的 下界估计 。真实的内存访问量由算子的load store模式决定,取决于具体实现,在此不做考虑。

MemoryAccessCounter 应与 DispatchCounterMode 搭配使用。

警告

目前,MemoryAccessCounter 支持的 aten 操作类型有限。查看源代码以获取操作列表。如需添加新操作, 可以使用 extra_rules 参数;也欢迎提交 pull request 来完善默认的 rules

参数:
  • extra_rules (dict[Any, Callable]) -- 额外的操作规则,格式为 {aten_op, func}, 其中 func 是一个函数,接受 (args, kwargs, out) 并返回字节数

  • extra_ignore_modules (list[nn.Module]) -- 额外需要忽略的模块列表,这些模块中的操作不会被计数


  • English

Memory access counter for estimating memory access in deep networks.

This counter tracks the byte count of input and output tensors for operations as a lower bound estimate of memory access. Actual amount of memory access depends on the load store patterns of specific implementations, so it is not considered here.

MemoryAccessCounter should be used with DispatchCounterMode.

警告

Currently, MemoryAccessCounter supports a limited number of aten operations. See the source code for the list of operations. If you want to add a new operation, you can use the extra_rules parameter. Welcome to submit a pull request to improve the default rules!

参数:
  • extra_rules (dict[Any, Callable]) -- additional operation rules, format as {aten_op: func}, where func is a function that takes (args, kwargs, out) and returns byte count

  • extra_ignore_modules (list[nn.Module]) -- additional list of modules to ignore. Operations within these modules will not be counted


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    MemoryAccessCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn

model = nn.Sequential(nn.Linear(100, 50), nn.ReLU(), nn.Linear(50, 10))
x = torch.randn(32, 100)

memory_counter = MemoryAccessCounter()

with DispatchCounterMode([memory_counter]):
    output = model(x)

total_bytes = memory_counter.get_total()
print(f"Total memory access: {total_bytes / 1024:.2f} KB")
返回:

None

返回类型:

None

MAC / AC / SynOp Counters#

class spikingjelly.activation_based.op_counter.mac.MACCounter(extra_rules: dict[Any, Callable] = {}, extra_ignore_modules: list[Module] = [])[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

  • 中文

硬件级乘累加(MAC)计数器。

该计数器统计网络中的 MAC 操作次数,并与 ACCounter 形成互补视角,用于近似刻画硬件上的乘累加开销。具体构造参数见 __init__


  • English

  • English

Hardware-level multiply-accumulate (MAC) counter.

This counter tracks MAC operations in a network and complements ACCounter for approximate hardware-oriented compute analysis. See __init__ for constructor parameters.

API Language: 中文 | English


  • 中文

硬件级乘累加(Multiply-Accumulate,MAC)操作计数器,统计网络中所有 MAC 操作次数。

MAC 乘法结果立即累加到累加器(如矩阵内积),而非写入新的内存位置。MAC与AC互斥:若一个计算步骤 计入 MAC,则不会计入 AC;反之亦然。

MACCounter 应与 DispatchCounterMode 搭配使用。

警告

MACCounter 只能统计前向传播期间的 MAC 数量。部分专用于反向传播的算子还未覆盖。

目前,MACCounter 支持的 aten 操作类型有限。查看源代码以获取操作列表。如需添加新操作, 可以使用 extra_rules 参数;也欢迎提交 pull request 来完善默认的 rules

警告

MACCounter 会如实考虑 BN 内部的 MAC 操作。如果想在推理时忽略 BN 内部的 MAC,请将 BN 融合到线性层中;或者使用 extra_ignore_modules 参数将 BN 模块加入忽略列表。

参数:
  • extra_rules (dict[Any, Callable]) -- 额外的操作规则,格式为 {aten_op: func}, 其中 func 是一个函数,接受 (args, kwargs, out) 并返回 MAC 次数

  • extra_ignore_modules (list[torch.nn.Module]) -- 额外需要忽略的模块列表,这些模块中的操作不会被计数


  • English

Hardware-level Multiply-Accumulate (MAC) operation counter that counts all MAC operations in a network.

MAC's multiply result is immediately accumulated into a running accumulator (not written to a new memory location). MACCounter is mutually exclusive with ACCounter : if a computation step is counted as MAC, it will not be counted as AC, and vice versa.

警告

MACCounter can only count MACs during the forward pass. Some operators dedicated to backward pass are not yet covered.

Currently, MACCounter supports a limited number of aten operations. See the source code for the operation list. If you want to add new operations, use the extra_rules parameter. Welcome to submit a pull request to improve the default rules!

参数:
  • extra_rules (dict[Any, Callable]) -- additional operation rules, format as {aten_op: func}, where func is a function that takes (args, kwargs, out) and returns the MAC count

  • extra_ignore_modules (list[torch.nn.Module]) -- additional list of modules to ignore. Operations within these modules will not be counted


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    MACCounter,
    ACCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn

model = nn.Sequential(nn.Linear(100, 50), nn.ReLU(), nn.Linear(50, 10))
x = (torch.randn(32, 100) < 0.1).float()  # sparse binary input

mac_counter = MACCounter()
with DispatchCounterMode([mac_counter]):
    output = model(x)

print(f"Total MACs: {mac_counter.get_total()}")  # only the 2nd layer counts
返回:

None

返回类型:

None

class spikingjelly.activation_based.op_counter.ac.ACCounter(extra_rules: dict[Any, Callable] = {}, extra_ignore_modules: list[Module] = [])[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

硬件级累加(Accumulate,AC)操作计数器,从硬件视角统计网络中的纯加法次数。

SynOpCounter 的区别: SynOpCounter 只关注脉冲驱动的矩阵乘法和卷积; ACCounter 还会统计 BN、add/sub 等算子内部的加法,范围更广但语义更宽泛。 例如,SEW ResNet 中残差连接处的加法操作将被计入 AC。

ACCounter 应与 DispatchCounterMode 搭配使用。

警告

ACCounter 只能统计前向传播期间的 AC 数量。部分专用于反向传播的算子还未覆盖。

目前,ACCounter 支持的 aten 操作类型有限。查看源代码以获取操作列表。如需添加新操作, 可以使用 extra_rules 参数;也欢迎提交 pull request 来完善默认的 rules

警告

ACCounter 会如实考虑 BN 内部的 AC 操作。如果想在推理时忽略 BN 内部的 AC,请将 BN 融合到线性层中;或者使用 extra_ignore_modules 参数将 BN 模块加入忽略列表。

参数:
  • extra_rules (dict[Any, Callable]) -- 额外的操作规则,格式为 {aten_op: func}, 其中 func 是一个函数,接受 (args, kwargs, out) 并返回 AC 次数

  • extra_ignore_modules (list[torch.nn.Module]) -- 额外需要忽略的模块列表


  • English

Hardware-level Accumulate (AC) operation counter that counts pure additions in a network from a hardware perspective.

Compared with SynOpCounter: SynOpCounter only covers spike-driven matmul and conv; ACCounter also covers BN, add/sub, etc., thus is broader but more semantically general.

ACCounter should be used with DispatchCounterMode.

警告

ACCounter can only count ACs during the forward pass. Some operators dedicated to backward pass are not yet covered.

Currently, ACCounter supports a limited number of aten operations. See the source code for the operation list. If you want to add new operations, use the extra_rules parameter. Welcome to submit a pull request to improve the default rules!

警告

ACCounter counts AC operations inside BN. To ignore AC inside BN during inference, please fuse BN into linear/conv layers; or use the extra_ignore_modules parameter to add BN modules to the ignore list.

参数:
  • extra_rules (dict[Any, Callable]) -- additional operation rules, format as {aten_op: func}, where func is a function that takes (args, kwargs, out) and returns the AC count

  • extra_ignore_modules (list[torch.nn.Module]) -- additional list of modules to ignore


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    ACCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn

model = nn.Sequential(nn.Linear(100, 50), nn.ReLU(), nn.Linear(50, 10))
spike = (torch.rand(32, 100) < 0.1).float()  # sparse binary input

ac_counter = ACCounter()
with DispatchCounterMode([ac_counter]):
    model(spike)

print(f"Total ACs: {ac_counter.get_total()}")  # only the 1st layer counts
返回:

None

返回类型:

None

class spikingjelly.activation_based.op_counter.synop.SynOpCounter(extra_rules: dict[Any, Callable] = {}, extra_ignore_modules: list[Module] = [])[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

突触操作(Synaptic Operations,SynOps)计数器,用于统计 SNN 中由 spike 驱动的突触权重累加次数。

ACCounter 的区别: ACCounter 除了权重层线性操作外,还会统计 BN、add/sub 等算子内部的加法; SynOpCounter 只关注脉冲驱动的矩阵乘法和卷积,范围更窄但语义更直接。 例如,SEW ResNet 中残差连接处的加法操作将不会被计入 SynOps。

SynOpCounter 应与 DispatchCounterMode 搭配使用。

警告

SynOpCounter 只能统计前向传播期间的突触操作数量。部分专用于反向传播的算子还未覆盖。

目前,SynOpCounter 支持的 aten 操作类型有限(mm、addmm、bmm、baddbmm、convolution)。 如需添加新操作,可以使用 extra_rules 参数;也欢迎提交 pull request 来完善默认的 rules

参数:
  • extra_rules (dict[Any, Callable]) -- 额外的操作规则,格式为 {aten_op: func}, 其中 func 是一个函数,接受 (args, kwargs, out) 并返回 SynOps 次数

  • extra_ignore_modules (list[torch.nn.Module]) -- 额外需要忽略的模块列表,这些模块中的操作不会被计数


  • English

Synaptic Operations (SynOps) counter that tracks spike-driven weight accumulations in SNNs.

Compared with ACCounter: ACCounter also covers BN internals, add/sub, ... SynOpCounter is narrower: only spike-driven matmul and conv are considered. This makes it more directly aligned with the intuitive concept of "synaptic operations" in neuromorphic computing.

SynOpCounter should be used with DispatchCounterMode.

警告

SynOpCounter can only count SynOps during the forward pass. Some operators dedicated to backward pass are not yet covered.

Currently, SynOpCounter supports mm, addmm, bmm, baddbmm, and convolution. If you want to add new operations, use the extra_rules parameter. Welcome to submit a pull request to improve the default rules!

参数:
  • extra_rules (dict[Any, Callable]) -- additional operation rules, format as {aten_op: func}, where func is a function that takes (args, kwargs, out) and returns the SynOps count

  • extra_ignore_modules (list[torch.nn.Module]) -- additional list of modules to ignore. Operations within these modules will not be counted


  • 代码示例 | Example

from spikingjelly.activation_based.op_counter import (
    SynOpCounter,
    DispatchCounterMode,
)
import torch
import torch.nn as nn

model = nn.Linear(10, 5, bias=False)
spike = (torch.rand(4, 10) < 0.2).float()

counter = SynOpCounter()
with DispatchCounterMode([counter]):
    model(spike)

print(f"SynOp count: {counter.get_total()}")
返回:

None

返回类型:

None

Compute-Only Energy Estimator#

class spikingjelly.activation_based.op_counter.compute_energy.ComputeEnergyCostConfig(e_mac_pj: float = 4.6, e_ac_pj: float = 0.9)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

仅计算 MAC/AC 的 compute-only 能耗模型成本配置。

默认值采用 SNN 文献中常见的 Horowitz 2014 口径:45nm、32-bit 浮点 E_MAC = 4.6 pJE_AC = 0.9 pJ

这是一个 cost-table-driven 的归一化模型。默认不会自动根据运行时 dtype 推断成本;如需切换口径,请显式使用 fp32(), fp16(), int8() 等 preset。


  • English

Cost configuration for the compute-only MAC/AC energy model.

Defaults follow the widely used Horowitz 2014 reference costs for 45nm, 32-bit floating-point arithmetic: E_MAC = 4.6 pJ and E_AC = 0.9 pJ.

This is a normalized, cost-table-driven model. It does not automatically infer energy costs from runtime dtype; use explicit presets such as fp32(), fp16(), or int8() when a different comparison regime is desired.

e_mac_pj: float = 4.6#
e_ac_pj: float = 0.9#
classmethod fp32() ComputeEnergyCostConfig[源代码]#

Return the Horowitz 2014 45nm FP32 preset.

classmethod fp16() ComputeEnergyCostConfig[源代码]#

Return the Horowitz 2014 45nm FP16 preset.

Uses FMult16 = 1.1 pJ and FAdd16 = 0.4 pJ, so E_MAC = 1.5 pJ and E_AC = 0.4 pJ.

classmethod int8() ComputeEnergyCostConfig[源代码]#

Return the Horowitz 2014 45nm INT8 preset.

Uses Mult8 = 0.2 pJ and Add8 = 0.03 pJ, so E_MAC = 0.23 pJ and E_AC = 0.03 pJ.

class spikingjelly.activation_based.op_counter.compute_energy.ComputeEnergyConfig(strict: bool = False, verbose: bool = False, cost_config: ~spikingjelly.activation_based.op_counter.compute_energy.ComputeEnergyCostConfig = <factory>, extra_ignore_modules: list[type[~torch.nn.modules.module.Module]] | None = None)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

控制 compute-only MAC/AC 能耗分析器行为的配置。

默认 cost_config 使用 ComputeEnergyCostConfig.fp32() 对应的口径。


  • English

Configuration for the compute-only MAC/AC energy profiler.

The default cost_config matches ComputeEnergyCostConfig.fp32(). strict only applies to profiler-level validation added by this wrapper. The internal DispatchCounterMode is intentionally kept non-strict because it composes multiple specialized counters with non-identical rule coverage.

strict: bool = False#
verbose: bool = False#
cost_config: ComputeEnergyCostConfig#
extra_ignore_modules: list[type[Module]] | None = None#
class spikingjelly.activation_based.op_counter.compute_energy.ComputeEnergyProfiler(*, config: ComputeEnergyConfig | None = None)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

  • 中文

基于 public counter 组装的 compute-only MAC/AC 能耗分析器。

用法与其他能耗分析器一致:以 context manager 方式包住一次真实前向传播, 然后调用 get_report()


  • English

  • English

Compute-only MAC/AC energy profiler composed from public counters.

Use it like the other energy profilers: wrap one real forward pass in the context manager and call get_report() afterwards.

参数:
  • config (ComputeEnergyConfig | None) -- 能耗配置,若为 None 则使用默认配置

  • config -- Energy configuration. If None, uses the default configuration

返回:

None

返回类型:

None

get_report() ComputeEnergyReport[源代码]#
get_total() float[源代码]#
get_counts() dict[str, int][源代码]#
class spikingjelly.activation_based.op_counter.compute_energy.ComputeEnergyReport(energy_total_pj: float, energy_mac_pj: float, energy_ac_pj: float, breakdown_pj: dict[str, float], counts: dict[str, int], warnings: list[str])[源代码]#

基类:object

API Language: 中文 | English


  • 中文

compute-only MAC/AC 能耗报告。

该模型只考虑计算能耗,不包含访存、寻址、状态驻留等开销。主结果 energy_total_pjMACAC 两部分组成。

SynOpsFLOPs 作为辅助统计返回,便于与现有 SNN/ANN 文献对齐, 但不参与主能耗计算。

该估计器面向“统一比较口径”,而不是对真实 kernel、混合精度累加路径或 特定硬件微架构做精确建模。


  • English

Report for the compute-only MAC/AC energy model.

This model only accounts for arithmetic compute energy, excluding memory, addressing, and state residency costs. The main result energy_total_pj consists of MAC and AC contributions only.

SynOps and FLOPs are returned as auxiliary counts for alignment with existing SNN/ANN literature, but they do not contribute to the primary energy estimate.

The estimator is intended as a normalized comparison regime rather than an exact model of real kernels, mixed-precision accumulation paths, or a specific hardware microarchitecture.

energy_total_pj: float#
energy_mac_pj: float#
energy_ac_pj: float#
breakdown_pj: dict[str, float]#
counts: dict[str, int]#
warnings: list[str]#
spikingjelly.activation_based.op_counter.compute_energy.estimate_compute_energy(model: Module, inputs, *, config: ComputeEnergyConfig | None = None) ComputeEnergyReport[源代码]#

API Language: 中文 | English


  • 中文

compute-only MAC/AC 能耗估计的便捷入口。该函数执行一次真实前向传播, 并返回总能耗与 MAC/AC 计数。

默认使用 Horowitz 2014 的 FP32 成本口径;若需要 FP16 或 INT8 比较, 请显式传入对应 preset。

参数:
  • model -- 待统计模型

  • inputs -- 模型输入;若为 tuple/list 则按 model(*inputs) 调用

  • config -- compute-only 能耗配置


  • English

Convenience entry for compute-only MAC/AC energy estimation. It runs one real forward pass and returns the energy report.

The default comparison regime is Horowitz 2014 FP32. For FP16 or INT8 comparisons, pass an explicit preset cost configuration.

参数:
  • model -- model to profile

  • inputs -- model input; tuple/list will be passed as model(*inputs)

  • config -- compute-only energy configuration

NeuroMC Energy Profiler#

class spikingjelly.activation_based.op_counter.neuromc.core.MemoryHierarchyConfig(preset_name: str = 'neuromc_like_v1', technology_nm: int = 32, level_order: tuple[str, str, str, str] = ('dram', 'sram', 'reg', 'noc'), memory_instances: dict[str, ~spikingjelly.activation_based.op_counter.neuromc.config.MemoryInstanceSpec] = <factory>, zero_dram_in_paper_energy: bool = True, zero_noc_in_paper_energy: bool = True, zero_sram_high_directions: bool = True)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

NeuroMC v1 硬件预设配置类。

参数:
  • preset_name (str) -- 预设名称

  • technology_nm -- 工艺节点(纳米)


  • English

MemoryHierarchyConfig class

返回:

None

返回类型:

None

copy()[源代码]#
level_order: tuple[str, str, str, str] = ('dram', 'sram', 'reg', 'noc')#
classmethod neuromc_like_v1(memory_model: str | None = None)[源代码]#
preset_name: str = 'neuromc_like_v1'#
technology_nm: int = 32#
validate()[源代码]#
zero_dram_in_paper_energy: bool = True#
zero_noc_in_paper_energy: bool = True#
zero_sram_high_directions: bool = True#
memory_instances: dict[str, MemoryInstanceSpec]#
class spikingjelly.activation_based.op_counter.neuromc.core.NeuroMCEnergyProfiler(*, core_type: str = 'fp_soma', memory_config: MemoryHierarchyConfig | None = None, strict: bool = False, verbose: bool = False, extra_ignore_modules: list[Module] | None = None)[源代码]#

基类:object

High-level energy profiler for spiking neural networks using the NeuroMC framework. API Language: 中文 | English


  • 中文

NeuroMC能耗分析器

返回类型:

None

Profiles the energy consumption of a model by tracking operation counts and memory access patterns across forward, backward, and optimizer stages.


  • English

NeuroMC energy profiler

返回:

None

返回类型:

None

参数:
  • core_type (str) -- Type of compute core (e.g., "fp_soma")

  • memory_config (MemoryHierarchyConfig | None) -- Memory hierarchy configuration. If None, uses the default neuromc_like_v1 config

  • strict (bool) -- If True, raise on unknown operations instead of warning

  • verbose (bool) -- If True, print progress information during profiling

  • extra_ignore_modules (list[nn.Module] | None) -- Additional module types to ignore during counting

抛出:

ValueError -- If core_type is not in the supported set

返回:

None

返回类型:

None

bind_model(model: Module)[源代码]#
bind_optimizer(optimizer: Optimizer | None)[源代码]#
stage(name: str)[源代码]#
suspend()[源代码]#
get_report() NeuroMCRuntimeEnergyReport[源代码]#
get_total() float[源代码]#
get_counts() dict[str, Any][源代码]#
record_optimizer_step(stage: str = 'optimizer') None[源代码]#
class spikingjelly.activation_based.op_counter.neuromc.core.NeuroMCRuntimeEnergyReport(energy_total_pj: float = 0.0, energy_compute_pj: float = 0.0, energy_memory_pj: float = 0.0, energy_by_stage: dict[str, float] | None = None, energy_by_op: dict[str, float] | None = None, primitive_counts: dict[str, Any] | None = None, memory_bits_by_level: dict[str, Any] | None = None, warnings: list[str] | None = None, energy_mac_pj: float = 0.0, energy_base_memory_pj: float = 0.0, energy_extra_memory_pj: float = 0.0, energy_extra_compute_pj: float = 0.0, energy_by_core_type: dict[str, float] | None = None, energy_by_process_key: dict[str, float] | None = None, energy_by_memory_level_dir: dict[str, dict[str, float]] | None = None, counts_by_core_type: dict[str, dict[str, int]] | None = None, counts_by_process_key: dict[str, dict[str, int]] | None = None, mapping_summary: list[dict[str, Any]] | None = None)[源代码]#

基类:object

Energy profiling report generated by the NeuroMC framework. API Language: 中文 | English


  • 中文

NeuroMC 运行时能耗报告数据类。

记录一次能耗分析会话的完整结果,包括总能耗、计算能耗、内存能耗、 各阶段能耗分解、各算子类型的能耗分布以及内存访问位宽等详细信息。 可通过 summary() 方法获取 关键指标的字符串摘要,便于快速查看分析结果。

参数:
  • energy_total_pj (float) -- Total energy consumption in picojoules

  • energy_compute_pj (float) -- Total compute energy in picojoules

  • energy_memory_pj (float) -- Total memory access energy in picojoules

  • energy_by_stage (dict[str, float]) -- Energy breakdown by execution stage

  • energy_by_op (dict[str, float]) -- Energy breakdown by operation type

  • primitive_counts (dict[str, Any]) -- Raw primitive operation counts

  • memory_bits_by_level (dict[str, Any]) -- Memory access bits by hierarchy level

  • warnings (list[str]) -- List of warnings generated during profiling

  • energy_mac_pj (float) -- Energy of MAC operations in picojoules

  • energy_base_memory_pj (float) -- Base memory energy in picojoules

  • energy_extra_memory_pj (float) -- Extra memory energy in picojoules

  • energy_extra_compute_pj (float) -- Extra compute energy in picojoules

返回类型:

None

Contains detailed breakdown of compute and memory energy consumption across different stages, operations, and memory hierarchy levels.


  • English

Neuromcruntimeenergyreport function

参数:
  • energy_total_pj (float) -- Total energy consumption in picojoules

  • energy_compute_pj (float) -- Total compute energy in picojoules

  • energy_memory_pj (float) -- Total memory access energy in picojoules

  • energy_by_stage (dict[str, float]) -- Energy breakdown by execution stage

  • energy_by_op (dict[str, float]) -- Energy breakdown by operation type

  • primitive_counts (dict[str, Any]) -- Raw primitive operation counts

  • memory_bits_by_level (dict[str, Any]) -- Memory access bits by hierarchy level

  • warnings (list[str]) -- List of warnings generated during profiling

  • energy_mac_pj (float) -- Energy of MAC operations in picojoules

  • energy_base_memory_pj (float) -- Base memory energy in picojoules

  • energy_extra_memory_pj (float) -- Extra memory energy in picojoules

  • energy_extra_compute_pj (float) -- Extra compute energy in picojoules

返回:

None

返回类型:

None

energy_total_pj: float = 0.0#
energy_compute_pj: float = 0.0#
energy_memory_pj: float = 0.0#
energy_by_stage: dict[str, float]#
energy_by_op: dict[str, float]#
primitive_counts: dict[str, Any]#
memory_bits_by_level: dict[str, Any]#
warnings: list[str]#
energy_mac_pj: float = 0.0#
energy_base_memory_pj: float = 0.0#
energy_extra_memory_pj: float = 0.0#
energy_extra_compute_pj: float = 0.0#
energy_by_core_type: dict[str, float]#
energy_by_process_key: dict[str, float]#
energy_by_memory_level_dir: dict[str, dict[str, float]]#
counts_by_core_type: dict[str, dict[str, int]]#
counts_by_process_key: dict[str, dict[str, int]]#
mapping_summary: list[dict[str, Any]]#
spikingjelly.activation_based.op_counter.neuromc.core.estimate_neuromc_runtime_energy(model: Module, inputs, *, target: Tensor | None = None, loss_fn: Callable | None = None, optimizer: Optimizer | None = None, core_type: str = 'fp_soma', op_cost_pj: dict[str, float] | None = None, memory_cost_pj_per_bit: dict[str, float] | None = None, memory_level_weights: dict[str, float] | None = None, memory_model: str | None = None, memory_config: MemoryHierarchyConfig | None = None, strict: bool = False, verbose: bool = False, extra_ignore_modules: list[Module] | None = None) NeuroMCRuntimeEnergyReport[源代码]#

API Language: 中文 | English


  • 中文

estimate neuromc runtime energy 函数

参数:
  • model (nn.Module) -- The PyTorch model to profile

  • inputs (Any) -- Input tensors for the forward pass

  • target (torch.Tensor | None) -- Target tensors for loss computation

  • loss_fn (Callable | None) -- Loss function for the backward pass

  • optimizer (torch.optim.Optimizer | None) -- Optimizer for training-stage profiling

  • core_type (str) -- Type of compute core (e.g., \"fp_soma\")

  • op_cost_pj (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_cost_pj_per_bit (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_level_weights (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_model (str | None) -- (Deprecated) Ignored

  • memory_config (MemoryHierarchyConfig | None) -- Memory hierarchy configuration. If None, uses the default config

  • strict (bool) -- If True, raise on unknown operations instead of warning

  • verbose (bool) -- If True, print progress information during profiling

  • extra_ignore_modules (list[nn.Module] | None) -- Additional module types to ignore during counting

返回:

Energy profiling report

返回类型:

NeuroMCRuntimeEnergyReport

This is a convenience function that creates a NeuroMCEnergyProfiler, binds the model and optional optimizer, runs the full profile, and returns the energy report.


  • English

Estimate Neuromc Runtime Energy function

参数:
  • model (nn.Module) -- The PyTorch model to profile

  • inputs (Any) -- Input tensors for the forward pass

  • target (torch.Tensor | None) -- Target tensors for loss computation

  • loss_fn (Callable | None) -- Loss function for the backward pass

  • optimizer (torch.optim.Optimizer | None) -- Optimizer for training-stage profiling

  • core_type (str) -- Type of compute core (e.g., \"fp_soma\")

  • op_cost_pj (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_cost_pj_per_bit (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_level_weights (dict[str, float] | None) -- (Deprecated) Ignored

  • memory_model (str | None) -- (Deprecated) Ignored

  • memory_config (MemoryHierarchyConfig | None) -- Memory hierarchy configuration. If None, uses the default config

  • strict (bool) -- If True, raise on unknown operations instead of warning

  • verbose (bool) -- If True, print progress information during profiling

  • extra_ignore_modules (list[nn.Module] | None) -- Additional module types to ignore during counting

返回:

Energy profiling report

返回类型:

NeuroMCRuntimeEnergyReport

SpikeSim Event-Driven Energy Profiler#

API Language: 中文 | English


  • 中文

SpikeSim能耗分析模块,基于脉冲驱动的计算成本建模。

return:

None

rtype:

None


  • English

SpikeSim energy profiling module for spike-driven computation cost modeling.

return:

None

rtype:

None

class spikingjelly.activation_based.op_counter.spikesim.SpikeSimEnergyConfig(xbar_size: int = 64, device: str = 'rram', activity_mode: str = 'dense', require_if_lif_neurons: bool = True, tile_buffer_pj: float = 397.0, temp_buffer_pj: float = 0.2, sub_pj: float = 1.15e-06, adc_pj: float = 2.03084, htree_pj: float = 157.12, mux_pj: float = 0.094245, mem_fetch_pj: float = 4.64, neuron_pj: float = 5.096, rram_xbar_pj: float = 1.76423, sram_xbar_pj: float = 671.089)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

SpikeSim 事件驱动能耗估计器的运行时能耗配置。

默认系数有意与已发布的 ela_spikesim.py 能耗路径保持一致, 但计数逻辑已替换为基于运行时事件的分析。


  • English

Runtime energy configuration for the event-driven SpikeSim estimator.

The default coefficients intentionally match the released ela_spikesim.py energy path, while the counting logic is replaced by runtime event analysis.

activity_mode: str = 'dense'#
adc_pj: float = 2.03084#
copy() SpikeSimEnergyConfig[源代码]#

API Language: 中文 | English


  • 中文

复制当前配置并返回新对象。

返回:

当前配置的副本

返回类型:

SpikeSimEnergyConfig


  • English

Return a copied config object.

返回:

a copy of the current config

返回类型:

SpikeSimEnergyConfig

device: str = 'rram'#
htree_pj: float = 157.12#
mem_fetch_pj: float = 4.64#
mux_pj: float = 0.094245#
neuron_pj: float = 5.096#
property patch_control_energy_pj: float#
pe_cycle_energy_for_kernel_pj(kernel_size: tuple[int, int]) float[源代码]#
require_if_lif_neurons: bool = True#
rram_xbar_pj: float = 1.76423#
sram_xbar_pj: float = 671.089#
sub_pj: float = 1.15e-06#
temp_buffer_pj: float = 0.2#
tile_buffer_pj: float = 397.0#
validate() None[源代码]#

API Language: 中文 | English


  • 中文

校验配置是否合法; 不合法时抛出 ValueError


  • English

Validate the config and raise ValueError on invalid values.

property xbar_array_energy_pj: float#
xbar_row_energy_pj(tile_channels: int) float[源代码]#
xbar_size: int = 64#
class spikingjelly.activation_based.op_counter.spikesim.SpikeSimCounter(*, config: SpikeSimEnergyConfig, strict: bool, verbose: bool)[源代码]#

基类:BaseCounter

API Language: 中文 | English


  • 中文

SpikeSim 计数器,用于在 spike 驱动的模拟中统计计算成本。

参数:
返回:

None

返回类型:

None


  • English

SpikeSim counter for profiling computation costs in spike-driven simulations.

参数:
  • config (SpikeSimEnergyConfig) -- SpikeSim energy configuration

  • strict (bool) -- Whether to use strict mode

  • verbose (bool) -- Whether to produce verbose output

返回:

None

返回类型:

None

count(func, args: tuple, kwargs: dict, out, active_modules=None, parent_names=None) int[源代码]#

API Language: 中文 | English


  • 中文

统计单次前向传播的计算成本。

参数:
  • func (Callable) -- 待统计的算子

  • args (tuple) -- 位置参数

  • kwargs (dict) -- 关键字参数

  • out -- 算子输出

  • active_modules -- 活跃模块列表

  • parent_names -- 父节点名称列表

返回:

计算成本

返回类型:

int

抛出:

NotImplementedError -- 若未注册的算子遇到则抛出


  • English

Count the computation cost of a single forward propagation.

参数:
  • func (Callable) -- The operator to count

  • args (tuple) -- Positional arguments

  • kwargs (dict) -- Keyword arguments

  • out -- Output of the operator

  • active_modules -- List of active modules

  • parent_names -- List of parent node names

返回:

computation cost

返回类型:

int

抛出:

NotImplementedError -- Raised when encountering an unregistered operator

get_stage_metadata() dict[str, dict[str, Any]][源代码]#
get_stage_stats() dict[str, dict[str, Any]][源代码]#
has_rule(func) bool[源代码]#
class spikingjelly.activation_based.op_counter.spikesim.SpikeSimEnergyProfiler(*, config: SpikeSimEnergyConfig | None = None, strict: bool = False, verbose: bool = False)[源代码]#

基类:object

API Language: 中文 | English


  • 中文

Runtime SpikeSim-aligned energy profiler.

使用方式:

  • 以 context manager 方式包住一次真实前向传播

  • 结束后调用 get_report() 获取能耗报告


  • English

Runtime SpikeSim-aligned energy profiler.

Usage:

  • wrap one real forward pass in the profiler context

  • call get_report() afterwards to build the energy report

API Language: 中文 | English


  • 中文

参数:
  • config -- SpikeSim 能耗配置;默认使用 SpikeSimEnergyConfig()

  • strict -- 是否在 unsupported 情况下直接抛异常

  • verbose -- 是否打印逐 stage 的运行时统计信息


  • English

参数:
  • config -- SpikeSim energy config; defaults to SpikeSimEnergyConfig()

  • strict -- whether to raise immediately on unsupported behaviors

  • verbose -- whether to print per-stage runtime statistics

返回:

None

返回类型:

None

add_warnings(messages: list[str]) None[源代码]#
get_counts() dict[str, Any][源代码]#

API Language: 中文 | English


  • 中文

返回统计量与 stage 元数据,便于和计数接口对齐。


  • English

Return event stats and stage metadata in an op_counter-like count shape.

get_report() SpikeSimEnergyReport[源代码]#

API Language: 中文 | English


  • 中文

生成并返回完整的 SpikeSim runtime 能耗报告。


  • English

Build and return the full runtime SpikeSim energy report.

get_total() float[源代码]#

API Language: 中文 | English


  • 中文

返回总能耗(pJ)。


  • English

Return total energy in pJ.

class spikingjelly.activation_based.op_counter.spikesim.SpikeSimEnergyReport(energy_total_pj: float, energy_by_stage: dict[str, float], energy_by_component: dict[str, Any], event_stats_by_stage: dict[str, dict[str, Any]], stage_metadata: dict[str, dict[str, Any]], warnings: list[str], breakdown_pj: dict[str, float], counts: dict[str, int])[源代码]#

基类:object

API Language: 中文 | English


  • 中文

SpikeSim 运行时能耗估计器的报告, 支持 denseevent 两种 activity mode。

字段包括总能耗、stage 分解、统计量、stage 元数据和 warning。 event_stats_by_stage 在两种 mode 下都会填充。


  • English

Report for the SpikeSim runtime energy estimator, supporting both dense and event activity modes.

Fields include total energy, stage-wise energy breakdown, event stats, stage metadata, and warnings. event_stats_by_stage is populated regardless of the selected activity mode.

energy_total_pj: float#
energy_by_stage: dict[str, float]#
energy_by_component: dict[str, Any]#
event_stats_by_stage: dict[str, dict[str, Any]]#
stage_metadata: dict[str, dict[str, Any]]#
warnings: list[str]#
breakdown_pj: dict[str, float]#
counts: dict[str, int]#
spikingjelly.activation_based.op_counter.spikesim.SpikeSimEventEnergyProfiler#

SpikeSimEnergyProfiler 的别名

spikingjelly.activation_based.op_counter.spikesim.SpikeSimEventEnergyReport#

SpikeSimEnergyReport 的别名

spikingjelly.activation_based.op_counter.spikesim.estimate_spikesim_event_energy(model: Module, inputs, *, config: SpikeSimEnergyConfig | None = None, strict: bool = False, verbose: bool = False) SpikeSimEnergyReport[源代码]#

API Language: 中文 | English


  • 中文

SpikeSim runtime 能耗估计的便捷入口。

该函数会执行一次真实前向传播并返回能耗报告。

参数:
  • model -- 待统计模型

  • inputs -- 模型输入;若为 tuple/list 则按 model(*inputs) 调用

  • config -- SpikeSim 能耗配置

  • strict -- 是否在 unsupported 情况下直接抛异常

  • verbose -- 是否打印逐 stage 的运行时统计信息


  • English

Convenience entry for runtime SpikeSim energy estimation. It runs one real forward pass and returns the energy report.

参数:
  • model -- model to profile

  • inputs -- model input; tuple/list will be passed as model(*inputs)

  • config -- SpikeSim energy config

  • strict -- whether to raise immediately on unsupported behaviors

  • verbose -- whether to print per-stage runtime statistics