openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
6.54k stars 2.12k forks source link

[Good First Issue][TF FE]: Support MatrixSetDiagV3 operation for TensorFlow #23249

Open rkazants opened 4 months ago

rkazants commented 4 months ago

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.

In order to infer TensorFlow models with MatrixSetDiagV3 operation by OpenVINO, TF FE needs to be extended with this operation support.

What needs to be done?

For MatrixSetDiagV3 operation support, you need to implement the corresponding loader into TF FE op directory and to register it into the dictionary of Loaders. One loader is responsible for conversion (or decomposition) of one type of TensorFlow operation.

Here is an example of loader implementation for TensorFlow Einsum operation:

OutputVector translate_einsum_op(const NodeContext& node) { 
     auto op_type = node.get_op_type(); 
     TENSORFLOW_OP_VALIDATION(node, op_type == "Einsum", "Internal error: incorrect usage of translate_einsum_op."); 
     auto equation = node.get_attribute<std::string>("equation"); 

     OutputVector inputs; 
     for (size_t input_ind = 0; input_ind < node.get_input_size(); ++input_ind) { 
         inputs.push_back(node.get_input(input_ind)); 
     } 

     auto einsum = make_shared<Einsum>(inputs, equation); 
     set_node_name(node.get_name(), einsum); 
     return {einsum}; 
 } 

In this example, translate_einsum_op converts TF Einsum into OV Einsum. NodeContext object passed into the loader packs all info about inputs and attributes of Einsum operation. The loader retrieves an attribute of the equation by using the NodeContext::get_attribute() method, prepares input vector, creates Einsum operation from OV opset and returns a vector of outputs.

Responsibility of a loader is to parse operation attributes, prepare inputs and express TF operation via OV operations sub-graph. Example for Einsum demonstrates the resulted sub-graph with one operation. In PR https://github.com/openvinotoolkit/openvino/pull/19007 you can see operation decomposition into multiple node sub-graph.

Once you are done with implementation of the translator, you need to implement the corresponding layer tests test_tf_MatrixInverse.py and put it into layer_tests/tensorflow_tests directory. Example how to run some layer test:

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

Hint

Check out how MatrixBandPart was implemented here: https://github.com/openvinotoolkit/openvino/pull/23082

Example Pull Requests

Resources

Contact points

Ticket

No response

Vishwa44 commented 4 months ago

.take

github-actions[bot] commented 4 months ago

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

p-wysocki commented 4 months ago

Hello @Vishwa44, is there anything we could help you with?

Vishwa44 commented 4 months ago

Hi @p-wysocki , I'm having a hard time navigating through your opset, if you can share me any relevant documentation, it will be really helpful

p-wysocki commented 4 months ago

Could you please share your specific questions? Without them I can only recommend the Technical Guide, which is an entry point to our technical documentation.

rkazants commented 4 months ago

Hi @Vishwa44, do you have any update on this task?

Best regards, Roman

amand143 commented 3 months ago

hi is this issue still being worked on or is this open for taking @Vishwa44 @rkazants

p-wysocki commented 3 months ago

I'm reopening the issue due to current assignee's inactivity.

Aryan8912 commented 3 months ago

assign to me

Aryan8912 commented 3 months ago

hey sir I submitted the pull request but sir I can't solve the rebase problem can you please help me

rkazants commented 3 months ago

Hi @Aryan8912, I release this GFI due to 2 weeks are over and PR is unclear how to support MatrixSetDiagV3.

YukumoHunter commented 3 months ago

.take

github-actions[bot] commented 3 months ago

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

p-wysocki commented 2 months ago

Hello @YukumoHunter, are you still working on that issue? Do you need any help?

YukumoHunter commented 2 months ago

Hello @YukumoHunter, are you still working on that issue? Do you need any help?

Hi, I got a little busy with other work the last couple of weeks but I'm working on it now!

YukumoHunter commented 2 months ago

Hi @p-wysocki, I started working on the issue but I am unsure about the loader implementation. I looked through the latest opset but I don't think the ops there are applicable to MatrixSetDiagV3. Does this mean I am supposed to implement the operation behavior directly in the loader? Or perhaps did I miss any other useful functions that might help?

p-wysocki commented 2 months ago

cc @rkazants