-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
POC refactor tflite frontend #5528
Conversation
@FrozenGene, @anijain2305, @siju-samuel, @u99127, @mbaret Could you please review and let me know your thoughts? |
Have you seen #5519 ? Ramana |
Just now. I replied there. |
Yours goes further than #5519 and I'll think through it a bit more. My initial reaction is that this looks ok but there is one aspect that we could pull in here from 5519 : There is an appeal to keeping the number of inputs and outputs in the table and passing the input and output tensors to the helper functions seems to be high. It also seemed to me that the equality check could be done at the top level and any place where we had a range check we punted to the helper function as I had commented. I'll try and push out something the approach for something like conv2d. |
I thought of adding all the op attributes in table/map but decorator seemed to be more pythonic. Few more points to consider:
|
Thanks for the discussion and prompting this. I agree with you entirely with the motivation behind this that we should look to simplify the frontend, the amount of copy pasting to add a new operator isn't ideal and reducing the complexity is a good thing.
Ok.
That seems to be equivalent to -1 in the other scheme . So if we can't handle it in the common case because it has variable number of inputs but greater than a particular number for instance we need to make an operator specific check. I guess my question is whether a single decorator would be able to handle the most common cases. At the end of the day my goal is to reduce code duplication as much as I can avoid it which is why the table driven approach helps but as you say it has it's limits especially with the cases you mention. From a very old branch of mine, here is a table with the operator, helper function, number of inputs , number of outputs : all of which are likely to need just an equality check for number of inputs and outputs.
as these have fixed number of input and output tensors. My hunch is that we should be able to get to a single decorator for this sample set above falls out but I'd like to see what you think. Without working it out If on the other hand we end up with multiple decorators per helper for each of these , then we end up with duplication of code again and copy-pastism which I think is what we both want to avoid.
What would the relay expressions represent ?
I'm not sure I follow this one. |
Thanks for the response.
Let me clarify, the points which I mentioned are not for in or against both the approaches (table vs decorator). They were for general discussion. I think as far as code deduplication is considered both the approaches are fine. Both can achieve the same. The difference comes with the look and feel of it. And hence it is subjective and can be driven by personal choices. However, still, let me put a few pros of a decorator approach.
Let me know your thoughts.
Ok. Need to decide -1 or None.
I think a single decorator will suffice.
There is a common pattern where we convert TFLite tensor expression to Relay expression often using self.get_expr. Should we push back this conversion to a common code? Also a more generic implementation of conversion is added in this PR as get_tensor_expr function https://github.com/apache/incubator-tvm/pull/5528/files#diff-ee9a43edfb6fd0c9121e00c67c59ef43R2414.
I was thinking if we could somehow find some common code that will be a wrapper to code like below. But on the second though, I think it is not worth the effort. |
@u99127 @maheshambule Are we following up on this? |
@anijain2305, it would be great to hear your feedback/review on this proposed refactoring. |
@anijain2305 @u99127 please followup :) |
I am doing triage on old PRs, going to close this, please feel free to follow up if you would like to still merge these changes. Thanks for your contributions!. |
While working on TFLite Frontend ops, It was observed that most of the common code can be refactored to a single place.
For example below are few redundant things:
This PR is a POC to refactor tflite frontend. It adds a decorator which does all the things mentioned above. Currently, this PR demos the decorator for one operator only. I would like to hear opinions from the community about this approach and then once we decide on an approach/design we can refactor all the operators.
This change will allow new developers to quickly add new operators. Plus it will help reviewers also as new devs like me can not make obvious mistakes. :-)