hls4ml.model.optimizer package
Subpackages
- hls4ml.model.optimizer.passes package
- Submodules
- hls4ml.model.optimizer.passes.bn_fuse module
- hls4ml.model.optimizer.passes.fuse_biasadd module
- hls4ml.model.optimizer.passes.multi_dense module
- hls4ml.model.optimizer.passes.nop module
- hls4ml.model.optimizer.passes.precision_merge module
- hls4ml.model.optimizer.passes.qkeras module
- hls4ml.model.optimizer.passes.stamp module
- hls4ml.model.optimizer.passes.transpose_opt module
- Module contents
Submodules
hls4ml.model.optimizer.optimizer module
-
class
hls4ml.model.optimizer.optimizer.ConfigurableOptimizerPass Bases:
hls4ml.model.optimizer.optimizer.OptimizerPassAn optimizer that can be configured.
Existing instances of this class in the registry can be configured with the configure() method. Multiple instances with different configuration can co-exist if registered with different names.
-
configure(**kwargs)
-
get_config()
-
-
class
hls4ml.model.optimizer.optimizer.GlobalOptimizerPass Bases:
hls4ml.model.optimizer.optimizer.OptimizerPassGlobal optimizer that matches on every node in the model graph.
-
class
hls4ml.model.optimizer.optimizer.LayerOptimizerPass(name, layer_class, transform) Bases:
hls4ml.model.optimizer.optimizer.WrappedOptimizerPassAn wrapper optimizer specific to a layer class.
Commonly used by backends to add extra initialization to a layer instance.
-
class
hls4ml.model.optimizer.optimizer.ModelOptimizerPass(name, transform) Bases:
hls4ml.model.optimizer.optimizer.OptimizerPassA special optimizer that works with the model itself.
Examples include writing the model to C++/HLS.
-
class
hls4ml.model.optimizer.optimizer.OptimizerPass Bases:
objectBase optimizer class from which all other optimizer types are derived.
-
classmethod
get_name()
-
match(node) Predicate to match on a given node.
- Parameters
node (Layer) – Node in the model graph to try matching the optimizer on.
-
name= None
-
classmethod
-
class
hls4ml.model.optimizer.optimizer.WrappedOptimizerPass(name, condition, transform) Bases:
hls4ml.model.optimizer.optimizer.OptimizerPassAn optimizer class created by wrapping a function call.
Users should generally not create any wrapped optimizer passes manually.
-
get_name()
-
-
hls4ml.model.optimizer.optimizer.extract_optimizers_from_object(clazz)
-
hls4ml.model.optimizer.optimizer.extract_optimizers_from_path(opt_path, module_path, initializer=None)
-
hls4ml.model.optimizer.optimizer.get_available_passes() Return the list of all registered optimizer passes.
- Returns
List of registered passes.
- Return type
list
-
hls4ml.model.optimizer.optimizer.get_backend_passes(backend) Returns the list of optimizer passes belonging to a backend
- Parameters
backend (str) – Name of the backend.
- Returns
List of optimizer names registered with the given backend.
- Return type
list
-
hls4ml.model.optimizer.optimizer.get_optimizer(name) Return the optimizer instance registered with the given name.
- Parameters
name (str) – Name of the optimizer in the registry.
- Raises
Exception – If the optimizer with the given name is not found in the registry.
- Returns
The optimizer from the registry.
- Return type
-
hls4ml.model.optimizer.optimizer.layer_optimizer(layer) Decorator to turn a function into the optimization pass.
Example
@layer_optimizer(MyLayer) def init_mylayer(self, layer):
layer.set_attr(‘new_attribute’, ‘some_value’)
- Parameters
layer (_type_) – _description_
-
hls4ml.model.optimizer.optimizer.model_optimizer() Decorator to turn a function into a model optimizer.
-
hls4ml.model.optimizer.optimizer.optimize_model(model, passes) Optimize a given model with the given passes.
The passes are attempted until all passes no longer match or no changes to the model graph occur.
- Parameters
model (ModelGraph) – The model to optimize.
passes (list) – List of passes to apply.
- Returns
The set of applied passes (the pases that matched the predicate).
- Return type
set
-
hls4ml.model.optimizer.optimizer.optimizer_pass(condition)
-
hls4ml.model.optimizer.optimizer.register_pass(name, opt_cls, backend=None) Register a new optimizer pass.
- Parameters
name (str) – Name of the optimizer
opt_cls (class) – The class of the optimizer.
backend (str, optional) – Optional backend to register the optimizer to. If not None, the name of the backend will be appended to the name of the registered flow. Defaults to None.
- Raises
Exception – If the optimization pass has already been registered with the given name.
- Returns
The name of the registered optimizer.
- Return type
str