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

[Good First Issue][TF FE]: Support complex tensors for ExpandDims operation #22950

Closed
rkazants opened this issue Feb 20, 2024 · 12 comments · Fixed by #26892
Closed

[Good First Issue][TF FE]: Support complex tensors for ExpandDims operation #22950

rkazants opened this issue Feb 20, 2024 · 12 comments · Fixed by #26892
Assignees
Labels
category: TF FE OpenVINO TensorFlow FrontEnd good first issue Good for newcomers no_stale Do not mark as stale
Milestone

Comments

@rkazants
Copy link
Contributor

Context

OpenVINO component responsible for support of TensorFlow models is called as TensorFlow Frontend (TF FE). TF FE converts a model represented in TensorFlow opset to a model in OpenVINO opset.
Some audio models use tensors of complex type. Complex type tensor is a tensor that has elements of complex type. For example, 1D tensor with three elements x = [1+2j, 2, -2j].

For supporting ExpandDims operation on complex type tensor, you need to extend the corresponding loader for ExpandDims.

What needs to be done?

The existing loader for ExpandDims needs to be extended by propagating ComplexTypeMark from input to output and to represent output complex type tensor as a floating-point type tensor with auxiliary dimension that concatenates real and imaginary parts of complex tensor.
To validate the extension, the corresponding layer test needs to be updated with complex tensor cases.

Here is an example of how to extend Reshape loader to support complex type tensors:

OutputVector translate_reshape_op(const NodeContext& node) {
    default_op_checks(node, 2, {"Reshape"}, true);
    auto tensor = node.get_input(0);
    auto complex_type_mark = as_type_ptr<ComplexTypeMark>(tensor.get_node_shared_ptr());
    auto shape = node.get_input(1);
    if (complex_type_mark) {
        element::Type complex_part_type = complex_type_mark->get_complex_part_type();
        tensor = complex_type_mark->input_value(0);

        OutputVector concat_inputs;
        concat_inputs.push_back(shape);
        concat_inputs.push_back(make_shared<v0::Constant>(shape.get_element_type(), Shape{1}, 2));

        auto concat = make_shared<v0::Concat>(concat_inputs, 0);
        auto reshape = make_shared<v1::Reshape>(tensor, concat, false);
        set_node_name(node.get_name(), reshape);
        auto complex_reshape = make_shared<ComplexTypeMark>(reshape, complex_part_type);
        return {complex_reshape->output(0)};
    }

    auto reshape = make_shared<v1::Reshape>(tensor, shape, false);
    set_node_name(node.get_name(), reshape);
    return {reshape};
}

Since OpenVINO does not have native support of complex tensors, we handle complex type in intermediate layers by representing them as a floating-point type with additional dimension (specially created) to store real and imaginary parts of the original complex tensor so slicing by the last dimension will give either real or imaginary parts: x[...,0] - real and x[...,1] - imaginary parts.

On the first step, we update default_op_checks with true flag to indicate that loader for Reshape operation now handles complex tensors:

default_op_checks(node, 2, {"Reshape"}, true);

Secondly, we check if complex type mark exists by anticipated inputs. This mark indicates that input tensor of complex type:

auto complex_type_mark = as_type_ptr<ComplexTypeMark>(tensor.get_node_shared_ptr());

Thirdly, we retrieve a floating-point tensor (with additional dimension to store real and imaginary parts) simulating complex tensor:

tensor = complex_type_mark->input_value(0);

After that, we implement conversion for Reshape for this particular case. Since a floating-point tensor simulating complex tensor has additional dimension equal to 2,
we update input target shape by appending 2 value and perform reshape on a floating-point tensor simulating complex tensor.

Finally, since Reshape should produce complex tensor by output we insert a new mark ComplexTypeMark into the output.

To validate support of complex tensors for Reshape, the new layer test TestComplexReshape was added.

Example how to run the layer test:

export TEST_DEVICE=CPU
cd openvino/tests/layer_tests/tensorflow_tests
pytest test_tf_Reshape.py

Example Pull Requests

Resources

Contact points

  • @openvinotoolkit/openvino-tf-frontend-maintainers
  • rkazants in Discord

Ticket

No response

@rkazants rkazants added no_stale Do not mark as stale category: TF FE OpenVINO TensorFlow FrontEnd good first issue Good for newcomers labels Feb 20, 2024
@github-project-automation github-project-automation bot moved this to Contributors Needed in Good first issues Feb 20, 2024
@rkazants rkazants added the gsoc-prerequisite-task Prerequisite task related to Google Summer of Code projects label Feb 22, 2024
@AtharvaPore01
Copy link

.take

Copy link
Contributor

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

@rkazants rkazants moved this from Contributors Needed to Assigned in Good first issues Feb 23, 2024
@AtharvaPore01
Copy link

I am having question regarding the pytest. To run the desired python code to test the C++ code changes, should I need to add the test cases to check for the desired results?

@rkazants
Copy link
Contributor Author

rkazants commented Mar 8, 2024

Hi @AtharvaPore01,

Sorry for delay in response, I missed your message. For validation of C++ part required in this task, we use pytest based validation.
BTW, any update on this task?

Best regards,
Roman

@AtharvaPore01
Copy link

Hello @rkazants,

I apologize for the delay. I'm currently working on the task and endeavoring to submit it on time. Due to some prior commitments, I wasn't able to progress as quickly as I would have liked, but rest assured, I am actively working on it.

Best regards,
Atharva

@p-wysocki
Copy link
Contributor

Hello @AtharvaPore01, are you still working on this? Is there anything we could help you with?

@rkazants rkazants moved this from Assigned to Contributors Needed in Good first issues Apr 15, 2024
@rkazants rkazants removed the gsoc-prerequisite-task Prerequisite task related to Google Summer of Code projects label Apr 15, 2024
@rghvsh
Copy link
Contributor

rghvsh commented Apr 17, 2024

.take

Copy link
Contributor

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

@rghvsh
Copy link
Contributor

rghvsh commented Apr 17, 2024

Hi! @rkazants, Is this the correct way to do this

  if (complex_type_mark) {

    element::Type complex_part_type = complex_type_mark->get_complex_part_type();
    input = complex_type_mark->input_value(0);

    auto unsqueeze = make_shared<v0::Unsqueeze>(input, axis);
    set_node_name(node.get_name(), unsqueeze);
    return {unsqueeze};
}

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Apr 17, 2024
@p-wysocki
Copy link
Contributor

cc @rkazants

@mlukasze mlukasze moved this from Assigned to Contributors Needed in Good first issues Jul 25, 2024
@hub-bla
Copy link
Contributor

hub-bla commented Oct 3, 2024

.take

Copy link
Contributor

github-actions bot commented Oct 3, 2024

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Oct 3, 2024
@rkazants rkazants linked a pull request Oct 3, 2024 that will close this issue
github-merge-queue bot pushed a commit that referenced this issue Oct 3, 2024
### Details:
 - Support complex tensors for `ExpandDims` operation + tests

### Tickets:
 - [None](#22950)
@github-project-automation github-project-automation bot moved this from Assigned to Closed in Good first issues Oct 3, 2024
@mlukasze mlukasze added this to the 2024.5 milestone Oct 4, 2024
pkowalc1 pushed a commit to pkowalc1/openvino that referenced this issue Oct 9, 2024
…olkit#26892)

### Details:
 - Support complex tensors for `ExpandDims` operation + tests

### Tickets:
 - [None](openvinotoolkit#22950)
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 good first issue Good for newcomers no_stale Do not mark as stale
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants