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

[Frontend, Tensorflow2] Added support for TensorList ops #8454

Merged
merged 13 commits into from
Jul 25, 2021

Conversation

zxy844288792
Copy link
Contributor

This PR adds support for TensorList ops in TF2 frontend parser. Ops like TensorListFromTensor, TensorListGetItem etc are common in graphdef of TF2 OD models like Faster-RCNN etc.

This PR is in line with the original plan of supporting tensorflow2 parser in TVM frontend as in the discussion #4102 Exact commit plan here.

Co-authored-by: David Huang davhuan@amazon.com
Co-authored-by: Rohan Mukherjee mukrohan@amazon.com
Co-authored-by: Xingyu Zhou zhoxingy@amazon.com
Co-authored-by: Srinidhi Goud srinidhi.goud29@gmail.com
Co-authored-by: Xiao weix@amazon.com

Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

rohanmukh and others added 11 commits July 12, 2021 18:50
Co-authored-by: David Huang <davhuan@amazon.com>
Co-authored-by: Rohan Mukherjee <mukrohan@amazon.com>
Co-authored-by: Xingyu Zhou <zhoxingy@amazon.com>
Co-authored-by: Srinidhi Goud <srinidhi.goud29@gmail.com>
Co-authored-by: Xiao <weix@amazon.com>
@zxy844288792
Copy link
Contributor Author

zxy844288792 commented Jul 13, 2021

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

I don't really familiar with the logic behind TF2 converter so just some comments to the style. Leave to @yongwww @trevor-m

python/tvm/relay/frontend/tensorflow2.py Outdated Show resolved Hide resolved
python/tvm/relay/frontend/tensorflow2.py Show resolved Hide resolved
python/tvm/relay/frontend/tensorflow2.py Show resolved Hide resolved
python/tvm/relay/frontend/tensorflow2.py Show resolved Hide resolved
python/tvm/relay/frontend/tensorflow2.py Show resolved Hide resolved
@yongwww
Copy link
Member

yongwww commented Jul 22, 2021

Thanks for the pr, I will take a look at it later today.

# A map to record tensor list write ops and input tl/tensor indices
# Value is (index of tensor list, index of written node)
_tensor_list_write_ops = {
"TensorListSetItem": (0, 2),
Copy link
Member

Choose a reason for hiding this comment

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

is there any reason why you chose 0 and 2 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the input tensorlist and tensor indices defined in tensorflow API

elif cnode.name != stack_node.name:
if is_tensor_list_constuctor(cnode):
shape_attr = parse_attr(input_shape_node.attr)
if "value" not in shape_attr:
Copy link
Member

Choose a reason for hiding this comment

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

just for curiosity, for the case 'value' not in shape_attr, does that mean it is a input node without shape?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, then we will treat it as dynamic shape. It will still work as a unit test but in real model, it might cause problem if following by some ops like conv2D

"TensorListGetItem": _tensorlist_get_item(),
"TensorListReserve": _tensorlist_reserve(),
"TensorListSetItem": _tensorlist_set_item(),
"TensorListStack": _tensorlist_stack(),
Copy link
Member

Choose a reason for hiding this comment

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

seems there are several other TensorList related ops like TensorListScatter are not added here, what are the reasons you chose the list here to support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I chose these operators is due to the models I am working on only contain these ops, It will be ongoing efforts for adding new operator support

)
return model

run_sequential_model(tensorlist_read_model, input_shape=(3, 32))
Copy link
Member

Choose a reason for hiding this comment

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

maybe adding a test case with a public model that contains tensorlist ops

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have some public models but they will trigger a corner case which I will fix in the next Pr. The TensorList op alone works fine.

Copy link
Member

@yongwww yongwww left a comment

Choose a reason for hiding this comment

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

LGTM

@comaniac comaniac merged commit 8ab2074 into apache:main Jul 25, 2021
@comaniac
Copy link
Contributor

comaniac commented Jul 25, 2021

Thanks @zxy844288792 @yongwww @trevor-m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants