Skip to content
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

[TF FE]: Support complex tensors for Equal operation #29339

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

NingLi670
Copy link

Details:

  • Support complex tensors for Equal operation
  • Add corresponding layer test

Tickets:

@NingLi670 NingLi670 requested review from a team as code owners March 8, 2025 11:15
@github-actions github-actions bot added category: Core OpenVINO Core (aka ngraph) category: TF FE OpenVINO TensorFlow FrontEnd category: CPP API OpenVINO CPP API bindings category: TFL FE OpenVINO TensorFlow Lite FrontEnd labels Mar 8, 2025
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Mar 8, 2025
@@ -289,6 +291,52 @@ ov::Output<ov::Node> ComplexTypeMark::div(const NodeContext& context,
return {result};
}

ov::Output<ov::Node> ComplexTypeMark::equal(const NodeContext& context,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this functionality to common translators. We will re-use it in PyTorch FE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move it to src\frontends\common_translators\src\op\complex.cpp or put it in a new file?

Copy link
Member

@rkazants rkazants Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new file equal.cpp in src\frontends\common_translators\src\op\

Comment on lines 302 to 305
auto lr = lhs_complex->get_real();
auto li = lhs_complex->get_imag();
auto rr = rhs_complex->get_real();
auto ri = rhs_complex->get_imag();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please think how to implement it using get_data() and how it will simplify this decomposition

Comment on lines 311 to 333
} else if (lhs_complex) {
// rhs is of a real type
auto lhs_real = lhs_complex->get_real();
auto lhs_imag = lhs_complex->get_imag();

auto eq_real = context.mark_node(make_shared<v1::Equal>(lhs_real, rhs));
auto zero_const = context.mark_node(make_shared<v0::Constant>(lhs_imag.get_element_type(), Shape{}, 0));
auto eq_imag = context.mark_node(make_shared<v1::Equal>(lhs_imag, zero_const));

auto result = context.mark_node(make_shared<v1::LogicalAnd>(eq_real, eq_imag));
return {result};
} else if (rhs_complex) {
// lhs is of a real type
auto rhs_real = rhs_complex->get_real();
auto rhs_imag = rhs_complex->get_imag();

auto eq_real = context.mark_node(make_shared<v1::Equal>(lhs, rhs_real));
auto zero_const = context.mark_node(make_shared<v0::Constant>(rhs_imag.get_element_type(), Shape{}, 0));
auto eq_imag = context.mark_node(make_shared<v1::Equal>(rhs_imag, zero_const));

auto result = context.mark_node(make_shared<v1::LogicalAnd>(eq_real, eq_imag));
return {result};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two cases are not supported by TF. Both operands must be of the same type: https://www.tensorflow.org/api_docs/python/tf/raw_ops/Equal

@NingLi670 NingLi670 requested a review from a team as a code owner March 9, 2025 05:24
@NingLi670 NingLi670 requested review from ilya-lavrenov and removed request for a team March 9, 2025 05:24
@github-actions github-actions bot added no-match-files and removed category: CPP API OpenVINO CPP API bindings labels Mar 9, 2025
@github-actions github-actions bot removed the category: Core OpenVINO Core (aka ngraph) label Mar 9, 2025
@NingLi670 NingLi670 requested a review from rkazants March 9, 2025 05:46
@@ -8,6 +8,7 @@
#include <map>
#include <string>

#include "common_translators.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Suggested change
#include "common_translators.hpp"

@@ -19,6 +19,8 @@ COMMON_OP_CONVERTER(translate_imag);
COMMON_OP_CONVERTER(translate_atan2);
COMMON_OP_CONVERTER(translate_angle);

COMMON_OP_CONVERTER(translate_equal_op);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COMMON_OP_CONVERTER(translate_equal_op);
COMMON_OP_CONVERTER(translate_equal);

let us have names without _op suffix. It is obvious that this is for ops:)

Copy link
Member

@rkazants rkazants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left couple of comments. Other part looks good to me.

@rkazants
Copy link
Member

rkazants commented Mar 9, 2025

@mvafin, fyi. it can be reused for PT FE

@NingLi670 NingLi670 requested a review from rkazants March 9, 2025 08:33
@rkazants
Copy link
Member

rkazants commented Mar 9, 2025

build_jenkins

@rkazants rkazants added this to the 2025.1 milestone Mar 9, 2025
OutputVector translate_equal_op(const NodeContext& node) {
default_op_checks(node, 2, {"Equal"}, true);

auto result = common_translators::translate_equal(node);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkazants It seems that remove #include "common_translators.hpp" from src/frontends/tensorflow_common/include/common_op_table.hpp will result in an error here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions about the implementation of translate_equal_op function here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please include "common_translators.hpp" in "binary_op.cpp". No need to insert to header file, we use it internally in this case.

@NingLi670
Copy link
Author

@rkazants Updated

@rkazants
Copy link
Member

rkazants commented Mar 9, 2025

build_jenkins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: TF FE OpenVINO TensorFlow FrontEnd category: TFL FE OpenVINO TensorFlow Lite FrontEnd ExternalPR External contributor no-match-files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants