Skip to content

[CPU] fix CPU FullyConnected Node zeros value output issue #30197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/common/transformations/src/transformations/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "openvino/op/multiply.hpp"
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/random_uniform.hpp"
#include "openvino/op/read_value.hpp"
#include "openvino/op/relu.hpp"
#include "openvino/op/reshape.hpp"
Expand Down Expand Up @@ -491,19 +492,35 @@ bool is_constant_and_all_values_equal_int(const Output<Node>& output, const int6

bool is_on_constant_path(const ov::Output<ov::Node>& output) {
auto status = true;
std::deque<ov::Node*> nodes_to_calculate = {output.get_node()};

auto root_node = output.get_node();
if (!root_node || root_node->get_output_size() == 0) {
return false;
}
std::deque<ov::Node*> nodes_to_calculate = {root_node};

std::unordered_set<ov::Node*> visited;
while (status && !nodes_to_calculate.empty()) {
auto current_node = nodes_to_calculate.front();
nodes_to_calculate.pop_front();
if (visited.count(current_node)) {
continue;
}
visited.insert(current_node);
// RandomUniform output changes during runtime, so we should not consider it as a constant
if (current_node->get_type_info() == ov::op::v8::RandomUniform::get_type_info_static()) {
return false;
}

if (current_node->get_input_size() == 0 && !ov::is_type<ov::op::v0::Constant>(current_node)) {
status = false;
} else {
// not a leaf - continue to search
for (const auto& input_value : current_node->input_values()) {
const auto& input_node = input_value.get_node();
nodes_to_calculate.push_front(input_node);
if (!visited.count(input_node)) {
nodes_to_calculate.push_front(input_node);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openvino/opsets/opset1_decl.hpp"
#include "openvino/opsets/opset3_decl.hpp"
#include "openvino/opsets/opset7_decl.hpp"
#include "openvino/opsets/opset8_decl.hpp"
#include <openvino/pass/manager.hpp>
#include <ov_ops/type_relaxed.hpp>
#include <transformations/cpu_opset/common/pass/convert_matmul_to_fc.hpp>
Expand All @@ -25,6 +26,7 @@
#include "openvino/op/shape_of.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/random_uniform.hpp"

using namespace testing;
using namespace ov::intel_cpu;
Expand Down Expand Up @@ -543,3 +545,38 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_compressed_u8_weights) {
model_ref = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{data});
}
}

TEST_F(TransformationTestsF, ConvertMatMulToFCTest_WithRandomUniform) {
{
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});

auto random_uniform_shape = ov::opset1::Constant::create(ov::element::i32, ov::Shape{2}, {2, 2});
auto random_uniform_min = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1}, {0.0});
auto random_uniform_max = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1}, {1.0});
auto random_uniform = std::make_shared<ov::op::v8::RandomUniform>(random_uniform_shape,
random_uniform_min,
random_uniform_max,
ov::element::f32);

auto matmul = std::make_shared<ov::opset1::MatMul>(input1, random_uniform, false, false);

model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input1});

manager.register_pass<ConvertMatMulToFC>();
}
{
auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});

auto random_uniform_shape = ov::opset1::Constant::create(ov::element::i32, ov::Shape{2}, {2, 2});
auto random_uniform_min = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1}, {0.0});
auto random_uniform_max = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1}, {1.0});
auto random_uniform = std::make_shared<ov::op::v8::RandomUniform>(random_uniform_shape,
random_uniform_min,
random_uniform_max,
ov::element::f32);

auto matmul = std::make_shared<ov::opset1::MatMul>(input1, random_uniform, false, false);

model_ref = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input1});
}
}
Loading