Skip to content
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

Support multiple outputs in pytorch parser #1151

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions hls4ml/converters/pytorch/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def parse_squeeze_layer(operation, layer_name, input_names, input_shapes, node,
layer = {}
layer['class_name'] = 'Reshape'
layer['name'] = layer_name
layer['inputs'] = input_names

if len(node.args) > 1 or len(node.kwargs) > 0: # 'dim' argument is specified
output_shape = [i for i in input_shapes[0]]
Expand Down
18 changes: 15 additions & 3 deletions hls4ml/converters/pytorch_to_hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def parse_pytorch_model(config, verbose=True):
inputs_map = {}

input_layers = []
output_layers = []

# Output shape tracking
output_shapes = {}
Expand Down Expand Up @@ -365,11 +366,22 @@ def parse_pytorch_model(config, verbose=True):
if len(input_layers) == 0:
input_layers = None

return layer_list, input_layers
for layer in layer_list:
if layer['class_name'] == 'InputLayer':
continue
is_input = False
for lay in layer_list:
if 'inputs' not in lay.keys():
continue
if layer['name'] in lay['inputs']:
is_input = True
if not is_input:
output_layers.append(layer['name'])
return layer_list, input_layers, output_layers


def pytorch_to_hls(config):
layer_list, input_layers = parse_pytorch_model(config)
layer_list, input_layers, output_layers = parse_pytorch_model(config)
print('Creating HLS model')
hls_model = ModelGraph(config, layer_list, inputs=input_layers)
hls_model = ModelGraph(config, layer_list, inputs=input_layers, outputs=output_layers)
return hls_model
1 change: 1 addition & 0 deletions hls4ml/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def config_from_pytorch_model(
(
layer_list,
_,
_,
) = parse_pytorch_model(config, verbose=False)

def make_layer_config(layer):
Expand Down
Loading