Skip to content
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

The order issue of graph_helper's unordered_set #16688

Closed
yihuaxu opened this issue Apr 4, 2019 · 1 comment · Fixed by #16756
Closed

The order issue of graph_helper's unordered_set #16688

yihuaxu opened this issue Apr 4, 2019 · 1 comment · Fixed by #16756
Labels

Comments

@yihuaxu
Copy link
Contributor

yihuaxu commented Apr 4, 2019

在复现ISSUE#16316时候发现,graph_helper里使用了unordered_set来保存节点,但是发现unordered_set元素的插入顺序和再重新读出来的顺序不一致。
   1)PaddlePaddle版本: 76b49f0
   2)CPU: No AVX / No MKLML
   3)系统环境: CI 节点 yq01-gpu-255-134-14-04
   4)尝试解决思路:
           将排序部分移至graph转program之前或是将unordered_set改为vector。
   5)Log Patch:

        diff --git a/paddle/fluid/framework/ir/graph_helper.cc b/paddle/fluid/framework/ir/graph_helper.cc
        index 28a37f3..b54e396 100644
        --- a/paddle/fluid/framework/ir/graph_helper.cc
        +++ b/paddle/fluid/framework/ir/graph_helper.cc
        @@ -143,8 +143,20 @@ std::map<ir::Node *, std::unordered_set<ir::Node *>>                       BuildOperationAdjList(
             std::sort(nodes.begin(), nodes.end(), [](ir::Node *node1, ir::Node *node2) {
               return node1->id() > node2->id();
     });
        +    std::cout << "vector ";
        +    for (auto it = nodes.begin(); it != nodes.end(); it++) {
        +      std::cout << "node id " << (*it)->id() << ", name " << (*it)->Name()
        +                << ", ";
        +    }
        +    std::cout << std::endl;
             adj_list[n].insert(std::make_move_iterator(nodes.begin()),
                                std::make_move_iterator(nodes.end()));
        +    std::cout << "unordered_set ";
        +    for (auto it = adj_list[n].begin(); it != adj_list[n].end(); it++) {
        +      std::cout << "node id " << (*it)->id() << ", name " << (*it)->Name()
        +                << ", ";
        +    }
        +    std::cout << std::endl;
           }
           return adj_list;
         }
6)Log:
        [08:42:22] :	 [Step 1/1] 131: **vector node id 717, name assign, node id 715, name assign, node id 695, name assign,** node id 693, name assign, node id 673, name assign, node id 671, name assign, node id 651, name assign, node id 649, name assign, node id 629, name assign, node id 627, name assign, node id 607, name assign, node id 605, name assign, node id 585, name fill_constant_batch_size_like, node id 583, name fill_constant_batch_size_like, node id 581, name fill_constant_batch_size_like, node id 579, name fill_constant_batch_size_like, node id 577, name fill_constant_batch_size_like, node id 575, name fill_constant_batch_size_like, node id 573, name fill_constant_batch_size_like, node id 571, name fill_constant_batch_size_like, node id 569, name fill_constant_batch_size_like, node id 567, name fill_constant_batch_size_like, node id 565, name fill_constant_batch_size_like, node id 563, name fill_constant_batch_size_like, node id 561, name write_to_array, node id 559, name write_to_array, node id 554, name less_than, node id 552, name fill_constant, node id 550, name fill_constant, node id 3, name feed, node id 0, name feed, 
        [08:42:22] :	 [Step 1/1] 131: unordered_set node id 0, name feed, node id 3, name feed, node id 550, name fill_constant, node id 552, name fill_constant, node id 559, name write_to_array, node id 554, name less_than, node id 563, name fill_constant_batch_size_like, node id 565, name fill_constant_batch_size_like, node id 567, name fill_constant_batch_size_like, node id 569, name fill_constant_batch_size_like, node id 571, name fill_constant_batch_size_like, node id 573, name fill_constant_batch_size_like, node id 575, name fill_constant_batch_size_like, node id 577, name fill_constant_batch_size_like, node id 605, name assign, node id 607, name assign, node id 579, name fill_constant_batch_size_like, node id 581, name fill_constant_batch_size_like, node id 583, name fill_constant_batch_size_like, node id 585, name fill_constant_batch_size_like, node id 649, name assign, node id 651, name assign, node id 671, name assign, node id 673, name assign, node id 627, name assign, node id 693, name assign, node id 629, name assign, node id 695, **name assign, node id 715, name assign, node id 561, name write_to_array, node id 717, name assign**,
7)相关链接:

       https://stackoverflow.com/questions/41334952/how-does-unordered-set-determine-the-inserting-order-in-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants