Skip to content

Fix profiling for GRU/LSTM #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions hls4ml/model/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seaborn as sb

from hls4ml.model.graph import ModelGraph
from hls4ml.model.layers import GRU, LSTM

try:
import qkeras
Expand Down Expand Up @@ -172,7 +173,6 @@ def ap_fixed_WIFS(dtype):


def types_hlsmodel(model):
suffix = ['w', 'b']
data = {'layer': [], 'low': [], 'high': []}
# Plot the default precision
default_precision = model.config.model_precision['default']
Expand All @@ -182,6 +182,10 @@ def types_hlsmodel(model):
data['high'].append(I - 1 if S else I)

for layer in model.get_layers():
if isinstance(layer, GRU) or isinstance(layer, LSTM):
suffix = ['w', 'rw', 'b', 'rb']
else:
suffix = ['w', 'b']
for iw, weight in enumerate(layer.get_weights()):
wname = f'{layer.name}/{suffix[iw]}'
T = weight.type
Expand Down Expand Up @@ -213,13 +217,16 @@ def activation_types_hlsmodel(model):


def weights_hlsmodel(model, fmt='longform', plot='boxplot'):
suffix = ['w', 'b']
if fmt == 'longform':
data = {'x': [], 'layer': [], 'weight': []}
elif fmt == 'summary':
data = []

for layer in model.get_layers():
if isinstance(layer, GRU) or isinstance(layer, LSTM):
suffix = ['w', 'rw', 'b', 'rb']
else:
suffix = ['w', 'b']
name = layer.name
for iw, weight in enumerate(layer.get_weights()):
label = f'{name}/{suffix[iw]}'
Expand Down