Skip to content

Commit

Permalink
Merge branch 'main' into torch-profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
JanFSchulte authored Jan 10, 2025
2 parents d1a6b35 + 3fa2902 commit f49c831
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
args: ["--profile", "black", --line-length=125]

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]
Expand Down
7 changes: 6 additions & 1 deletion hls4ml/model/optimizer/passes/convert_to_channels_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ def transform(self, model, node):
if (
isinstance(node, Reshape)
and len(node.attributes['target_shape']) == 1
and not model.config.config['HLSConfig']['Model']['ChannelsLastConversion'] == "internal"
and not model.config.config['HLSConfig']['Model']['ChannelsLastConversion'] == "off"
):
previous_node = node.get_input_node(node.inputs[0])
input = previous_node.name
outshape = previous_node.get_output_variable().shape

if (model.config.config['IOType'] == 'io_stream') and len(outshape) == 3:
raise Exception(
'No 3D transpose available in io_stream, this model cannot be converted to channels-last'
)

if len(outshape) == 2:
attributes = {'perm': [1, 0]}
else:
Expand Down
2 changes: 1 addition & 1 deletion hls4ml/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def config_from_pytorch_model(
default_precision='ap_fixed<16,6>',
default_reuse_factor=1,
channels_last_conversion='full',
transpose_outputs=True,
transpose_outputs=False,
max_precision=None,
):
"""Create an HLS conversion config given the PyTorch model.
Expand Down
2 changes: 2 additions & 0 deletions hls4ml/writer/vivado_accelerator_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def write_board_script(self, model):
f.write('set clock_uncertainty {}\n'.format(model.config.get_config_value('ClockUncertainty', '12.5%')))
f.write('variable version\n')
f.write('set version "{}"\n'.format(model.config.get_config_value('Version', '1.0.0')))
f.write('variable maximum_size\n')
f.write('set maximum_size {}\n'.format(model.config.get_config_value('MaximumSize', '4096')))
if self.vivado_accelerator_config.get_interface() == 'axi_stream':
in_bit, out_bit = self.vivado_accelerator_config.get_io_bitwidth()
f.write(f'set bit_width_hls_output {in_bit}\n')
Expand Down
2 changes: 1 addition & 1 deletion test/pytest/test_pytorch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def test_pooling(pooling, padds, backend):
model.eval()
pytorch_prediction = model(torch.Tensor(X_input)).detach().numpy()

config = config_from_pytorch_model(model, input_shape_forHLS)
config = config_from_pytorch_model(model, input_shape_forHLS, transpose_outputs=True)
output_dir = str(test_root_path / f'hls4mlprj_pytorch_api_pooling_{pooling.__name__}_padds_{padds}_backend_{backend}')
hls_model = convert_from_pytorch_model(model, hls_config=config, output_dir=output_dir, backend=backend)
hls_model.compile()
Expand Down

0 comments on commit f49c831

Please sign in to comment.