提交 a6546b80 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!1147 INFO user when set_strategy not under [semi_]auto_parallel mode

Merge pull request !1147 from yihuaijie/master
......@@ -48,6 +48,7 @@ constexpr double INF = 1e20;
constexpr char AUTO_PARALLEL_RUN_ONCE_ONLY[] = "auto_parallel_run_once_only";
constexpr char SEMI_AUTO_PARALLEL_RUN_ONCE_ONLY[] = "semi_auto_parallel_run_once_only";
constexpr char CHECK_SET_STRATEGY_VALID_ONCE_ONLY[] = "check_set_strategy_valid_once_only";
constexpr char STRATEGY[] = "strategy";
constexpr char GEN_STRATEGY[] = "gen_strategy";
constexpr char REDUCE_OP_SUM[] = "sum";
......
......@@ -333,6 +333,28 @@ bool StrategyFound(std::unordered_map<std::string, ValuePtr> attrs) {
return !((iter == attrs.end()) || (iter->second->type_name() == NONE));
}
bool HasStrategy(const FuncGraphPtr &root) {
AnfNodePtr ret = root->get_return();
MS_EXCEPTION_IF_NULL(ret);
std::vector<AnfNodePtr> all_nodes = DeepScopedGraphSearch(ret);
for (auto &node : all_nodes) {
auto cnode = node->cast<CNodePtr>();
if ((cnode == nullptr) || !IsValueNode<Primitive>(cnode->input(0))) {
continue;
}
ValueNodePtr prim_anf_node = cnode->input(0)->cast<ValueNodePtr>();
PrimitivePtr prim = GetValueNode<PrimitivePtr>(prim_anf_node);
auto attrs = prim->attrs();
if (StrategyFound(attrs)) {
return true;
}
}
return false;
}
bool IsCommunicationOp(const PrimitivePtr &prim) {
MS_EXCEPTION_IF_NULL(prim);
return (COMMUNICATION_OPS.find(prim->name()) != COMMUNICATION_OPS.end());
......@@ -2230,6 +2252,14 @@ bool StepParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &optimizer)
// control whether use model_parallel mode
if (!root->has_flag(AUTO_PARALLEL) || ((parallel_mode != AUTO_PARALLEL) && (parallel_mode != SEMI_AUTO_PARALLEL)) ||
(root->has_flag(SEMI_AUTO_PARALLEL_RUN_ONCE_ONLY))) {
if (!root->has_flag(CHECK_SET_STRATEGY_VALID_ONCE_ONLY)) {
if (HasStrategy(root)) {
MS_LOG(INFO) << "strategies ignored in " << parallel_mode
<< ", set_strategy() only valid in [semi_]auto_parallel.";
}
root->flags()[CHECK_SET_STRATEGY_VALID_ONCE_ONLY] = true;
}
return changes;
}
......@@ -2287,6 +2317,9 @@ bool StepParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &optimizer)
root->flags()[SEMI_AUTO_PARALLEL_RUN_ONCE_ONLY] = true;
res->results()[pipeline::kStepParallelGraph] = root;
// in auto parallel mode, no need to check if stategies set
root->flags()[CHECK_SET_STRATEGY_VALID_ONCE_ONLY] = true;
(void)gettimeofday(&end_time, nullptr);
uint64_t time = kUSecondInSecond * static_cast<uint64_t>(end_time.tv_sec - start_time.tv_sec);
time += static_cast<uint64_t>(end_time.tv_usec - start_time.tv_usec);
......
......@@ -111,6 +111,7 @@ class Primitive(Primitive_):
Note:
Valid only in semi auto parallel or auto parallel mode.
In other parallel modes, strategies will be ignored if set.
Args:
strategy (tuple): Strategy describes the distributed parallel mode of the current primitive.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册