Skip to content

Fix for cloned stream that is subsequently flattened #708

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 14 commits into from
Mar 30, 2023
Merged

Conversation

jmduarte
Copy link
Member

@jmduarte jmduarte commented Feb 2, 2023

Description

Fixes #707. The issue is if a cloned stream is subsequently flattened, the original stream is used later instead of the clone. I think this is because the InplaceVariable is not correctly updated.

Somewhat related, there is also a bug in concatenate1d when you consider the case that a stream is not truly from a 1D array, but from a flattened 2D array. I tried to use @rfforelli's fix for this, but it seems to not be quite working. Maybe he has some input?

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Tests

  • Added a test that should fail on main but succeed on this branch

Test Configuration:

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added. (to be done later)
  • I have added tests that prove my fix is effective or that my feature works.

@jmduarte jmduarte added the bug label Feb 2, 2023
@jmitrevs
Copy link
Contributor

jmitrevs commented Feb 2, 2023

Flatten is one of the operations that often breaks in the current main branch. The qonnx branch has quite a few fixes there, because the inplace variable as is in main is generally broken when working with optimizers. It sets what the inplace variable points to too early, and optimizers often break this. Let me take a look more carefully at this fix.

@jmitrevs
Copy link
Contributor

jmitrevs commented Feb 2, 2023

I actually have the test fail in main, ingest-qonnx-master, and clone_flatten branches, but I think the form of the code in myproject.cpp produced by both the ingest-qonnx-master and clone_flatten branches seems correct. I would recommend using the ingest-qonnx-master branch for these cases, because as I mentioned, inplace variables are broken in main.

@jmduarte
Copy link
Member Author

jmduarte commented Feb 2, 2023

OK, the new test should now succeed in clone_flatten but fail in main.

The test fails in main for two reasons: (1) the InplaceVariable problem and (2) the incorrect concatenate1d HLS code for the case when the input stream depth is not the same as full size of the array (e.g. if they are from flattened 2D streams).

This PR has a band-aid solution for (1) and a good solution for (2).

Perhaps, the best way to proceed is

  • Check that if we add the solution to (2) to the ingest-qonnx-master, the test passes.
  • If so, then we update this PR to just solve (2) since (1) will be solved by the more general ingest-qonnx-master fixes.
  • We can also add the new test to the ingest-qonnx-master branch (after it's rebased to include changes from this branch).

@jmitrevs
Copy link
Contributor

jmitrevs commented Feb 2, 2023

If I copy nnet_merge_stream.h from clone_flatten to ingest-qonnx-master, the test passes there. So (2) is definitely a bug to fix. I think I'll try to extract the inplace variable stuff from from ingest-qonnx-master and make it a separate PR, in order to make the merging of that PR easier.

One thing, can you check if the same fix is needed for quartus? On a first glance it looks to me like it's needed there, too. The code is at https://github.com/fastmachinelearning/hls4ml/blob/main/hls4ml/templates/quartus/firmware/nnet_utils/nnet_merge_stream.h#L139-L165.

@jmitrevs jmitrevs mentioned this pull request Feb 14, 2023
8 tasks
@jmitrevs jmitrevs added this to the v0.7.0 milestone Feb 16, 2023
@jmduarte jmduarte self-assigned this Mar 4, 2023
@jmduarte
Copy link
Member Author

jmduarte commented Mar 4, 2023

@jmitrevs OK, I confirm that the added test (including Quartus) passes if I merge this branch with #714. So should we plan to merge them both at the same time?

@jmduarte jmduarte requested a review from jmitrevs March 4, 2023 15:53
Copy link
Contributor

@jmitrevs jmitrevs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix pre-commit, and I will approve.

@vloncar
Copy link
Contributor

vloncar commented Mar 7, 2023

What's the deal with the failed test?

@jmitrevs
Copy link
Contributor

jmitrevs commented Mar 8, 2023

I assume the failed tests are ones that succeed when #714 is also merged.

@vloncar vloncar added the please test Trigger testing by creating local PR branch label Mar 30, 2023
@jmduarte jmduarte added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Mar 30, 2023
@vloncar vloncar merged commit 7c0a065 into main Mar 30, 2023
@vloncar vloncar deleted the clone_flatten branch March 30, 2023 19:37
JanFSchulte pushed a commit to JanFSchulte/hls4ml that referenced this pull request May 23, 2023
…ning#708)

* add failing test; update pre-commit to run on 3.8

* update

* update

* remove formatting for now

* spacing

* fix from ryan

* rm bandaid solution

* update quartus

* add quartus test

* add quartus

* pre-commit

* pre-commit

---------

Co-authored-by: Jovan Mitrevski <[email protected]>
calad0i pushed a commit to calad0i/hls4ml that referenced this pull request Jul 1, 2023
…ning#708)

* add failing test; update pre-commit to run on 3.8

* update

* update

* remove formatting for now

* spacing

* fix from ryan

* rm bandaid solution

* update quartus

* add quartus test

* add quartus

* pre-commit

* pre-commit

---------

Co-authored-by: Jovan Mitrevski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloned HLS stream is read from twice. Second duplicate stream is left full.
4 participants