Unverified Commit 5414b7ad authored by Michał Karzyński's avatar Michał Karzyński Committed by GitHub

Improve Provenance tests (#4358)

* Disable adding ONNX tags if Provenance disabled globally

* Improve Provenance tests

* Change where get_provenance_enabled is checked.

* Review comments
Co-authored-by: 's avatarRobert Kimball <robert.kimball@intel.com>
parent c62feaf0
......@@ -20,6 +20,7 @@
#include "graph.hpp"
#include "node.hpp"
#include "provenance.hpp"
#include "utils/common.hpp"
namespace ngraph
......@@ -224,6 +225,11 @@ namespace ngraph
void Graph::add_provenance_tag_to_initializer(
const Tensor& tensor, std::shared_ptr<default_opset::Constant> node) const
{
if (!ngraph::get_provenance_enabled())
{
return;
}
const std::string tag =
detail::build_input_provenance_tag(tensor.get_name(), tensor.get_shape());
......@@ -233,6 +239,11 @@ namespace ngraph
void Graph::add_provenance_tag_to_input(const ValueInfo& input,
std::shared_ptr<ngraph::Node> node) const
{
if (!ngraph::get_provenance_enabled())
{
return;
}
const std::string tag =
detail::build_input_provenance_tag(input.get_name(), input.get_shape());
......@@ -242,6 +253,11 @@ namespace ngraph
void Graph::add_provenance_tags(const Node& onnx_node,
const NodeVector& ng_node_vector) const
{
if (!ngraph::get_provenance_enabled())
{
return;
}
const auto tag = detail::build_op_provenance_tag(onnx_node);
const auto ng_inputs = onnx_node.get_ng_inputs();
......
......@@ -22,6 +22,7 @@
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/opset0_downgrade.hpp"
#include "ngraph/provenance.hpp"
#include "util/provenance_enabler.hpp"
#include "util/test_control.hpp"
#include "util/type_prop.hpp"
......@@ -68,6 +69,8 @@ void test_provenance_tags(const std::shared_ptr<Function> function,
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_only_output)
{
test::ProvenanceEnabler provenance_enabler;
// the Add node in the model does not have a name,
// only its output name should be found in the provenance tags
const auto function = onnx_import::import_onnx_model(
......@@ -77,6 +80,8 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_only_output)
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_node_name_and_outputs)
{
test::ProvenanceEnabler provenance_enabler;
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/provenance_node_name_and_outputs.prototxt"));
test_provenance_tags<default_opset::Add>(function, "<ONNX Add (Add_node -> output_of_add)>");
......@@ -84,6 +89,8 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_node_name_and_outputs)
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_multiple_outputs_op)
{
test::ProvenanceEnabler provenance_enabler;
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/provenance_multiple_outputs_op.prototxt"));
test_provenance_tags<default_opset::TopK>(function, "<ONNX TopK (TOPK -> values, indices)>");
......@@ -91,6 +98,8 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_multiple_outputs_op)
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_tagging_constants)
{
test::ProvenanceEnabler provenance_enabler;
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/provenance_input_tags.prototxt"));
test_provenance_tags<default_opset::Constant>(function,
......@@ -99,6 +108,8 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_tagging_constants)
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_tagging_parameters)
{
test::ProvenanceEnabler provenance_enabler;
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/provenance_input_tags.prototxt"));
test_provenance_tags<default_opset::Parameter>(function, "<ONNX Input (input_B) Shape:{}>");
......@@ -106,7 +117,7 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_tagging_parameters)
NGRAPH_TEST(onnx_${BACKEND_NAME}, provenance_tag_downgrade_pass)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/provenance_downgrade_topk.prototxt"));
......
......@@ -30,6 +30,7 @@
#include "ngraph/pass/opset0_downgrade.hpp"
#include "ngraph/pass/opset1_upgrade.hpp"
#include "ngraph/provenance.hpp"
#include "util/provenance_enabler.hpp"
using namespace std;
using namespace ngraph;
......@@ -39,18 +40,7 @@ using ProvSet = std::unordered_set<std::string>;
TEST(provenance, provenance)
{
class ProvenanceEnabler
{
public:
ProvenanceEnabler()
{
saved_enable_state = get_provenance_enabled();
set_provenance_enabled(true);
}
~ProvenanceEnabler() { set_provenance_enabled(saved_enable_state); }
private:
bool saved_enable_state;
} provenance_enabler;
test::ProvenanceEnabler provenance_enabler;
//
// Before:
......@@ -406,7 +396,7 @@ TEST(provenance, builder)
TEST(provenance, fused_copy_origin_tags)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
auto p1 = make_shared<op::Parameter>(element::f32, PartialShape{2, 3, 4});
p1->add_provenance_tag("P1");
......@@ -439,7 +429,7 @@ TEST(provenance, fused_copy_origin_tags)
TEST(provenance, fused_decomposition_tag)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
auto p1 = make_shared<op::Parameter>(element::f32, PartialShape{2, 3, 4});
auto fused_op = make_shared<op::MVN>(p1);
......@@ -556,7 +546,7 @@ TEST(provenance, scaled_quantize_concat_unsigned)
TEST(provenance, opset1_upgrade_pass_topk)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
const size_t axis = 2;
const size_t k = 10;
......@@ -585,7 +575,7 @@ TEST(provenance, opset1_upgrade_pass_topk)
TEST(provenance, opset0_downgrade_pass_topk)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
const auto data = make_shared<op::Parameter>(element::i32, Shape{5, 10, 15});
const int32_t k = 10;
......@@ -618,7 +608,7 @@ TEST(provenance, opset0_downgrade_pass_topk)
TEST(provenance, opset1_upgrade_pass_graph)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
auto x = make_shared<op::Parameter>(element::i32, PartialShape{2, 3, 4});
auto y = make_shared<op::Parameter>(element::i32, PartialShape{2, 3, 4});
......@@ -661,7 +651,7 @@ TEST(provenance, opset1_upgrade_pass_graph)
TEST(provenance, opset0_downgrade_pass_graph)
{
set_provenance_enabled(true);
test::ProvenanceEnabler provenance_enabler;
auto x = make_shared<op::Parameter>(element::i32, PartialShape{2, 3, 4});
auto y = make_shared<op::Parameter>(element::i32, PartialShape{2, 3, 4});
......
......@@ -25,6 +25,7 @@ set (SRC
test_tools.cpp
test_control.cpp
test_case.cpp
provenance_enabler.hpp
backend_utils.cpp
)
......
//*****************************************************************************
// Copyright 2017-2020 Intel Corporation
//
// 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.
//*****************************************************************************
#include "ngraph/provenance.hpp"
namespace ngraph
{
namespace test
{
/// \brief Enable provenance for the duration of a unit test.
///
/// During creation this object activates provenance support, when it's destroyed
/// it returns the provenance support to previous state.
class ProvenanceEnabler
{
public:
ProvenanceEnabler()
{
saved_enable_state = get_provenance_enabled();
set_provenance_enabled(true);
}
~ProvenanceEnabler() { set_provenance_enabled(saved_enable_state); }
private:
bool saved_enable_state;
};
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment