You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/flows.rst
+19-13Lines changed: 19 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
Optimizer Passes and Flows
3
3
==========================
4
4
5
+
Internal Structure
6
+
------------------
7
+
5
8
The ``hls4ml`` library will parse models from Keras, PyTorch or ONNX into an internal execution graph. This model graph is represented with the
6
9
:py:class:`~hls4ml.model.graph.ModelGraph` class. The nodes in this graph, corresponding to the layer and operations of the input model are represented
7
10
by classes derived from the :py:class:`~hls4ml.model.layers.Layer` base class.
@@ -13,15 +16,17 @@ Layers can define expected attributes and can be verified for correctness, or to
13
16
Optimizer passes
14
17
----------------
15
18
16
-
To reach a state from which the code can be generated, internal model graph will undergo a series of optimizations (transformations), dubbed *optimization passes*.
17
-
All transformations of the model and any modification to any layer's attributes must be implemented through an optimization pass. All optimizer passes derive from
18
-
the :py:class:`~hls4ml.model.optimizer.optimizer.OptimizerPass` class. Optimizer passes are applied at the level of nodes/layers, however a special class
19
-
:py:class:`~hls4ml.model.optimizer.optimizer.ModelOptimizerPass` exists that is applied on the full model. Subclasses of
20
-
:py:class:`~hls4ml.model.optimizer.optimizer.OptimizerPass` must provide a criteria in ``match`` function that, if satisfied, will perform the transformation from
21
-
``transform`` function. The boolean return value of ``transform`` indicates if the optimizer pass made changes to the model graph, requiring running the optimizers again.
22
-
Example of an optimizer pass that runs on the full model, is :py:class:`~hls4ml.model.optimizer.passes.stamp.MakeStamp`, while an example of the layer optimizer is
23
-
:py:class:`~hls4ml.model.optimizer.passes.fuse_biasadd` class that adds a bias to a :py:class:`~hls4ml.model.layers.Dense`,
24
-
:py:class:`~hls4ml.model.layers.Conv1D`, or :py:class:`~hls4ml.model.layers.Conv2D` layer.
19
+
To reach a state from which the code can be generated, the internal model graph undergoes a series of optimizations (transformations), dubbed
20
+
*optimization passes*. All transformations of the model and any modification to any layer's attributes must be implemented through an optimization
21
+
pass. All optimizer passes derive from the :py:class:`~hls4ml.model.optimizer.optimizer.OptimizerPass` class. Optimizer passes are usually applied to
22
+
nodes/layers; however, a special class :py:class:`~hls4ml.model.optimizer.optimizer.ModelOptimizerPass` exists that is applied on the full model. An
23
+
example of a layer optimizer is :py:class:`~hls4ml.model.optimizer.passes.fuse_biasadd`, which adds a bias to a
24
+
:py:class:`~hls4ml.model.layers.Dense`, :py:class:`~hls4ml.model.layers.Conv1D`, or :py:class:`~hls4ml.model.layers.Conv2D` layer, while an example of
25
+
an optimizer pass that runs on the full model is :py:class:`~hls4ml.model.optimizer.passes.stamp.MakeStamp`, which creates a unique number (stamp).
26
+
27
+
Subclasses of :py:class:`~hls4ml.model.optimizer.optimizer.OptimizerPass` must provide a criteria in ``match`` function that, if satisfied, will
28
+
perform the transformation from ``transform`` function. The boolean return value of ``transform`` indicates if the optimizer pass made changes to the
29
+
model graph that may require running the optimizers again. In that case, optimizers in a flow are run again.
25
30
26
31
Optimizers can be general, independent of the backend, in which case they are located in :py:mod:`hls4ml.model.optimizer.passes`, or they may be backend-specific,
27
32
in which case they are located in a folder dependent on the backend, e.g., :py:mod:`hls4ml.backends.vivado.passes` or
@@ -44,10 +49,11 @@ New optimizers can be registered with the :py:func:`~hls4ml.model.optimizer.opti
44
49
45
50
Flows
46
51
-----
47
-
A :py:class:`~hls4ml.model.flow.flow.Flow` is an ordered set of optimizers that represent a single stage in the conversion process. The optimizers from a flow are applied
48
-
until they no longer make changes to the model graph after which the next flow (stage) can start. Flows may depend on other flows being applied before them,
49
-
ensuring the model graph is in a desired state before a flow starts. The function :py:func:`~hls4ml.model.flow.flow.register_flow` is used to register a new flow. Flows
50
-
are applied on a model graph with :py:func:`~hls4ml.model.graph.ModelGraph.apply_flow`.
52
+
A :py:class:`~hls4ml.model.flow.flow.Flow` is an ordered set of optimizers that represent a single stage in the conversion process. The optimizers
53
+
from a flow are applied in sequence until they no longer make changes to the model graph (controlled by the ``transform`` return value), after which
54
+
the next flow (stage) can start. Flows may require that other flows are applied before them, ensuring the model graph is in a desired state before a
55
+
flow starts. The function :py:func:`~hls4ml.model.flow.flow.register_flow` is used to register a new flow. Flows are applied on a model graph with
There are common model-level flows that can run regardless of the backend, and there are backend-specific flows.
53
59
The `convert and optimize <https://github.com/fastmachinelearning/hls4ml/blob/7c0a065935904f50bd7e4c547f85354b36276092/hls4ml/model/optimizer/__init__.py#L14-L20>`_
0 commit comments