fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.19k stars 390 forks source link

Don't use reader in ModelGraph and layers #770

Closed vloncar closed 1 year ago

vloncar commented 1 year ago

Description

Currently, adding weights data happens during initialization of layers by using the supplied reader. This is a relic of old design that required splitting this from converter. Upcoming ONNX support and nested model require this step to be done during conversion. This PR removes reader from ModelGraph and its subsequent use to read weights data. This is now moved to converters themselves and weights data is available as an attribute.

Type of change

Tests

This just changes the existing functionality so existing tests should verify that it works as expected

Checklist

jmitrevs commented 1 year ago

Is this ready for review? My initial impression is positive, but I need to look more carefully.

vloncar commented 1 year ago

It is ready for review. Note that by accident I left in a definition of KerasNestedFileReader in keras_to_hls.py that is not used by the rest of the code. The followup PR that adds support for nested models makes use of it. I'll make that PR once this one is merged.

jmitrevs commented 1 year ago

onnx_to_hls, pytorch_to_hls, and tf_to_hls still pass the reader to ModelGraph. They will no longer work with this change. Are they not changed because others (e.g. me for ONNX) will fix this and changing it will make a merge conflict?

By the way, what's the status of tf_to_hls? Does anyone support it?

vloncar commented 1 year ago

We agreed that the changes to onnx and pytorch will come after this merge, since both need to be updated. tf_to_hls is not supported anymore, no one uses it, it relies on old v1 compatibility so it is not worth maintaining in its current form.

jmitrevs commented 1 year ago

Sounds good. I will make a few more checks and likely merge this. As a separate PR we may consider removing tf_to_hls afterwards.

jmitrevs commented 1 year ago

Is there a convention enforced with _data?