Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintConstantGeneration
- class Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintConstantGeneration
Bases:
CodeTransformationPass,IntrospectiveCodeTransformationMixInCode transformation pass for generating debug print statements for constant tensors.
This class extends CodeTransformationPass to automatically insert debug printing code that displays the contents of constant tensors used by operations. It’s useful for debugging, verification, and analysis of neural network weights, biases, and other constant parameters.
Constant tensors represent model parameters and other immutable data that don’t change during execution. Printing these values helps verify that the correct parameters are loaded and accessible during operation execution.
Notes
This transformation only processes ConstantBuffer instances that have users (are actually referenced by operations). The printing is added before the operation execution to show the constant values being used.
This is particularly useful for debugging quantization issues, parameter loading problems, and weight/bias verification in neural networks.
Methods
- __init__()
__init__()apply(ctxt, executionBlock, name[, verbose])Apply constant tensor printing transformation to an execution block.
dereferenceVars(template, varNames)Dereference the specified variables in the given template.
extractDynamicReferences(ctxt[, ...])Extract all dynamic references from the given execution block.
indexVars(template, varNames, index)Index the specified variables in the given template.
Attributes
parseTreeDict- apply(ctxt: NetworkContext, executionBlock: ExecutionBlock, name: str, verbose: CodeGenVerbosity = CodeGenVerbosity(tilingProfiling=None, untiledProfiling=None)) Tuple[NetworkContext, ExecutionBlock]
Apply constant tensor printing transformation to an execution block.
Analyzes all dynamic references in the execution block and adds debug print statements for constant tensors before the operation execution.
- Parameters:
ctxt (NetworkContext) – The network context containing buffer and type information.
executionBlock (ExecutionBlock) – The execution block to instrument with constant printing code.
name (str) – The name of the operation being instrumented.
verbose (CodeGenVerbosity, optional) – The verbosity level for code generation. Default is _NoVerbosity.
- Returns:
A tuple containing: - The unchanged network context - The modified execution block with constant print statements added
- Return type:
Tuple[NetworkContext, ExecutionBlock]
Notes
The transformation: 1. Extracts all dynamic references from the execution block 2. Filters for constant buffers that have users 3. Adds debug print statements before the operation execution 4. Generates formatted output showing constant tensor metadata and values
- static dereferenceVars(template: Template, varNames: List[str]) None
Dereference the specified variables in the given template.
This function modifies the provided template in place by dereferencing the variables listed in varNames. The template is modified in place.
- Parameters:
template (Template) – The template object to be modified.
varNames (list of str) – List of variable names to dereference within the template.
- extractDynamicReferences(ctxt: NetworkContext, executionBlock: ExecutionBlock = None, unrollStructs=False, includeGlobalReferences=False)
Extract all dynamic references from the given execution block.
- Parameters:
ctxt (NetworkContext) – The network context.
executionBlock (ExecutionBlock, optional) – The execution block.
unrollStructs (bool, optional) – Whether to unroll structs.
includeGlobalReferences (bool, optional) – Whether to include global references.
- Returns:
A list of dynamic references.
- Return type:
List[str]
- static indexVars(template: Template, varNames: List[str], index: str) None
Index the specified variables in the given template.
Modifies the template in place by indexing the specified variable names.
- Parameters:
template (Template) – The template to modify.
varNames (List[str]) – The variable names to index.
index (str) – The index to use.