Skip to content
Snippets Groups Projects

Improve Remove Flatten

Merged Cyril Moineau requested to merge ImproveRemoveFlatten into dev
1 unresolved thread

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
39
40 40 void removeFlatten(std::shared_ptr<GraphView> graphView){
41
42
43 std::shared_ptr<GraphRegex> regex = std::make_shared<GraphRegex>();
44 regex->setNodeKey("Flatten","getType($) =='Flatten'");
45 regex->setNodeKey("FC","getType($) =='FC'");
46 regex->addQuery("Flatten->FC");
41 const auto matches = SinglePassGraphMatching(graphView).match(
42 "(FC|MatMul)<-(Flatten)+"
43 );
47 44
48 for (const auto& solution : regex->match(graphView)) {
49 removeFlatten(solution);
45 for (const auto& solution : matches) {
46 removeFlatten(solution.graph->getNodes());
  • Suggestion: replace the removeFlatten function with 2 lines:

    auto flattenNodes(solution.graph->getNodes());
    flattenNodes.erase(solution.graph->rootNode());
    GraphView::replace(flattenNodes, {});

    The root node is garanteed to be FC or MatMul, the other nodes are garanteed to be Flatten node.

  • Author Maintainer

    Why is the root node guaranteed to be FC or MatMul ? From the documentation:

    There is a root node in the GraphView (by default, the first node added to it), and nodes inside a GraphView can be ranked with a unique and deterministic order if the nodes form a single connected graph;

    So is it because by construction of the GraphMatching algorithm, the graph is built with nodes declared from left to right in the query ? If so is this behavior documented ?

    Also, I am not in favor of using this mechanism has I find that it limit the readability of the code. If we use the proposed implementation, I think a explanation comment would be required.

  • Yep, it is documented: "The first node of the first sequence is the root node and cannot be optional" (by construction in the GraphMatching). It is an important feature.

    Edited by Olivier BICHLER
  • Author Maintainer

    I think the suggestion is dependant on the current implementation which may change in the future. Furthermore, I find it less readable.

    Do you agree on skipping the suggestion or do you want me to apply it ?

    The MR is ready for review and then merge :smile:

  • The implementation regarding root node will not change in the future. It is an important feature of graph matching and I already rely on it heavily. I would prefer to keep the proposed suggestion, perhaps with the right comment, as I find it more idiomatic of how graph matching should be used (meaning, ideally, without having to re-iterate through the matched nodes and check their type).

    Also, there is no purpose of keeping a sub-function anymore...

    Edited by Olivier BICHLER
  • Cyril Moineau changed this line in version 5 of the diff

    changed this line in version 5 of the diff

  • Author Maintainer

    I added the proposed changes, I propose to merge this MR.

  • Please register or sign in to reply
  • Cyril Moineau added 11 commits

    added 11 commits

    • 20abe188...f410ee54 - 9 commits from branch dev
    • 4bba1745 - Merge branch 'dev' into ImproveRemoveFlatten
    • 441b4bde - Remove old GraphRegex to use new GraphMatching in unit test.

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Cyril Moineau added 1 commit

    added 1 commit

    • e4d3416c - Update remove flatten tests.

    Compare with previous version

  • requested review from @olivierbichler

  • Cyril Moineau added 1 commit

    added 1 commit

    • 04231e35 - Applied proposed change in...

    Compare with previous version

  • Olivier BICHLER added 32 commits

    added 32 commits

    • 04231e35...7f1ba66c - 27 commits from branch dev
    • a551865e - Remove Flatten now use new graphmatching + remove Flatten beofre MatMul + remove multiple Flatten.
    • b1097ce8 - Remove old GraphRegex to use new GraphMatching in unit test.
    • 2659ce34 - Fixed GraphMatching
    • 7f304045 - Update remove flatten tests.
    • 515ef7d5 - Applied proposed change in...

    Compare with previous version

  • Olivier BICHLER approved this merge request

    approved this merge request

  • Olivier BICHLER enabled an automatic merge when the pipeline for 515ef7d5 succeeds

    enabled an automatic merge when the pipeline for 515ef7d5 succeeds

  • mentioned in commit 45cd45cc

  • Please register or sign in to reply
    Loading