qualia_plugin_snn.postprocessing package
Submodules
- qualia_plugin_snn.postprocessing.EnergyEstimationMetric module
SpikeCounterEnergyEstimationMetricLoggerFieldsEnergyEstimationMetricLoggerFields.nameEnergyEstimationMetricLoggerFields.mem_potEnergyEstimationMetricLoggerFields.mem_weightsEnergyEstimationMetricLoggerFields.mem_biasEnergyEstimationMetricLoggerFields.mem_ioEnergyEstimationMetricLoggerFields.mem_totalEnergyEstimationMetricLoggerFields.opsEnergyEstimationMetricLoggerFields.addrEnergyEstimationMetricLoggerFields.opsaddrEnergyEstimationMetricLoggerFields.totalEnergyEstimationMetricLoggerFields.input_spikerateEnergyEstimationMetricLoggerFields.output_spikerateEnergyEstimationMetricLoggerFields.input_countEnergyEstimationMetricLoggerFields.output_countEnergyEstimationMetricLoggerFields.input_is_binaryEnergyEstimationMetricLoggerFields.output_is_binaryEnergyEstimationMetricLoggerFields.is_sjEnergyEstimationMetricLoggerFields.__new__()
EnergyMetricsEnergyMetrics.nameEnergyMetrics.mem_potEnergyMetrics.mem_weightsEnergyMetrics.mem_biasEnergyMetrics.mem_ioEnergyMetrics.opsEnergyMetrics.addrEnergyMetrics.input_spikerateEnergyMetrics.output_spikerateEnergyMetrics.input_countEnergyMetrics.output_countEnergyMetrics.input_is_binaryEnergyMetrics.output_is_binaryEnergyMetrics.is_sjEnergyMetrics.mem_totalEnergyMetrics.opsaddrEnergyMetrics.totalEnergyMetrics.asnamedtuple()EnergyMetrics.__init__()
EnergyEstimationMetricEnergyEstimationMetric.energy_valuesEnergyEstimationMetric.__init__()EnergyEstimationMetric._set_op_estimation_type()EnergyEstimationMetric._set_energy_values()EnergyEstimationMetric._rdin_conv_fnn()EnergyEstimationMetric._e_rdin_conv_fnn()EnergyEstimationMetric._rdin_fc_fnn()EnergyEstimationMetric._e_rdin_fc_fnn()EnergyEstimationMetric._rdin_add_fnn()EnergyEstimationMetric._e_rdin_add_fnn()EnergyEstimationMetric._rdweights_conv_fnn()EnergyEstimationMetric._e_rdweights_conv_fnn()EnergyEstimationMetric._rdbias_conv_fnn()EnergyEstimationMetric._e_rdbias_conv_fnn()EnergyEstimationMetric._rdweights_fc_fnn()EnergyEstimationMetric._e_rdweights_fc_fnn()EnergyEstimationMetric._rdbias_fc_fnn()EnergyEstimationMetric._e_rdbias_fc_fnn()EnergyEstimationMetric._wrout_conv_fnn()EnergyEstimationMetric._e_wrout_conv_fnn()EnergyEstimationMetric._wrout_fc_fnn()EnergyEstimationMetric._e_wrout_fc_fnn()EnergyEstimationMetric._wrout_add_fnn()EnergyEstimationMetric._e_wrout_add_fnn()EnergyEstimationMetric._mac_ops_conv_fnn()EnergyEstimationMetric._e_ops_conv_fnn()EnergyEstimationMetric._mac_ops_fc_fnn()EnergyEstimationMetric._acc_ops_fc_fnn()EnergyEstimationMetric._e_ops_fc_fnn()EnergyEstimationMetric._mac_ops_add_fnn()EnergyEstimationMetric._acc_ops_add_fnn()EnergyEstimationMetric._e_ops_add_fnn()EnergyEstimationMetric._mac_addr_conv_fnn()EnergyEstimationMetric._acc_addr_conv_fnn()EnergyEstimationMetric._e_addr_conv_fnn()EnergyEstimationMetric._mac_addr_fc_fnn()EnergyEstimationMetric._acc_addr_fc_fnn()EnergyEstimationMetric._e_addr_fc_fnn()EnergyEstimationMetric._mac_addr_add_fnn()EnergyEstimationMetric._acc_addr_add_fnn()EnergyEstimationMetric._e_addr_add_fnn()EnergyEstimationMetric._compute_model_energy_fnn()EnergyEstimationMetric._rdin_snn()EnergyEstimationMetric._e_rdin_snn()EnergyEstimationMetric._rdweights_conv_snn()EnergyEstimationMetric._e_rdweights_conv_snn()EnergyEstimationMetric._rdbias_conv_snn()EnergyEstimationMetric._e_rdbias_conv_snn()EnergyEstimationMetric._rdweights_fc_snn()EnergyEstimationMetric._e_rdweights_fc_snn()EnergyEstimationMetric._rdbias_fc_snn()EnergyEstimationMetric._e_rdbias_fc_snn()EnergyEstimationMetric._wrout_snn()EnergyEstimationMetric._e_wrout_snn()EnergyEstimationMetric._wrpot_conv_snn()EnergyEstimationMetric._e_wrpot_conv_snn()EnergyEstimationMetric._wrpot_fc_snn()EnergyEstimationMetric._e_wrpot_fc_snn()EnergyEstimationMetric._rdpot_conv_snn()EnergyEstimationMetric._e_rdpot_conv_snn()EnergyEstimationMetric._rdpot_fc_snn()EnergyEstimationMetric._e_rdpot_fc_snn()EnergyEstimationMetric._mac_ops_conv_snn()EnergyEstimationMetric._acc_ops_conv_snn()EnergyEstimationMetric._e_ops_conv_snn()EnergyEstimationMetric._mac_ops_fc_snn()EnergyEstimationMetric._acc_ops_fc_snn()EnergyEstimationMetric._e_ops_fc_snn()EnergyEstimationMetric._mac_addr_conv_snn()EnergyEstimationMetric._acc_addr_conv_snn()EnergyEstimationMetric._e_addr_conv_snn()EnergyEstimationMetric._mac_addr_fc_snn()EnergyEstimationMetric._acc_addr_fc_snn()EnergyEstimationMetric._e_addr_fc_snn()EnergyEstimationMetric._compute_model_energy_snn()EnergyEstimationMetric._energy_summary()EnergyEstimationMetric._record_spike_count()EnergyEstimationMetric._process_model()EnergyEstimationMetric.__call__()EnergyEstimationMetric._e_ram()EnergyEstimationMetric._e_addEnergyEstimationMetric._e_mul
- qualia_plugin_snn.postprocessing.FuseBatchNorm module
- qualia_plugin_snn.postprocessing.OperationCounter module
OperationCounterLoggerFieldsOperationCounterLoggerFields.nameOperationCounterLoggerFields.syn_accOperationCounterLoggerFields.syn_macOperationCounterLoggerFields.addr_accOperationCounterLoggerFields.addr_macOperationCounterLoggerFields.total_accOperationCounterLoggerFields.total_macOperationCounterLoggerFields.mem_writeOperationCounterLoggerFields.mem_readOperationCounterLoggerFields.input_spikerateOperationCounterLoggerFields.output_spikerateOperationCounterLoggerFields.input_countOperationCounterLoggerFields.output_countOperationCounterLoggerFields.input_is_binaryOperationCounterLoggerFields.output_is_binaryOperationCounterLoggerFields.is_sjOperationCounterLoggerFields.__new__()
OperationMetricsOperationMetrics.nameOperationMetrics.syn_accOperationMetrics.syn_macOperationMetrics.addr_accOperationMetrics.addr_macOperationMetrics.mem_writeOperationMetrics.mem_readOperationMetrics.input_spikerateOperationMetrics.output_spikerateOperationMetrics.input_countOperationMetrics.output_countOperationMetrics.input_is_binaryOperationMetrics.output_is_binaryOperationMetrics.is_sjOperationMetrics.total_accOperationMetrics.total_macOperationMetrics.asnamedtuple()OperationMetrics.asdict()OperationMetrics.__init__()
OperationCounter
- qualia_plugin_snn.postprocessing.QualiaCodeGen module
Module contents
Qualia-Plugin-SNN postprocessing package contains postprocessing modules adapted for or dedicated to Spiking Neural Networks.
- class qualia_plugin_snn.postprocessing.EnergyEstimationMetric[source]
Bases:
PostProcessing[Module]Analytical energy estimation metric.
From An Analytical Estimation of Spiking Neural Networks Energy Efficiency, Lemaire et al. ICONIP2022.
@inproceedings{EnergyEstimationMetricICONIP2022, title = {An Analytical Estimation of Spiking Neural Networks Energy Efficiency}, author = {Lemaire, Edgar and Cordone, Loïc and Castagnetti, Andrea and Novac, Pierre-Emmanuel and Courtois, Jonathan and Miramond, Benoît}, booktitle = {Proceedings of the 29th International Conference on Neural Information Processing}, pages = {574--587}, year = {2023}, doi = {10.1007/978-3-031-30105-6_48}, series = {ICONIP}, }
Supports sequential (non-residual) formal and spiking convolutional neural networks with the following layers:
torch.nn.ReLUfor formal neural networksspikingjelly.activation_based.neuron.IFNodefor spiking neural networksspikingjelly.activation_based.neuron.LIFNodefor spiking neural networks
- energy_values: Final[dict[int, dict[str, float]]] = {8: {'add': 0.03, 'mul': 0.2}, 32: {'add': 0.1, 'mul': 3.1}}
Energy values for different bit widths and operations.
Default from Computing’s Energy Problem (and what we can do about it), Mark Horowitz, ISSCC 2014.
- __init__(mem_width: int, fifo_size: int = 0, total_spikerate_exclude_nonbinary: bool = True, op_estimation_type: dict[str, str] | None = None, sram_estimation_type: str | None = None) None[source]
Construct
qualia_plugin_snn.postprocessing.EnergyEstimationMetric.EnergyEstimationMetric.- Parameters:
mem_width (int) – Memory access size in bits, e.g. 16 for 16-bit quantization
fifo_size (int) – Size of the input/output FIFOs for each layer in SPLEAT
total_spikerate_exclude_nonbinary (bool) – If True, exclude non-binary inputs/outputs from total spikerate computation
op_estimation_type (dict[str, str] | None) – Optional estimation type for the energy values, one of ‘ICONIP’, ‘saturation’, ‘linear’, ‘quadratic’, defaults to ‘ICONIP’, see
_set_energy_values()and_set_op_estimation_type()sram_estimation_type (str | None) – Optional SRAM estimation algorithm, ‘old’ (ICONIP2022) or ‘new’ (T. Louis), defaults to ‘old’, see :meth:``_e_ram`
- Return type:
None
- _set_op_estimation_type(bit_width: int, op_type: str, op_estimation_type: str | int) float[source]
Set the estimation type for the energy values.
If op_estimation_type is not in [‘ICONIP’, ‘saturation’, ‘linear’, ‘quadratic’], raise ValueError.
If op_estimation_type is ‘’ICONIP’, use the energy values from the ICONIP 2022 paper (i.e. 32-bit values).
If op_estimation_type is ‘saturation’, use self.energy_values[8][type] for 8-bit and below, and self.energy_values[32][type] for bit widths between 9 and 32.
If op_estimation_type is ‘linear’, use self.energy_values[8][type] and self.energy_values[32][type] to estimate the energy values by solving a linear equation: y = m*bit_width + c.
If op_estimation_type is ‘quadratic’, use self.energy_values[8][type] and self.energy_values[32][type] to estimate the energy values by solving a quadratic equation: y = a*bit_width^2 + b*bit_width + c.
- Parameters:
- Returns:
Energy for the given bit width, operation and estimation type
- Raises:
ValueError – When
op_estimation_typeis invalid, orbit_widthis out of bounds for ‘saturation’op_estimation_type- Return type:
- _set_energy_values(bit_width: int, op_estimation_type: dict[str, str] | None) None[source]
Set the operation energy values for the given bit width.
If
op_estimation_typeis set, use_set_op_estimation_type()to infer the values according to the wanted bit width and type.Otherwise, if
bit_widthis inenergy_valuesuse the predefined energy values inenergy_values.Otherwise, defaults to using predefined 32-bit values from
energy_values.
- _rdin_conv_fnn(layer: TConvLayer) int[source]
Count number of read operations for the input of a convolutional layer in a formal neural network.
Eq. 3: Cin × Cout × Hout × Wout × Wkernel × Hkernel.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of read operations for the input of a convolutional layer in a formal neural network
- Return type:
- _e_rdin_conv_fnn(layer: TConvLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the input of a convolution layer in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the input of a convolution layer in a formal neural network
- Return type:
- _rdin_fc_fnn(layer: TDenseLayer) int[source]
Count number of read operations for the input of a fully-connected layer in a formal neural network.
Eq. 4: Nin.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of read operations for the input of a fully-connected layer in a formal neural network
- Return type:
- _e_rdin_fc_fnn(layer: TDenseLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the input of a fully-connected layer in a formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the input of a fully-connected layer in a formal neural network
- Return type:
- _rdin_add_fnn(layer: TAddLayer) int[source]
Count number of read operations for the input of an add layer in a formal neural network.
#InLayers × Nin.
- _e_rdin_add_fnn(layer: TAddLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the input of an add layer in a formal neural network.
- _rdweights_conv_fnn(layer: TConvLayer) int[source]
Count number of read operations for the weights of a convolutional layer (excluding bias) in a formal neural network.
Eq. 6.1f: Cin × Wkernel × Hkernel × Cout × Wout × Hout.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of read operations for the weights of a convolutional layer (excluding bias) in a formal neural network
- Return type:
- _e_rdweights_conv_fnn(layer: TConvLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the weights of a convolutional layer (excluding bias) in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the weights of a convolutional layer (excluding bias) in a formal neural network
- Return type:
- _rdbias_conv_fnn(layer: TConvLayer) int[source]
Count number of read operations for the biases of a convolutional layer in a formal neural network.
Eq. 6.1s: Cout × Wout × Hout.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of read operations for the biases of a convolutional layer in a formal neural network
- Return type:
- _e_rdbias_conv_fnn(layer: TConvLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the biases of a convolutional layer in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the biases of a convolutional layer in a formal neural network or 0 if the layer does not use biases
- Return type:
- _rdweights_fc_fnn(layer: TDenseLayer) int[source]
Count number of read operations for the weights of a fully-connected layer (excluding bias) in a formal neural network.
Eq. 6.2f: Nin × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of read operations for the weights of a fully-connected layer (excluding bias) in a formal neural network
- Return type:
- _e_rdweights_fc_fnn(layer: TDenseLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for weights of a fully-connected layer (excluding bias) in a formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the weights of a fully-connected layer (excluding bias) in a formal neural network
- Return type:
- _rdbias_fc_fnn(layer: TDenseLayer) int[source]
Count number of read operations for the biases of a fully-connected layer in a formal neural network.
Eq. 6.2s: Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of read operations for the biases of a fully-connected layer in a formal neural network
- Return type:
- _e_rdbias_fc_fnn(layer: TDenseLayer, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the biases of a fully-connected layer in a formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the biases of a fully-connected layer in a formal neural network or 0 if the layer does not use biases
- Return type:
- _wrout_conv_fnn(layer: TConvLayer) int[source]
Count number of write operations for the output of a convolutional layer in a formal neural network.
Eq. 11: Cout × Hout × Wout.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of write operations for the output of a convolutional layer in a formal neural network
- Return type:
- _e_wrout_conv_fnn(layer: TConvLayer, e_wrram: Callable[[int], float]) float[source]
Compute energy for write operations for the output of a convolutional layer in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
e_rdram – Function to compute memory write access energy for a given memory size
- Returns:
Energy for write operations for the output of a convolutional layer in a formal neural network
- Return type:
- _wrout_fc_fnn(layer: TDenseLayer) int[source]
Count number of write operations for the output of a fully-connected layer in a formal neural network.
Eq. 12: Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of write operations for the output of a fully-connected layer in a formal neural network
- Return type:
- _e_wrout_fc_fnn(layer: TDenseLayer, e_wrram: Callable[[int], float]) float[source]
Compute energy for write operations for the output of a fully-connected layer in a formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
e_rdram – Function to compute memory write access energy for a given memory size
- Returns:
Energy for write operations for the output of a fully-connected layer in a formal neural network
- Return type:
- _wrout_add_fnn(layer: TAddLayer) int[source]
Count number of write operations for the output of an add layer in a formal neural network.
Nout.
- _e_wrout_add_fnn(layer: TAddLayer, e_wrram: Callable[[int], float]) float[source]
Compute energy for write operations for the output of an add layer in a formal neural network.
- _mac_ops_conv_fnn(layer: TConvLayer) int[source]
Count number of multiply-accumulate operations inside a convolutional layer in a formal neural network.
Eq. 1.1: Cout × Hout × Wout × Cin × Hkernel × Wkernel.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of multiply-accumulate operations inside a convolutional layer in a formal neural network.
- Return type:
- _e_ops_conv_fnn(layer: TConvLayer) float[source]
Compute energy for multiply-accumulate and accumulate operations inside convolutional layer in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Energy for multiply-accumulate and accumulate operations inside a convolutional layer in a formal neural network.
- Return type:
- _mac_ops_fc_fnn(layer: TDenseLayer) int[source]
Count number of multiply-accumulate operations inside a fully-connected layer in a formal neural network.
Eq. 2.1: Nin × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of multiply-accumulate operations inside a fully-connected layer in a formal neural network.
- Return type:
- _acc_ops_fc_fnn(layer: TDenseLayer) int[source]
Count number of accumulate operations inside a fully-connected layer in a formal neural network.
Eq. 2.2: Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of accumulate operations inside a fully-connected layer in a formal neural network.
- Return type:
- _e_ops_fc_fnn(layer: TDenseLayer) float[source]
Compute energy for multiply-accumulate and accumulate operations inside fully-connected layer in formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Energy for multiply-accumulate and accumulate operations inside a fully-connected layer in formal neural network.
- Return type:
- _mac_ops_add_fnn(_: TAddLayer) int[source]
Count number of multiply-accumulate operations inside an add layer in a formal neural network.
- _acc_ops_add_fnn(layer: TAddLayer) int[source]
Count number of accumulate operations inside an add layer in a formal neural network.
(#InLayers -1 ) × Nin Nout.
- _e_ops_add_fnn(layer: TAddLayer) float[source]
Compute energy for multiply-accumulate and accumulate operations inside an add layer in formal neural network.
- _mac_addr_conv_fnn(_: TConvLayer) int[source]
Count number of multiply-accumulate operations for addressing a convolutional layer in a formal neural network.
0
- Returns:
0
- Parameters:
_ (TConvLayer)
- Return type:
- _acc_addr_conv_fnn(layer: TConvLayer) int[source]
Count number of accumulate operations for addressing a convolutional layer in a formal neural network.
Cin × Hin × Win + Cout × Hout × Wout + Cout × Hkernel × Wkernel.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Number of accumulate operations for addressing a convolutional layer in a formal neural network
- Return type:
- _e_addr_conv_fnn(layer: TConvLayer) float[source]
Compute energy for addressing a convolutional layer in a formal neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
- Returns:
Energy for addressing a convolutional layer in a formal neural network.
- Return type:
- _mac_addr_fc_fnn(_: TDenseLayer) int[source]
Count number of multiply-accumulate operations for addressing a fully-connected layer in a formal neural network.
0
- Returns:
0
- Parameters:
_ (TDenseLayer)
- Return type:
- _acc_addr_fc_fnn(layer: TDenseLayer) int[source]
Count number of accumulate operations for addressing a fully-connected layer in a formal neural network.
Nin × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Number of accumulate operations for addressing a fully-connected layer in a formal neural network
- Return type:
- _e_addr_fc_fnn(layer: TDenseLayer) float[source]
Compute energy for addressing a fully-connected layer in a formal neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
- Returns:
Energy for addressing a fully-connected layer in a formal neural network.
- Return type:
- _mac_addr_add_fnn(_: TAddLayer) int[source]
Count number of multiply-accumulate operations for addressing an add layer in a formal neural network.
0
- _acc_addr_add_fnn(layer: TAddLayer) int[source]
Count number of accumulate operations for addressing an add layer in a formal neural network.
Nin.
- _e_addr_add_fnn(layer: TAddLayer) float[source]
Compute energy for addressing an add layer in a formal neural network.
- _compute_model_energy_fnn(modelgraph: ModelGraph, e_rdram: Callable[[int], float], e_wrram: Callable[[int], float]) list[EnergyMetrics][source]
Compute the energy per inference for each layer of a formal neural network.
Supports the following layers:
- Parameters:
- Returns:
A list of EnergyMetrics for each layer and a total with fields populated with energy estimation
- Return type:
- _rdin_snn(layer: TBaseLayer, input_spikerate: float) float[source]
Count average number of read operations for the input of a layer in a spiking neural network.
Eq. 5: θl-1.
- Parameters:
layer (TBaseLayer) – A convolutional or fully-connected layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of read operations for the input of a layer in a spiking neural network
- Return type:
- _e_rdin_snn(layer: TBaseLayer, input_spikerate: float, e_rdram: Callable[[int], float]) float[source]
Compute average energy for read operations for the input of a layer in a spiking neural network.
- Parameters:
layer (TBaseLayer) – A convolutional or fully-connected layer
input_spikerate (float) – Average spike per input per inference
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Average energy for read operations for the input of a layer in a spiking neural network
- Return type:
- _rdweights_conv_snn(layer: TConvLayer, input_spikerate: float) float[source]
Count average number of read operations for weights of convolutional layer (excluding bias) in spiking neural network.
Eq. 7f: θl-1 × Cout × Wkernel × Hkernel.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of read operations for weights of convolutional layer (excluding bias) in spiking neural network
- Return type:
- _e_rdweights_conv_snn(layer: TConvLayer, input_spikerate: float, e_rdram: Callable[[int], float]) float[source]
Compute average energy for read operations for convolutional layer weights (excluding bias) in spiking neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Average energy for read operations for weights of convolutional layer (excluding bias) in spiking neural network
- Return type:
- _rdbias_conv_snn(layer: TConvLayer, timesteps: int) int[source]
Count number of read operations for the biases of a convolutional layer in a spiking neural network.
Eq. 7s: Cout × Wout × Hout.
- Parameters:
layer (TConvLayer) – A convolutional layer
timesteps (int) – Number of timesteps
- Returns:
Number of read operations for the biases of a convolutional layer in a spiking neural network
- Return type:
- _e_rdbias_conv_snn(layer: TConvLayer, timesteps: int, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the biases of a convolutional layer in a spiking neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
timesteps (int) – Number of timesteps
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the biases of a convolutional layer in a spiking neural network or 0 if the layer does not use biases
- Return type:
- _rdweights_fc_snn(layer: TDenseLayer, input_spikerate: float) float[source]
Count average number of read operations for weights of fully-connected layer (excluding bias) in spiking neural network.
Eq. 8f: θl-1 × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of read operations for weights of fully-connected layer (excluding bias) in spiking neural network
- Return type:
- _e_rdweights_fc_snn(layer: TDenseLayer, input_spikerate: float, e_rdram: Callable[[int], float]) float[source]
Compute average energy for weights read operations of fully-connected layer (excluding bias) in spiking neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Average energy for read operations for weights of fully-connected layer (excluding bias) in spiking neural network
- Return type:
- _rdbias_fc_snn(layer: TDenseLayer, timesteps: int) int[source]
Count number of read operations for the biases of a fully-connected layer in a spiking neural network.
Eq. 6.2s: Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
timesteps (int) – Number of timesteps
- Returns:
Number of read operations for the biases of a fully-connected layer in a spiking neural network
- Return type:
- _e_rdbias_fc_snn(layer: TDenseLayer, timesteps: int, e_rdram: Callable[[int], float]) float[source]
Compute energy for read operations for the biases of a fully-connected layer in a spiking neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
timesteps (int) – Number of timesteps
e_rdram (Callable[[int], float]) – Function to compute memory read access energy for a given memory size
- Returns:
Energy for read operations for the biases of a fully-connected layer in a spiking neural network or 0 if the layer does not use biases
- Return type:
- _wrout_snn(layer: TBaseLayer, output_spikerate: float) float[source]
Count average number of write operations for the output of a layer in a spiking neural network.
Eq. 13: Noutput.
- Parameters:
layer (TBaseLayer) – A convolutional or fully-connected layer
output_spikerate (float) – Average spike per output per inference
- Returns:
Average number of write operations for the output of a layer in a spiking neural network
- Return type:
- _e_wrout_snn(layer: TBaseLayer, output_spikerate: float, e_wrram: Callable[[int], float]) float[source]
Compute average energy for write operations for the output of a layer in a spiking neural network.
- Parameters:
layer (TBaseLayer) – A convolutional or fully-connected layer
output_spikerate (float) – Average spike per output per inference
e_rdram – Function to compute memory write access energy for a given memory size
- Returns:
Average energy for write operations for the output of a layer in a spiking neural network
- Return type:
- _wrpot_conv_snn(layer: TConvLayer, input_spikerate: float, timesteps: int) float[source]
Count average number of write operations for the potentials of a convolutional layer in a spiking neural network.
Eq 14: θl-1 × Cout × Wkernel × Hkernel + Cout × Hout × Wout.
- Parameters:
layer (TConvLayer) – A convolutional layer
timesteps (int) – Number of timesteps
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of write operations for the potentials of a convolutional layer in a spiking neural network
- Return type:
- _e_wrpot_conv_snn(layer: TConvLayer, input_spikerate: float, timesteps: int, e_wrram: Callable[[int], float]) float[source]
Compute average energy for write operations for the potentials of a convolutional layer in a spiking neural network.
- Parameters:
- Returns:
Average energy for write operations for the potentials of a convolutional layer in a spiking neural network
- Return type:
- _wrpot_fc_snn(layer: TDenseLayer, input_spikerate: float, timesteps: int) float[source]
Count average number of write operations for the potentials of a fully-connected layer in a spiking neural network.
Eq 15: θl-1 × Nout + Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
timesteps (int) – Number of timesteps
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of write operations for the potentials of a fully-connected layer in a spiking neural network
- Return type:
- _e_wrpot_fc_snn(layer: TDenseLayer, input_spikerate: float, timesteps: int, e_wrram: Callable[[int], float]) float[source]
Compute average energy for write operations for the potentials of a fully-connected layer in a spiking neural network.
- Parameters:
- Returns:
Average energy for write operations for the potentials of a fully-connected layer in a spiking neural network
- Return type:
- _rdpot_conv_snn(layer: TConvLayer, input_spikerate: float, timesteps: int) float[source]
Count average number of read operations for the potentials of a convolutional layer in a spiking neural network.
Eq 9: θl-1 × Cout × Wkernel × Hkernel + Cout × Hout × Wout.
- Parameters:
layer (TConvLayer) – A convolutional layer
timesteps (int) – Number of timesteps
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of read operations for the potentials of a convolutional layer in a spiking neural network
- Return type:
- _e_rdpot_conv_snn(layer: TConvLayer, input_spikerate: float, timesteps: int, e_rdram: Callable[[int], float]) float[source]
Compute average energy for write operations for the potentials of a convolutional layer in a spiking neural network.
- Parameters:
- Returns:
Average energy for read operations for the potentials of a convolutional layer in a spiking neural network
- Return type:
- _rdpot_fc_snn(layer: TDenseLayer, input_spikerate: float, timesteps: int) float[source]
Count average number of read operations for the potentials of a fully-connected layer in a spiking neural network.
Eq 10: θl-1 × Nout + Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
timesteps (int) – Number of timesteps
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of read operations for the potentials of a fully-connected layer in a spiking neural network
- Return type:
- _e_rdpot_fc_snn(layer: TDenseLayer, input_spikerate: float, timesteps: int, e_wrram: Callable[[int], float]) float[source]
Compute average energy for read operations for the potentials of a fully-connected layer in a spiking neural network.
- Parameters:
- Returns:
Average energy for read operations for the potentials of a fully-connected layer in a spiking neural network
- Return type:
- _mac_ops_conv_snn(layer: TConvLayer, timesteps: int, leak: bool) int[source]
Count number of multiply-accumulate operations inside a convolutional layer in a spiking neural network.
Eq. 1.3: T × Cout × Hout × Wout.
- Parameters:
layer (TConvLayer) – A convolutional layer
timesteps (int) – Number of timesteps
leak (bool) – Whether the neuron has leak (LIF) or not (IF)
- Returns:
Number of multiply-accumulate operations inside a convolutional layer in a spiking neural network, 0 if no leak
- Return type:
- _acc_ops_conv_snn(layer: TConvLayer, input_spikerate: float, output_spikerate: float, timesteps: int) float[source]
Count average number of accumulate operations inside a convolutional layer in a spiking neural network.
Eq. 1.4: θl-1 × ceil(Hkernel / S) × ceil(Wkernel / S) × Cout + T × Cout × Hout × Wout + θl.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
output_spikerate (float) – Average spike per output per inference
timesteps (int) – Number of timesteps
- Returns:
Average number of accumulate operations inside a convolutional layer in a spiking neural network.
- Return type:
- _e_ops_conv_snn(layer: TConvLayer, input_spikerate: float, output_spikerate: float, timesteps: int, leak: bool) float[source]
Compute average energy for multiply-accumulate and accumulate inside a convolutional layer in spiking neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
output_spikerate (float) – Average spike per output per inference
timesteps (int) – Number of timesteps
leak (bool) – Whether the neuron has leak (LIF) or not (IF)
- Returns:
Average energy for multiply-accumulate and accumulate inside a convolutional layer in spiking neural network.
- Return type:
- _mac_ops_fc_snn(layer: TDenseLayer, timesteps: int, leak: bool) int[source]
Count number of multiply-accumulate operations inside a fully-connected layer in a spiking neural network.
Eq. 2.3: T × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
timesteps (int) – Number of timesteps
leak (bool) – Whether the neuron has leak (LIF) or not (IF)
- Returns:
Number of multiply-accumulate operations inside a fully-connected layer in a spiking neural network, 0 if no leak
- Return type:
- _acc_ops_fc_snn(layer: TDenseLayer, input_spikerate: float, output_spikerate: float, timesteps: int) float[source]
Count average number of accumulate operations inside a fully-connected layer in a spiking neural network.
Eq. 2.4: θl-1 × Nout + T × Nout + θl.
Warning 1: the article counts Nin times too many as 1 input spike triggers only Nout MAC (each output neuron).
Warning 2: the article is missing the third term which corresponds to the reset.
Original equation (not used here): Eq. 2.4: θl-1 × Nin × Nout + T × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
output_spikerate (float) – Average spike per output per inference
timesteps (int) – Number of timesteps
- Returns:
Average number of accumulate operations inside a fully-connected layer in a spiking neural network.
- Return type:
- _e_ops_fc_snn(layer: TDenseLayer, input_spikerate: float, output_spikerate: float, timesteps: int, leak: bool) float[source]
Compute average energy for multiply-accumulate and accumulate inside fully-connected layer in spiking neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
output_spikerate (float) – Average spike per output per inference
timesteps (int) – Number of timesteps
leak (bool) – Whether the neuron has leak (LIF) or not (IF)
- Returns:
Average energy for multiply-accumulate and accumulate inside a fully-connected layer in spiking neural network.
- Return type:
- _mac_addr_conv_snn(layer: TConvLayer, input_spikerate: float) float[source]
Count average number of multiply-accumulate operations for addressing a convolutional layer in a spiking neural network.
Eq. 16.2: θl-1 × 2.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
- Returns:
average number of multiply-accumulate operations for addressing a convolutional layer in a spiking neural network.
- Return type:
- _acc_addr_conv_snn(layer: TConvLayer, input_spikerate: float) float[source]
Count average number of accumulate operations for addressing a convolutional layer in a spiking neural network.
Eq 16.3: θl-1 × Cout × Hkernel × Wkernel.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of accumulate operations for addressing a convolutional layer in a spiking neural network
- Return type:
- _e_addr_conv_snn(layer: TConvLayer, input_spikerate: float) float[source]
Compute average energy for addressing a convolutional layer in a spiking neural network.
- Parameters:
layer (TConvLayer) – A convolutional layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average energy for addressing a convolutional layer in a spiking neural network.
- Return type:
- _mac_addr_fc_snn(_: TDenseLayer) int[source]
Count number of multiply-accumulate operations for addressing a fully-connected layer in a spiking neural network.
0
- Returns:
0
- Parameters:
_ (TDenseLayer)
- Return type:
- _acc_addr_fc_snn(layer: TDenseLayer, input_spikerate: float) float[source]
Count average number of accumulate operations for addressing a fully-connected layer in a spiking neural network.
Eq. 17.2: θl-1 × Nout.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average number of accumulate operations for addressing a fully-connected layer in a spiking neural network
- Return type:
- _e_addr_fc_snn(layer: TDenseLayer, input_spikerate: float) float[source]
Compute average energy for addressing a fully-connected layer in a spiking neural network.
- Parameters:
layer (TDenseLayer) – A fully-connected layer
input_spikerate (float) – Average spike per input per inference
- Returns:
Average energy for addressing a fully-connected layer in a spiking neural network.
- Return type:
- _compute_model_energy_snn(modelgraph: ModelGraph, input_spikerates: dict[str, float], output_spikerates: dict[str, float], input_is_binary: dict[str, bool], output_is_binary: dict[str, bool], input_counts: dict[str, int | float | bool], output_counts: dict[str, int | float | bool], is_module_sj: dict[str, bool], timesteps: int, e_rdram: Callable[[int], float], e_wrram: Callable[[int], float]) list[EnergyMetrics][source]
Compute the energy per inference for each layer of a spiking neural network.
Supports the following layers:
Input spike rates are per-timestep, this function multiplies by the number of timesteps to get the spike rates per infernce which are used by the operation count and energy computation functions.
- Parameters:
modelgraph (ModelGraph) – Model to compute energy on
input_spikerate – Dict of layer names and average spike per input per timestep for the layer
output_spikerate – Dict of layer names and average spike per output per timestep for the layer
input_is_binary (dict[str, bool]) – Dict of layer names and whether its input is binary (spike) or not
output_is_binary (dict[str, bool]) – Dict of layer names and whether its output is binary (spike) or not
input_counts (dict[str, int | float | bool]) – Dict of layer names and number of inputs for the layer
output_counts (dict[str, int | float | bool]) – Dict of layer names and number of outputs for the layer
timesteps (int) – Number of timesteps
e_rdram (Callable[[int], float]) – Function to compute memory read energy for a given memory size
e_wrram (Callable[[int], float]) – Function to compute memory write energy for a given memory size
- Returns:
A list of EnergyMetrics for each layer and a total with fields populated with energy estimation
- Return type:
- _energy_summary(ems: list[EnergyMetrics]) str[source]
Generate a human-friendly text summary of the energy metrics per layer.
- Parameters:
ems (list[EnergyMetrics]) – List of EnergyMetrics per layer and the total
- Returns:
The text summary
- Return type:
- _record_spike_count(trainresult: TrainResult, framework: SpikingJelly, model: SNN, dataset: RawData) tuple[dict[str, bool], dict[str, SpikeCounter], dict[str, SpikeCounter]][source]
Compute spike rate averaged over each neuron and timestep.
A forward hook is added to each layer in order to record its input and output during inference performed over the given dataset.
The layer name is computed using the internal
torch.fxfunctionstorch.fx.graph._Namespace.create_name()andtorch.fx.graph._snake_case()so that it is compatible withqualia_codegen_core.graph.ModelGraph.ModelGraph.- Parameters:
trainresult (TrainResult) – TrainResult containing configuration for
pytorch_lightning.Trainersuch asmicroai_core.microai.TrainResult.batch_sizeandmicroai_core.microai.TrainResult.dataaugmentationsframework (SpikingJelly) – A
microai_plugin_snn.learningframework.SpikingJelly.SpikingJellyinstancemodel (SNN) – A model to evaluate spike rate on
dataset (RawData) – The data to use for inference
- Returns:
A tuple of 4 dicts, first 2 dicts map a layer name to its input and output spike rates per timestep respectively, the other 2 dicts map a layer name to
Trueif the input or outputs are binary respectively,Falseotherwise.- Return type:
tuple[dict[str, bool], dict[str, SpikeCounter], dict[str, SpikeCounter]]
- _process_model(trainresult: TrainResult) tuple[ModelGraph | None, dict[str, float] | None, dict[str, float] | None, dict[str, bool] | None, dict[str, bool] | None, dict[str, int | float | bool] | None, dict[str, int | float | bool] | None, dict[str, bool] | None][source]
Process the model to generate layer graph and compute activity in case of SNN.
Use Qualia CodeGen in order to build a
qualia_codegen_core.graph.ModelGraph.ModelGraphthat is easier to parse.Execute inference pass on dataset using
_record_spike_count()to collect statistics of spike activity in case of SNN.- Parameters:
trainresult (TrainResult) – TrainResult containing the SNN or FNN model, the dataset and the training configuration
- Returns:
A tuple of Qualia-CodeGen’s ModelGraph and various SNN metrics as dicts of layer name and associated value, in order: input spike rate, output spike rate, input is binary, output is binary, input spike count, output spike count, module is sj
- Return type:
tuple[ModelGraph | None, dict[str, float] | None, dict[str, float] | None, dict[str, bool] | None, dict[str, bool] | None, dict[str, int | float | bool] | None, dict[str, int | float | bool] | None, dict[str, bool] | None]
- __call__(trainresult: TrainResult, model_conf: ModelConfigDict) tuple[TrainResult, ModelConfigDict][source]
Compute energy estimation metric from Lemaire et al, 2022.
Uses Qualia CodeGen in order to build a
qualia_codegen_core.graph.ModelGraph.ModelGraphthat is easier to parse. Call either_compute_model_energy_snn()or_compute_model_energy_fnn()depending on whether the model is an SNN or an FNN. Print the resulting metrics and log them to a CSV file inside the logs/<bench.name>/EnergyEstimationMetric directory.- Parameters:
trainresult (TrainResult) – TrainResult containing the SNN or FNN model, the dataset and the training configuration
model_conf (ModelConfigDict) – Unused
- Returns:
The unmodified trainresult
- Return type:
tuple[TrainResult, ModelConfigDict]
- _e_ram(mem_params: int, bits: int) float[source]
Energy for a single RAM access (read or write).
If
_sram_estimation_typeis ‘new’, use T. Louis method with multiple data packed over a single 10pJ 64-bit access, regardless of total memory size.Otherwise, use ICONIP2022 method with a single access for each data with energy proportional to total memory size, computed with a linear regression over Horowitz 2014 values of 8KiB, 32KiB and 1MiB SRAM.
- class qualia_plugin_snn.postprocessing.FuseBatchNorm[source]
Bases:
FuseBatchNormExtend
qualia_core.postprocessing.FuseBatchNorm.FuseBatchNormwith support for Spiking Neural Networks.spikingjelly.activation_based.neuron.BaseNodeandspikingjelly.activation_based.base.StepModuleare added toqualia_core.postprocessing.FuseBatchNorm.FuseBatchNorm.custom_layersto avoid tracing inside.SpikingJelly-wrapped layers are added to lookup patterns:
(
spikingjelly.activation_based.layer.Conv1d,spikingjelly.activation_based.layer.BatchNorm1d(
spikingjelly.activation_based.layer.Conv2d,spikingjelly.activation_based.layer.BatchNorm2d(
spikingjelly.activation_based.layer.Conv3d,spikingjelly.activation_based.layer.BatchNorm3d
Extended attributes
timestepsandis_snnare copied into target model.- extra_custom_layers: tuple[type[Module | StepModule], ...] = (<class 'spikingjelly.activation_based.neuron.BaseNode'>, <class 'spikingjelly.activation_based.base.StepModule'>)
- __init__(evaluate: bool = True) None[source]
Construct
qualia_plugin_snn.postprocessing.FuseBatchNorm.FuseBatchNorm.Patterns are extended to include SpikingJelly-wrapped layers.
- Parameters:
evaluate (bool)
- Return type:
None
- fuse(model: Module, graphmodule_cls: type[GraphModule], framework: PyTorch, inplace: bool = False) GraphModule[source]
Fuse BatchNorm to Conv and copy source model
timestepsand is_snn attributes to target model.- Parameters:
mode – PyTorch model with Conv-BatchNorm layers to fuse
inplace (bool) – Modify model in place instead of deep-copying
model (Module)
graphmodule_cls (type[GraphModule])
framework (PyTorch)
- Returns:
Resulting model with BatchNorm fused to Conv
- Return type:
- class qualia_plugin_snn.postprocessing.OperationCounter[source]
Bases:
EnergyEstimationMetricOperation counter metric.
From An Analytical Estimation of Spiking Neural Networks Energy Efficiency, Lemaire et al. ICONIP2022.
@inproceedings{EnergyEstimationMetricICONIP2022, title = {An Analytical Estimation of Spiking Neural Networks Energy Efficiency}, author = {Lemaire, Edgar and Cordone, Loïc and Castagnetti, Andrea and Novac, Pierre-Emmanuel and Courtois, Jonathan and Miramond, Benoît}, booktitle = {Proceedings of the 29th International Conference on Neural Information Processing}, pages = {574--587}, year = {2023}, doi = {10.1007/978-3-031-30105-6_48}, series = {ICONIP}, }
Supports sequential (non-residual) formal and spiking convolutional neural networks with the following layers:
torch.nn.ReLUfor formal neural networksspikingjelly.activation_based.neuron.IFNodefor spiking neural networksspikingjelly.activation_based.neuron.LIFNodefor spiking neural networks
- __init__(total_spikerate_exclude_nonbinary: bool = True) None[source]
Construct
qualia_plugin_snn.postprocessing.OperationCounter.OperationCounter.- Parameters:
total_spikerate_exclude_nonbinary (bool) – If True, exclude non-binary inputs/outputs from total spikerate computation
- Return type:
None
- _compute_model_operations_fnn(modelgraph: ModelGraph) list[OperationMetrics][source]
Compute the operations per inference for each layer of a formal neural network.
Supports the following layers:
- Parameters:
modelgraph (ModelGraph) – Model to compute energy on
- Returns:
A list of OperationMetrics for each layer and a total with fields populated with operation estimation
- Return type:
- _compute_model_operations_snn(modelgraph: ModelGraph, input_spikerates: dict[str, float], output_spikerates: dict[str, float], input_is_binary: dict[str, bool], output_is_binary: dict[str, bool], input_counts: dict[str, int | float | bool], output_counts: dict[str, int | float | bool], is_module_sj: dict[str, bool], timesteps: int) list[OperationMetrics][source]
Compute the operations per inference for each layer of a spiking neural network.
Supports the following layers:
Input spike rates are per-timestep, this function multiplies by the number of timesteps to get the spike rates per infernce which are used by the operation count functions.
- Parameters:
modelgraph (ModelGraph) – Model to computer operations on
input_spikerate – Dict of layer names and average spike per input per timestep for the layer
output_spikerate – Dict of layer names and average spike per output per timestep for the layer
input_is_binary (dict[str, bool]) – Dict of layer names and whether its input is binary (spike) or not
output_is_binary (dict[str, bool]) – Dict of layer names and whether its output is binary (spike) or not
input_counts (dict[str, int | float | bool]) – Dict of layer names and number of inputs for the layer
output_counts (dict[str, int | float | bool]) – Dict of layer names and number of outputs for the layer
is_module_sj (dict[str, bool]) – Whether the layer is a spiking layer (a SpikingJelly module)
timesteps (int) – Number of timesteps
- Returns:
A list of OperationMetrics for each layer and a total with fields populated with operation count
- Return type:
- _operations_summary(oms: list[OperationMetrics]) str[source]
Generate a human-friendly text summary of the operations per layer.
- Parameters:
oms (list[OperationMetrics]) – List of OperationMetrics per layer and the total
- Returns:
The text summary
- Return type:
- __call__(trainresult: TrainResult, model_conf: ModelConfigDict) tuple[TrainResult, ModelConfigDict][source]
Compute operation count metric from Lemaire et al, 2022.
First process the model to extract the graph and activity in case of SNN using
_process_model(). Then call either_compute_model_operations_snn()or_compute_model_operations_fnn()depending on whether the model is an SNN or an FNN. Print the resulting metrics and log them to a CSV file inside the logs/<bench.name>/OperationCounter directory.- Parameters:
trainresult (TrainResult) – TrainResult containing the SNN or FNN model, the dataset and the training configuration
model_conf (ModelConfigDict) – Unused
- Returns:
The unmodified trainresult
- Return type:
tuple[TrainResult, ModelConfigDict]
- class qualia_plugin_snn.postprocessing.QualiaCodeGen[source]
Bases:
QualiaCodeGenQualia-CodeGen converter calling Qualia-CodeGen-Plugin-SNN to handle Spiking Neural Network layers.
- deployers: ModuleType
qualia_plugin_snn.deployment.qualia_codegendefault deployers.Includes
qualia_plugin_spleat.deployment.qualia_codegen.Linux.Linux.
- __init__(quantize: str, long_width: int | None = None, outdir: str | None = None, metrics: list[str] | None = None, model_name: str = 'cnn', dump_featuremaps: bool = False, timestep_mode: Literal['duplicate', 'iterate'] = 'duplicate') None[source]
Construct
qualia_plugin_snn.postprocessing.QualiaCodeGen.QualiaCodeGen.See
qualia_core.postprocessing.QualiaCodeGen.QualiaCodeGenfor more information.- Parameters:
quantize (str) – Quantization data type
long_width (int | None) – Long number bit width
outdir (str | None) – Output directory
model_name (str) – Model name to assign to the main inference function, default is
'cnn'dump_featuremaps (bool) – Generate code in model call chain to dump output of all layers to JSON files
timestep_mode (Literal['duplicate', 'iterate']) – Input timestep handling mode, either
'duplicate'to duplicate static input data over timesteps, or'iterate'to iterate over existing input data timestep dimension
- Return type:
None
- convert_model_to_modelgraph(model: Module) ModelGraph | None[source]
Convert PyTorch model to a Qualia-CodeGen ModelGraph graph representation.
Uses the
qualia_codegen_plugin_snn.graph.TorchModelGraph.TorchModelGraphfrom Qualia-CodeGen-Plugin-SNN in order to support Spiking Neural Networks. The following layers are passed ascustom_layers:spikingjelly.activation_based.layer.Conv1d, handled like atorch.nn.Conv1dspikingjelly.activation_based.layer.Conv2d, handled like atorch.nn.Conv2dspikingjelly.activation_based.layer.Flatten, handled like atorch.nn.Flattenspikingjelly.activation_based.layer.Linear, handled like atorch.nn.Linearqualia_core.learningmodel.pytorch.layers.Add.Add, mapped to aqualia_codegen_core.graph.layers.TAddLayer.TAddLayerqualia_plugin_snn.learningmodel.pytorch.layers.spikingjelly.GlobalSumPool1d.GlobalSumPool1d, mapped to aqualia_codegen_core.graph.layers.TSumLayer.TSumLayerqualia_plugin_snn.learningmodel.pytorch.layers.spikingjelly.GlobalSumPool2d.GlobalSumPool2d, mapped to aqualia_codegen_core.graph.layers.TSumLayer.TSumLayer
SpikingJelly
step_modeis forced to's'for single-step operation to simplify visit of the graph.- Parameters:
model (Module) – PyTorch model
- Returns:
Qualia-CodeGen ModelGraph or None in case of error
- Return type:
ModelGraph | None
- convert_modelgraph_to_c(modelgraph: ModelGraph, output_path: Path) str | bool[source]
Generate C code for the given ModelGraph using Qualia-CodeGen.
Uses the
qualia_codegen_plugin_snn.Converter.Converterfrom Qualia-CodeGen-Plugin-SNN in order to support Spiking Neural Networks.- Parameters:
modelgraph (ModelGraph) – The ModelGraph object from
qualia_codegen_plugin_snn.graph.TorchModelGraph.TorchModelGraphafter conversion withconvert_model_to_modelgraph()output_path (Path) – Generated C code output path
- Returns:
String containing the single-file C code
- Return type: