[Resolved] Adding tf.size operator to TVM



I have a model which has the Size operator. I was wondering if there are some hints on how to achieve this. I have seen there is a guide on how to add new Relay operators, but the whole process still not clear, in particularly exposing a new operator to the tensorflow frontend.




I would suggest looking at some of the pull requests or commits in the repository for aoother such operators. The usual situation with adding support in the frontend is to add support to python/tvm/relay/frontend/tensorflow.py.

Add an entry to the _convert_map ‘map’ for your new operator and try to add support for this using existing relay operators. If there is pre-existing support for the ‘size’ relay operator, you could probably use that otherwise you’d have to add new relay operator and plumb it through.

Hope this helps and good luck !



Thanks for your answer, yes that is my understanding that one the one hand one should check the existing support in relay and then look at the supported ops in frontend of interest.

I found that the operator shape would be the closest to size in the tensorflow frontend:

But it seems that it does not use a relay op but instead computes the shape directly in python. Could you have a look and give a hint based on the shape op as example?



It would be nice to have some more comments in the front end about when to use what in the frontend. Having had a quick look at the documents, it sounds to me like tf.size is equivalent to np.size and it’s really looking for the number of elements matching the type given as input to size. This would thus be a check to see whether the type of the input tensor matches with the tensor dtype and a count of the number of elements, which should be detectable statically from other information in there.

Probably others better versed in tf than me can comment - @srkreddy1238 , maybe ?

I would start by first writing a test in tests/python/frontend/tensorflow/test_forward.py for this and working with that.

Good luck,


Thanks for your suggestions!

Indeed, for the frontend there a bit of documentation and comments missing to know when to use what. For example, I see that is some cases the operator are invoked with the _op prefix like _op.clip(...). Other times the AttrCvt() function is used for other operators. So is not really clear how can I add a simple operator like size.

I am looking forward to further feedback on this. I hope also that in the future there will be better documentation to add new operators, in particular for the frontend because for Relay there is a guide. Usual unsupported operators become showstoppers when it comes to use frameworks like TVM.



@tico tf.size is supported now.


@yongwww that’s great news! Thanks a lot!