hls4ml.model.optimizer.passes package
Submodules
hls4ml.model.optimizer.passes.bn_fuse module
- class hls4ml.model.optimizer.passes.bn_fuse.FuseBatchNormalization
Bases:
OptimizerPass- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
hls4ml.model.optimizer.passes.fuse_biasadd module
- class hls4ml.model.optimizer.passes.fuse_biasadd.FuseBiasAdd
Bases:
OptimizerPassFuses BiasAdd into Dense/Conv2D layer (common in TF models).
- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
hls4ml.model.optimizer.passes.multi_dense module
- class hls4ml.model.optimizer.passes.multi_dense.ReplaceMultidimensionalDenseWithConv
Bases:
OptimizerPass- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
hls4ml.model.optimizer.passes.nop module
- class hls4ml.model.optimizer.passes.nop.EliminateLinearActivation
Bases:
OptimizerPass- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
hls4ml.model.optimizer.passes.precision_merge module
- class hls4ml.model.optimizer.passes.precision_merge.SetPrecisionConcat
Bases:
OptimizerPass- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Set concat output precision
- hls4ml.model.optimizer.passes.precision_merge.get_concat_type(itype1, itype2)
hls4ml.model.optimizer.passes.qkeras module
- class hls4ml.model.optimizer.passes.qkeras.ApplyAlpha(model, name, attributes, inputs, outputs=None)
Bases:
BatchNormalizationA custom layer to scale the output of a QDense layer which used ‘alpha != 1’ Inference computation uses BatchNormalization methods
- add_bias(bias, quantizer=None)
- add_weights(scale, quantizer=None)
- initialize()
- class hls4ml.model.optimizer.passes.qkeras.ExtractTernaryThreshold
Bases:
OptimizerPassThe input value (threshold) at which the output of a a ternary activation changes is configurable. This pass extracts that threshold point, inserting a BatchNormalization layer to execute the scaling. That BatchNormalization layer is then expected to be fused into a BatchNormalizationQuantizedTanh layer configured with the correct threshold.
- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
- class hls4ml.model.optimizer.passes.qkeras.FuseConsecutiveBatchNormalization
Bases:
OptimizerPassOptimizerPass to merge consecutive BatchNormalization layers. These may exist in a model after QKerasFactorizeAlpha layer. Scale and Bias of each layer are combined into scale and bias of a single layer.
- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
- class hls4ml.model.optimizer.passes.qkeras.OutputRoundingSaturationMode
Bases:
ConfigurableOptimizerPassSet the Rounding and Saturation mode of the output (and accumulator, if applicable) of the layers specific in layer list. The layer list is empty by default. To specify which layer to apply this pass to, perform e.g.: hls4ml.model.optimizer.get_optimizer(‘output_rounding_saturation_mode’).configure(layers=[‘Dense’, ‘Activation’]) The Rounding and Saturation modes are ‘None’ by default (so use the compiler defaults) To set which mode to use: hls4ml.model.optimizer.get_optimizer(‘output_rounding_saturation_mode’).configure(rounding_mode=’AP_RND_CONV’) hls4ml.model.optimizer.get_optimizer(‘output_rounding_saturation_mode’).configure(saturation_mode=’AP_SAT’)
- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- precision_string_modify(pstr)
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
- class hls4ml.model.optimizer.passes.qkeras.QKerasFactorizeAlpha
Bases:
OptimizerPassOptimizerPass for extracting alpha “scale” from QKeras quantized layer. The weights of the Q{Dense, Conv} layer are scaled to the common data type, and an ‘ApplyAlpha’ layer is inserted to reapply the scale.
- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
- class hls4ml.model.optimizer.passes.qkeras.QKerasPO2Quantizer(config)
Bases:
object
- hls4ml.model.optimizer.passes.qkeras.register_qkeras()
hls4ml.model.optimizer.passes.stamp module
- class hls4ml.model.optimizer.passes.stamp.MakeStamp
Bases:
ModelOptimizerPass- transform(model)
Transformation to apply if matching was successful.
Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).
- Parameters
model (ModelGraph) – Model to optimize
node (Layer) – The matched node in the model graph.
hls4ml.model.optimizer.passes.transpose_opt module
- class hls4ml.model.optimizer.passes.transpose_opt.RemoveUselessTranspose
Bases:
OptimizerPass- match(node)
Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
- transform(model, node)
Remove a transpose layer if it doesn’t do anything. i.e 1D input and perm = [0]