forked from mindspore-Ecosystem/mindspore
!34243 DDE coredump: infer public fuction of list append is wrong.
Merge pull request !34243 from lanzhineng/issue
This commit is contained in:
commit
2dbd3b8b14
|
@ -618,7 +618,12 @@ void PurifySequenceValueNode(const CNodePtr &cnode, size_t index, ProgramSpecial
|
|||
}
|
||||
std::vector<size_t> dead_node_positions;
|
||||
ValuePtrList elements;
|
||||
for (size_t i = 0; i < (*flags).size(); ++i) {
|
||||
auto sequence_value_size = sequence_value->value().size();
|
||||
if (flags->size() < sequence_value_size) {
|
||||
MS_LOG(EXCEPTION) << "Inner exception. CNode: " << cnode->ToString() << " input: " << old_input->ToString()
|
||||
<< " flags size: " << flags->size() << " values size: " << sequence_value->value().size();
|
||||
}
|
||||
for (size_t i = 0; i < sequence_value_size; ++i) {
|
||||
ValuePtr old_sequence_value = sequence_value->value()[i];
|
||||
auto old_sequence_str_value = old_sequence_value->cast<StringImmPtr>();
|
||||
if (!(*flags)[i]) {
|
||||
|
@ -848,8 +853,8 @@ AnfNodePtr FuncGraphSpecializer::BuildReplacedNode(const AnfNodeConfigPtr &conf)
|
|||
AddTodoItem(new_conf->node());
|
||||
auto repl = GetReplicatedNode(new_conf->node());
|
||||
if (repl->func_graph()) {
|
||||
MS_LOG(DEBUG) << "Set repl: graph(" << repl->func_graph()->ToString() << "), node:" << repl->DebugString()
|
||||
<< ") to replace origin:" << new_conf->node()->DebugString();
|
||||
MS_LOG(DEBUG) << "Set repl: graph(" << repl->func_graph()->ToString() << "), node: " << repl->DebugString()
|
||||
<< ") to replace origin: " << new_conf->node()->DebugString();
|
||||
} else {
|
||||
MS_LOG(DEBUG) << "Set repl: graph(nullptr), node(" << repl->DebugString()
|
||||
<< ") to replace origin: " << new_conf->node()->DebugString();
|
||||
|
@ -1039,7 +1044,7 @@ std::pair<AbstractBasePtrList, AbstractBasePtr> FuncGraphSpecializer::BuildFromB
|
|||
std::vector<AbstractBasePtrList> args_vector;
|
||||
auto eval_cache_iter = eval_cache_.find(eval);
|
||||
if (eval_cache_iter == eval_cache_.end()) {
|
||||
MS_LOG(EXCEPTION) << "Evaluator:" << eval->ToString() << " not exist in cache.";
|
||||
MS_LOG(EXCEPTION) << "Evaluator: " << eval->ToString() << " not exist in cache.";
|
||||
}
|
||||
auto &origin_eval_cache = eval_cache_iter->second->GetCache();
|
||||
for (auto &argvals_map : origin_eval_cache) {
|
||||
|
|
|
@ -628,10 +628,10 @@ bool AbstractSequence::PurifyElements() {
|
|||
|
||||
// Purify the elements.
|
||||
auto &elements_use_flags = *elements_use_flags_ptr;
|
||||
if (elements_use_flags.size() != elements_.size()) {
|
||||
MS_LOG(EXCEPTION) << "Elements size should be equal to elements use flags size. " << ToString();
|
||||
if (elements_use_flags.size() < elements_.size()) {
|
||||
MS_LOG(EXCEPTION) << "Elements size should not be greater to elements use flags size. " << ToString();
|
||||
}
|
||||
for (size_t i = 0; i < elements_use_flags.size(); ++i) {
|
||||
for (size_t i = 0; i < elements_.size(); ++i) {
|
||||
MS_EXCEPTION_IF_NULL(elements_[i]);
|
||||
if (!elements_use_flags[i]) {
|
||||
const auto unuse_node_none = std::make_shared<AbstractScalar>(std::make_shared<Int32Imm>(0));
|
||||
|
|
|
@ -309,6 +309,10 @@ AbstractBasePtr InferImplListAppend(const AnalysisEnginePtr &, const PrimitivePt
|
|||
}
|
||||
// Add one element in flag list.
|
||||
auto flags = GetSequenceNodeElementsUseFlags(node);
|
||||
MS_EXCEPTION_IF_NULL(flags);
|
||||
if (flags->size() >= new_list.size()) {
|
||||
continue;
|
||||
}
|
||||
(void)flags->emplace_back(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
# Copyright 2021-2022 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
""" test list control flow """
|
||||
import pytest
|
||||
import mindspore.context as context
|
||||
from mindspore import Tensor, dtype
|
||||
from mindspore.nn import Cell
|
||||
import mindspore.ops.operations as P
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Not support list as parameter in while function yet')
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_while_list():
|
||||
"""
|
||||
Feature: list in while.
|
||||
Description: Infer list in while.
|
||||
Expectation: Null.
|
||||
"""
|
||||
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addn = P.AddN()
|
||||
|
||||
def construct(self, x):
|
||||
y = []
|
||||
for _ in range(3):
|
||||
while x < 10:
|
||||
y.append(x)
|
||||
x = self.addn(y)
|
||||
return x
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, save_graphs=True, save_graphs_path="./listir")
|
||||
net = Net()
|
||||
x = Tensor([1], dtype.float32)
|
||||
print(net(x))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_for_list():
|
||||
"""
|
||||
Feature: list for.
|
||||
Description: Infer list in for.
|
||||
Expectation: Null.
|
||||
"""
|
||||
|
||||
def convert_points_to_homogeneous(points):
|
||||
padding = [[0, 0] for _ in range(len(points.shape))]
|
||||
padding[-1][-1] = 1
|
||||
return padding
|
||||
|
||||
class Net(Cell):
|
||||
def construct(self, x1, x2):
|
||||
y1 = convert_points_to_homogeneous(x1)
|
||||
y2 = convert_points_to_homogeneous(x2)
|
||||
return y1, y2
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
x1 = Tensor([[[-1, -1], # left top
|
||||
[1, -1], # right top
|
||||
[-1, 5], # left bottom
|
||||
[1, 5]]], dtype.float32) # right bottom
|
||||
x2 = Tensor([[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.]], dtype.float32)
|
||||
net = Net()
|
||||
print(net(x1, x2))
|
Loading…
Reference in New Issue