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/advanced/extension.rst
+2-5Lines changed: 2 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ Extension API
5
5
``hls4ml`` natively supports a large number of neural network layers.
6
6
But what if a desired layer is not supported?
7
7
If it is standard enough and its implementation would benefit the community as a whole, we would welcome a contribution to add it to the standard set of supported layers.
8
-
However, if it is a somewhat niche custom layer, there is another approach we can take to extend hls4ml through the *extension API*.
8
+
However, if it is a somewhat niche custom layer, there is another approach we can take to extend hls4ml through the *extension API*. This feature is support for both keras and pytorch layers.
9
9
10
-
This documentation will walk through a complete `complete end-to-end example <https://github.com/fastmachinelearning/hls4ml/blob/main/test/pytest/test_extensions.py>`_, which is part of our testing suite.
10
+
Complete end-to-end examples are available for both `keras <https://github.com/fastmachinelearning/hls4ml/blob/main/test/pytest/test_extensions.py>`_ and `pytorch <https://github.com/fastmachinelearning/hls4ml/blob/main/test/pytest/test_extensions_pytorch.py>`_, which are part of our testing suite. The description here uses the keras example.
11
11
To implement a custom layer in ``hls4ml`` with the extension API, the required components are:
12
12
13
13
* Your custom layer class
@@ -18,9 +18,6 @@ To implement a custom layer in ``hls4ml`` with the extension API, the required c
18
18
* Function config template
19
19
* Registration of layer, source code, and templates
20
20
21
-
.. note::
22
-
currently, then extension API supports keras models. Support for pytorch models is in development.
Once converted to an HLS project, you can connect the project into the Python runtime and use it to run predictions on a numpy array:
101
+
102
+
.. code-block:: python
103
+
104
+
import numpy as np
105
+
106
+
# Compile the hls project and link it into the Python runtime
107
+
hls_model.compile()
108
+
109
+
# Generate random input data
110
+
X_input = np.random.rand(100, 16)
85
111
86
-
#Print full list of example model if you want to explore more
87
-
hls4ml.utils.fetch_example_list()
112
+
#Run the model on the input data
113
+
hls_prediction = hls_model.predict(X_input)
88
114
89
-
After that, you can use :code:`Vivado HLS` to synthesize the model:
115
+
After that, you can use :code:`Vitis HLS` to synthesize the model:
90
116
91
117
.. code-block:: python
92
118
93
-
# Use Vivado HLS to synthesize the model
119
+
# Use Vitis HLS to synthesize the model
94
120
# This might take several minutes
95
121
hls_model.build()
96
122
97
-
#Print out the report if you want
123
+
#Optional: print out the report
98
124
hls4ml.report.read_vivado_report('my-hls-test')
99
125
100
126
Done! You've built your first project using ``hls4ml``! To learn more about our various API functionalities, check out our tutorials `here <https://github.com/fastmachinelearning/hls4ml-tutorial>`__.
0 commit comments