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 Bincount operation for TensorFlow Hub models #22071

Closed
rkazants opened this issue Jan 10, 2024 · 21 comments · Fixed by #23418
Closed

[Good First Issue][TF FE]: Support Bincount operation for TensorFlow Hub models #22071

rkazants opened this issue Jan 10, 2024 · 21 comments · Fixed by #23418
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

rkazants commented Jan 10, 2024

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 Hub models with Bincount operation by OpenVINO, TF FE needs to be extended with this operation support.

We have a couple of models from TF Hub containing this operation:

What needs to be done?

For Bincount 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 #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_Bincount.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 -m use_new_frontend

Hint

Bincount operation requires decomposition using OV opset. The following idea is proposed to use for the decomposition but you may implement your more elegant and performance efficient idea:

  1. Generate range tensor [0, size) using Range operation
  2. Reshape tensors of arr and weights to 1D tensors
  3. Unsqueeze range to [size, 1] shape and unsqueeze arr and weights to shapes [1, num]
  4. Generate a mask of equalness range == arr where to set 0 or weight from weights tensor
  5. After we use operations Select, ReduceSum, and ScatterUpdate for result generation

Example Pull Requests

Resources

Contact points

@openvinotoolkit/openvino-tf-frontend-maintainers

@rkazants rkazants added good first issue Good for newcomers no_stale Do not mark as stale labels Jan 10, 2024
@rkazants rkazants moved this to Contributors Needed in Good first issues Jan 10, 2024
@rkazants rkazants added the category: TF FE OpenVINO TensorFlow FrontEnd label Jan 10, 2024
@TheNobody-12
Copy link

Hello @rkazants , I would like to contribute to this program. Can you please assign me this task. ?

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Jan 11, 2024
@rkazants
Copy link
Contributor Author

Fyi, please use new link to join Intel DevHub Discord server, if you have not yet joined. The previous one is outdated.

Best regards,
Roman

@rkazants
Copy link
Contributor Author

Hi @TheNobody-12, do you have any update on this task? Please let me know in case questions and you can create a preliminary PR to discuss.

Best regards,
Roman

@rkazants
Copy link
Contributor Author

Hi @TheNobody-12, any update on this task?

@TheNobody-12
Copy link

If possible i require some guidance, how i should start working on this issue?

@ViswanathBalla22
Copy link

hi @rkazants I'm a beginner excited to contribute. I'm looking to solve issue can you assign to me. and can you help me if I stuck with any problem

@rkazants
Copy link
Contributor Author

rkazants commented Jan 21, 2024

hi @rkazants I'm a beginner excited to contribute. I'm looking to solve issue can you assign to me. and can you help me if I stuck with any problem

Hi @ViswanathBalla22, sorry but task has been already assigned. Please track new (available) good first issues in OpenVINO. We try to post new GFIs almost every day.

Best regards,
Roman

@rkazants
Copy link
Contributor Author

rkazants commented Jan 21, 2024

If possible i require some guidance, how i should start working on this issue?

Hi @TheNobody-12, try to start with completing the first two steps of the hint in the ticket description and post PR with these changes so I will check and give the next guidance. You can see PR with example for another operation: #19007

Best regards,
Roman

@rkazants
Copy link
Contributor Author

Hi @ViswanathBalla22, here is the task that just gets available: #22082.
You you wish to contribute there, just type a comment .take in that ticket.

@openvinotoolkit openvinotoolkit deleted a comment from github-actions bot Jan 21, 2024
@ViswanathBalla22
Copy link

ok @rkazants ,I can assign that issue. and btw can you provide any community channel or discord for this project

@mlukasze
Copy link
Contributor

hey @ViswanathBalla22
Here is our Discord
Have fun :)

@p-wysocki
Copy link
Contributor

Hello @ViswanathBalla22, are you still working on that issue?

@p-wysocki p-wysocki moved this from Assigned to Contributors Needed in Good first issues Feb 5, 2024
@Aryan8912
Copy link
Contributor

assign it to me so I can work on this issue

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Feb 6, 2024
@mlukasze
Copy link
Contributor

mlukasze commented Feb 6, 2024

as you wish @Aryan8912 :)

@rkazants
Copy link
Contributor Author

Hi @Aryan8912, any progress on it?

@Aryan8912
Copy link
Contributor

sorry sir for the late reply I am traveling, give me one or two days, and I will submit a PR

@rkazants
Copy link
Contributor Author

rkazants commented Mar 8, 2024

Hi @Aryan8912, I return this GFI to available status since no update.

@rkazants rkazants moved this from Assigned to Contributors Needed in Good first issues Mar 8, 2024
@chux0519
Copy link
Contributor

Hi developers, I'd like to take this one!

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Mar 11, 2024
@mlukasze
Copy link
Contributor

be our guest, have fun, it's yours now :)

@chux0519
Copy link
Contributor

chux0519 commented Mar 12, 2024

Hi, developers

I'm still work in progress, following some example code and I want to check if my implementation works so far, I added a test case (test_tf_Bincount.py) in python side, run pytest test_tf_Bincount.py and I hit

Internal error, no translator found for operation(s): Bincount

(but I can run other test cases)

here is the diff(implementation is still incomplete, and I just want to make sure test case works:

https://github.com/openvinotoolkit/openvino/compare/master...chux0519:openvino:feat-bincount?expand=1

I'm using a intel mac and my compile command is

cmake \
-G "Ninja Multi-Config" \
-DENABLE_CPPLINT=OFF \
-DENABLE_NCC_STYLE=OFF \
-DENABLE_TESTS=ON \
-DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
-DENABLE_STRICT_DEPENDENCIES=OFF \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DENABLE_SYSTEM_PUGIXML=ON -DENABLE_SYSTEM_SNAPPY=ON -DENABLE_SYSTEM_PROTOBUF=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DENABLE_PYTHON=ON -DPython3_EXECUTABLE=/Users/chux0519/venv/bin/python -DENABLE_WHEEL=ON ..

python version is 3.11, and I reinstalled wheels after rebuild, did I miss anything

update

it seems the wheel is not rebuilt(timestamp shows it's not updated), i'll clean and rebuild and see if it works

cool, seems so, just delete wheels and regenerate one fixed this.

chux0519 added a commit to chux0519/openvino that referenced this issue Mar 12, 2024
@chux0519
Copy link
Contributor

PR sent: #23418

@rkazants rkazants linked a pull request Mar 12, 2024 that will close this issue
github-merge-queue bot pushed a commit that referenced this issue Mar 15, 2024
### Details:
 - implemented Bincount op
 - simple test cases

### Tickets:
#22071

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
@github-project-automation github-project-automation bot moved this from Assigned to Closed in Good first issues Mar 15, 2024
bbielawx pushed a commit to bbielawx/openvino that referenced this issue Apr 12, 2024
### Details:
 - implemented Bincount op
 - simple test cases

### Tickets:
openvinotoolkit#22071

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
alvoron pushed a commit to alvoron/openvino that referenced this issue Apr 29, 2024
### Details:
 - implemented Bincount op
 - simple test cases

### Tickets:
openvinotoolkit#22071

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
@ilya-lavrenov ilya-lavrenov added this to the 2024.1 milestone May 23, 2024
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.

8 participants