Skip to content

Commit

Permalink
updated scaling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e-ddykim committed Jan 9, 2025
1 parent 9a3cda3 commit e667219
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ ov::pass::activations_scaling::MulConcatTransformation::MulConcatTransformation(
last_dep_const_type = last_dep_const.get_element_type();
}

auto target_inputs = concat->get_output_target_inputs(0);

for (auto& input : concat->inputs()) {
auto dep_node = input.get_source_output().get_node_shared_ptr();
auto dep_input0 = dep_node->input(0).get_source_output().get_node();
Expand Down Expand Up @@ -314,7 +316,10 @@ ov::pass::activations_scaling::MulConcatTransformation::MulConcatTransformation(
ov::op::TemporaryReplaceOutputType(last_dep_const, concat_type).get());
new_mul->set_friendly_name(concat->get_friendly_name() + "_c");
ov::copy_runtime_info(concat, new_mul);
ov::replace_output_update_name(concat->output(0), new_mul->output(0));

for (auto& in : target_inputs) {
in.replace_source_output(new_mul);
}

return true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ TEST_F(TransformationTestsF, ScaleDownSingleLayerTest) {
CoordinateDiff{},
CoordinateDiff{},
Strides{});
auto convert = std::make_shared<ov::op::v0::Convert>(conv, ov::element::f32);
auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});
auto add = std::make_shared<ov::op::v1::Add>(conv, bias_const);
auto convert = std::make_shared<ov::op::v0::Convert>(add, ov::element::f32);
auto result = std::make_shared<ov::op::v0::Result>(convert);

model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});
Expand All @@ -56,8 +58,11 @@ TEST_F(TransformationTestsF, ScaleDownSingleLayerTest) {
CoordinateDiff{},
CoordinateDiff{},
Strides{});
auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});
auto scale_down_bias = std::make_shared<ov::op::v1::Multiply>(bias_const, scale_down_const);
auto add = std::make_shared<ov::op::v1::Add>(conv, scale_down_bias);
auto scale_up_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{}, {scale_factor});
auto scale_up = std::make_shared<ov::op::v1::Multiply>(conv, scale_up_const);
auto scale_up = std::make_shared<ov::op::v1::Multiply>(add, scale_up_const);
auto convert = std::make_shared<ov::op::v0::Convert>(scale_up, ov::element::f32);
auto result = std::make_shared<ov::op::v0::Result>(convert);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,23 @@ class ActivationsScaling : public testing::WithParamInterface<ActivationsScaling

function = init_subgraph(inputDynamicShapes, shape_params.weights_shapes, input_precision);
}

void validate() override {
ov::test::SubgraphBaseTest::validate();

ov::element::Type input_precision = function->input(0).get_element_type();
auto runtime_model = compiledModel.get_runtime_model();

for (auto& op : runtime_model->get_ordered_ops()) {
ASSERT_EQ(op->output(0).get_element_type(), input_precision)
<< "expected output precision is " << input_precision << " , while actual is " << op->output(0).get_element_type();
}
}
};

TEST_P(ActivationsScaling, Inference) {
core->set_property(targetDevice, ov::hint::activations_scale_factor(4.3));
run();
ov::serialize(compiledModel.get_runtime_model(), "test.xml");
}

TEST_P(ActivationsScaling, Inference_cached) {
Expand Down

0 comments on commit e667219

Please sign in to comment.