Browse Source

Bugfix in ConvertNonscalarTensorToParameter

In the last commit (015d7354c7), I deleted the check on whether different ValueNode have
same tensor value, but forgot the situation that several nodes use the same ValueNode,
in this case, the function will create several parameter for the same ValueNode, but all
ValueNode is replaced with the first parameter, and the remaining parameters are not used.
This will result in a "parameter has no user" error.
Use a std::set for the ValueNodes can resolve this problem.
tags/v1.6.0
dayschan 4 years ago
parent
commit
174e4ea3ce
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      mindspore/ccsrc/backend/optimizer/graph_kernel/core/graph_builder.cc

+ 3
- 2
mindspore/ccsrc/backend/optimizer/graph_kernel/core/graph_builder.cc View File

@@ -18,6 +18,7 @@
#include <algorithm>
#include <memory>
#include <tuple>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>
@@ -103,7 +104,7 @@ void EliminateMakeTuple(const FuncGraphPtr &fg) {

bool ConvertNonscalarTensorToParameter(const FuncGraphPtr &fg, AnfNodePtrList *inputs_ptr) {
auto cnodes = fg->GetOrderedCnodes();
AnfNodePtrList value_nodes;
std::set<AnfNodePtr> value_nodes;
for (const auto &cnode : cnodes) {
auto &inputs = cnode->inputs();
for (size_t i = 1; i < inputs.size(); ++i) {
@@ -112,7 +113,7 @@ bool ConvertNonscalarTensorToParameter(const FuncGraphPtr &fg, AnfNodePtrList *i
if (tensor == nullptr || tensor->DataSize() == 1) {
continue;
}
value_nodes.push_back(tnode);
value_nodes.insert(tnode);
}
}
if (value_nodes.empty()) return false;


Loading…
Cancel
Save