Updated partitioning function for PartitionFromDict #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had recently tried building a larger model (~517 nodes) in FINN and got stuck at CreateDataflowPartition for a long time. I did some timing measurements and tracked the longest time spent down to PartitionFromDict. Since I supply a large partition dict for a large model, this step takes a long time. The changes I'd propose here keep the functionality but speed the usage of this transform up a bit:
If the node is not in the graph, the if block is never executed, but this check still runs over the whole graph for every key in the partitioning. Moving the check out before the loop enables an early return in case the node is not in the graph.
Since the index of the node in the graph doesn't change during the function execution, it does not need to be requested in every loop iteration, and so it can be moved out of the loop as well.
For smaller models and partitionings this is negligible, however it helped for my usecase and others might benefit from it as well.