qualia_plugin_snn.postprocessing.QualiaCodeGen module

Provide the model postprocessing class to generate C code for Spiking Neural Networks using Qualia-CodeGen-Plugin-SNN.

class qualia_plugin_snn.postprocessing.QualiaCodeGen.QualiaCodeGen[source]

Bases: QualiaCodeGen

Qualia-CodeGen converter calling Qualia-CodeGen-Plugin-SNN to handle Spiking Neural Network layers.

deployers: ModuleType

qualia_plugin_snn.deployment.qualia_codegen default 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.QualiaCodeGen for more information.

Parameters:
  • quantize (str) – Quantization data type

  • long_width (int | None) – Long number bit width

  • outdir (str | None) – Output directory

  • metrics (list[str] | None) – List of metrics to implement

  • 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.TorchModelGraph from Qualia-CodeGen-Plugin-SNN in order to support Spiking Neural Networks. The following layers are passed as custom_layers:

SpikingJelly step_mode is 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.Converter from Qualia-CodeGen-Plugin-SNN in order to support Spiking Neural Networks.

Parameters:
Returns:

String containing the single-file C code

Return type:

str | bool