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:
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: