[CPU] Graph::DropNode fix (#17702)
This commit is contained in:
1 parent
f2017e8c2e
commit
b167460fe3
2 files changed
+87
-63
No files matched your search
@@ -1408,27 +1408,20 @@ void Graph::DropNode(const NodePtr &node) {
|
||||
auto parent = p_edge->getParent();
|
||||
if (!parent) continue;
|
||||
|
||||
for (size_t j = 0; j < children.size(); j++) {
|
||||
if (!children[j].lock())
|
||||
continue;
|
||||
auto child = children[j].lock()->getChild();
|
||||
if (!child)
|
||||
continue;
|
||||
const int inNum = p_edge->getInputNum();
|
||||
p_edge->drop();
|
||||
RemoveEdge(p_edge);
|
||||
|
||||
for (size_t j = 0; j < children.size(); j++) {
|
||||
auto c_edge = children[j].lock();
|
||||
if (!c_edge) continue;
|
||||
auto child = c_edge->getChild();
|
||||
if (!child) continue;
|
||||
|
||||
const int outNum = c_edge->getOutputNum();
|
||||
c_edge->drop();
|
||||
RemoveEdge(c_edge);
|
||||
|
||||
EdgePtr &remEdge = p_edge;
|
||||
int inNum = 0;
|
||||
if (remEdge) {
|
||||
inNum = remEdge->getInputNum();
|
||||
remEdge->drop();
|
||||
RemoveEdge(remEdge);
|
||||
}
|
||||
remEdge = children[j].lock();
|
||||
int outNum = 0;
|
||||
if (remEdge) {
|
||||
outNum = remEdge->getOutputNum();
|
||||
remEdge->drop();
|
||||
RemoveEdge(remEdge);
|
||||
}
|
||||
EdgePtr newEdge(new Edge(parent, child, inNum, outNum));
|
||||
graphEdges.push_back(newEdge);
|
||||
parent->addEdge(newEdge);
|
||||
@@ -1453,27 +1446,20 @@ void Graph::DropDWConvNode(const NodePtr &node) {
|
||||
auto parent = p_edge->getParent();
|
||||
if (!parent) continue;
|
||||
|
||||
for (size_t j = 0; j < children.size(); j++) {
|
||||
if (!children[j].lock())
|
||||
continue;
|
||||
auto child = children[j].lock()->getChild();
|
||||
if (!child)
|
||||
continue;
|
||||
const int inNum = p_edge->getInputNum();
|
||||
p_edge->drop();
|
||||
RemoveEdge(p_edge);
|
||||
|
||||
for (size_t j = 0; j < children.size(); j++) {
|
||||
auto c_edge = children[j].lock();
|
||||
if (!c_edge) continue;
|
||||
auto child = c_edge->getChild();
|
||||
if (!child) continue;
|
||||
|
||||
const int outNum = c_edge->getOutputNum();
|
||||
c_edge->drop();
|
||||
RemoveEdge(c_edge);
|
||||
|
||||
EdgePtr &remEdge = p_edge;
|
||||
int inNum = 0;
|
||||
if (remEdge) {
|
||||
inNum = remEdge->getInputNum();
|
||||
remEdge->drop();
|
||||
RemoveEdge(remEdge);
|
||||
}
|
||||
remEdge = children[j].lock();
|
||||
int outNum = 0;
|
||||
if (remEdge) {
|
||||
outNum = remEdge->getOutputNum();
|
||||
remEdge->drop();
|
||||
RemoveEdge(remEdge);
|
||||
}
|
||||
EdgePtr newEdge(new Edge(parent, child, inNum, outNum));
|
||||
graphEdges.push_back(newEdge);
|
||||
parent->addEdge(newEdge);
|
||||
@@ -1486,16 +1472,11 @@ void Graph::DropDWConvNode(const NodePtr &node) {
|
||||
auto parent = p_edge->getParent();
|
||||
if (!parent) continue;
|
||||
|
||||
EdgePtr &remEdge = p_edge;
|
||||
int inNum = 0;
|
||||
int portCandidate = 0;
|
||||
if (remEdge) {
|
||||
inNum = remEdge->getInputNum();
|
||||
portCandidate = remEdge->getOutputNum();
|
||||
remEdge->drop();
|
||||
RemoveEdge(remEdge);
|
||||
}
|
||||
int outNum = parentConv->parentEdges.size();
|
||||
const int inNum = p_edge->getInputNum();
|
||||
const int portCandidate = p_edge->getOutputNum();
|
||||
p_edge->drop();
|
||||
RemoveEdge(p_edge);
|
||||
const int outNum = parentConv->parentEdges.size();
|
||||
|
||||
EdgePtr newEdge(new Edge(parent, parentConv, inNum, outNum));
|
||||
graphEdges.push_back(newEdge);
|
||||
|
||||
@@ -62,20 +62,58 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
TEST_P(RemoveUselessBF16ConvertCPUTest, CompareWithRefs) {
|
||||
run();
|
||||
//Convert is removed by graph_optimizer
|
||||
CheckNumberOfNodesWithType(compiledModel, "Convert", 0);
|
||||
//Disable Convert with Snippet
|
||||
CheckNumberOfNodesWithType(compiledModel, "Subgraph", 0);
|
||||
CheckPluginRelatedResults(compiledModel, "StridedSlice");
|
||||
}
|
||||
namespace {
|
||||
const std::vector<ElementType> inPrecisions = {
|
||||
// only bf16 could match this pattern
|
||||
ElementType::bf16,
|
||||
class RemoveUselessConvertCPUTest : public testing::WithParamInterface<RemoveConvertCPUTestParams>,
|
||||
virtual public SubgraphBaseTest,
|
||||
public CPUTestsBase {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<RemoveConvertCPUTestParams>& obj) {
|
||||
ElementType inType;
|
||||
InputShape inputShape;
|
||||
std::tie(inType, inputShape) = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "IS=" << inputShape << "_";
|
||||
result << "Prc=" << inType;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
ElementType inType;
|
||||
InputShape inputShape;
|
||||
std::tie(inType, inputShape) = this->GetParam();
|
||||
targetDevice = CommonTestUtils::DEVICE_CPU;
|
||||
|
||||
init_input_shapes({inputShape});
|
||||
auto input_params = builder::makeDynamicParams(inType, {inputShape.first});
|
||||
|
||||
// Such complicated graph is necessary to cover the case when Convert has several children and connected to non zero output
|
||||
const auto split_axis = builder::makeConstant(element::i64, ov::Shape{}, std::vector<int64_t>{1});
|
||||
const auto split_lengths = builder::makeConstant(element::i64, ov::Shape{2}, std::vector<int64_t>{-1, 1});
|
||||
const auto split = std::make_shared<ov::opset10::VariadicSplit>(input_params[0], split_axis, split_lengths);
|
||||
auto convert = builder::makeConversion(split->output(1), inType, ::helpers::ConversionTypes::CONVERT);
|
||||
auto relu = builder::makeActivation(convert, inType, ::helpers::ActivationTypes::Relu);
|
||||
|
||||
ov::ResultVector results{
|
||||
std::make_shared<ov::opset10::Result>(split->output(0)),
|
||||
std::make_shared<ov::opset10::Result>(convert),
|
||||
std::make_shared<ov::opset10::Result>(relu),
|
||||
};
|
||||
|
||||
function = std::make_shared<ov::Model>(results, input_params, "remove_convert");
|
||||
};
|
||||
};
|
||||
|
||||
TEST_P(RemoveUselessBF16ConvertCPUTest, CompareWithRefs) {
|
||||
run();
|
||||
CheckNumberOfNodesWithTypes(compiledModel, {"Convert", "Subgraph"}, 0);
|
||||
CheckPluginRelatedResults(compiledModel, "StridedSlice");
|
||||
}
|
||||
|
||||
TEST_P(RemoveUselessConvertCPUTest, CompareWithRefs) {
|
||||
run();
|
||||
CheckNumberOfNodesWithType(compiledModel, "Convert", 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
const std::vector<InputShape> inputShapes = {
|
||||
// dynamic batch
|
||||
{{-1, 4, 32, 64}, {{1, 4, 32, 64}, {2, 4, 32, 64}, {3, 4, 32, 64}}},
|
||||
@@ -86,7 +124,12 @@ const std::vector<InputShape> inputShapes = {
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_RemoveConvert,
|
||||
RemoveUselessBF16ConvertCPUTest,
|
||||
::testing::Combine(::testing::ValuesIn(inPrecisions), ::testing::ValuesIn(inputShapes)),
|
||||
::testing::Combine(::testing::Values(ElementType::bf16), ::testing::ValuesIn(inputShapes)),
|
||||
RemoveUselessBF16ConvertCPUTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_RemoveConvert,
|
||||
RemoveUselessConvertCPUTest,
|
||||
::testing::Combine(::testing::Values(ElementType::f32), ::testing::Values(inputShapes[0])),
|
||||
RemoveUselessConvertCPUTest::getTestCaseName);
|
||||
} // namespace
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
Reference in new issue
Block a user