Skip to content

Conversation

@MichaelJKlaiber
Copy link
Contributor

@MichaelJKlaiber MichaelJKlaiber commented Aug 16, 2022

There was a flaw in uma_lower (see issue #12410) that lead in some case to a different argument ordering of the cached_func and the Relay function. This results in an incorrect lowering of the primfunc and eventually a wrong result of a run-time error, in some cases.

This commit adds code to correct the described misbehavior and a unit test case to check this end-to-end functionality with a TFLITE model.

@MichaelJKlaiber
Copy link
Contributor Author

@areusch @cgerum @manupak this is a fix to bug #12410

@areusch
Copy link
Contributor

areusch commented Aug 18, 2022

@mbaret wondering if you know the answer to this one (see attached PR)?

@MichaelJKlaiber
Copy link
Contributor Author

@areusch, you are referring to the question from #12410, right?

"

Seems the bug is in the lowering step from relay_prim_func to tir_prim_func.

When collecting the input arguments, the order gets messed up. By replacing the function _get_tensors here
https://github.com/MichaelJKlaiber/tvm/blob/issue/uma-tflite/python/tvm/relay/backend/contrib/uma/api/lower.py#L83

by

            return list(te_cached_func.inputs) + list(te_cached_func.outputs)

everything works perfectly fine for all the test case we provided including the tflite import

Does anyone know if it is sufficient to rely on the .inputs parameters from te_cached_func ?

"

@MichaelJKlaiber
Copy link
Contributor Author

@manupak, could you also review? There are some minor changes in aot.py, as well

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

Thanks for catching this (and fixing this)!
I agree that we should use cached_func argument ordering rather than finding the inputs seperately.

A single nit and I think we'll probably need a commit message prior to merging.

dtype = str(param.type_annotation.dtype)
in_min, in_max = (np.iinfo(dtype).min, np.iinfo(dtype).max)
data = np.random.randint(in_min, high=in_max, size=data_shape, dtype=dtype)
if dtype == "float32":
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use np.finfo to make it "generally" working for float dtypes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ...
what do you mean by "we'll probably need a commit message prior to merging"?

Copy link
Contributor

@manupak manupak Aug 20, 2022

Choose a reason for hiding this comment

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

A general title and a short description. There is a ongoing proposal to make this formal -- apache/tvm-rfcs#88.

For this one, if you can propose and change the title and decription in the PR, Im happy to use that as the commit title and description to align to support the above ongoing effort.

Additionally, the fact that this fixes #12410 should be part of the description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I was not clear before...

I was suggesting something like :

if np.issubdtype(dtype, np.floating) :

so this would generally work.

@MichaelJKlaiber MichaelJKlaiber changed the title Fix for Issue #12410:Issue/uma tflite [BugFix][UMA] Fix order issue in uma_lower Aug 21, 2022
Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

Thanks for the commit message!

Only a single comment and I think this is good to go...

dtype = str(param.type_annotation.dtype)
in_min, in_max = (np.iinfo(dtype).min, np.iinfo(dtype).max)
data = np.random.randint(in_min, high=in_max, size=data_shape, dtype=dtype)
if dtype == "float32":
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I was not clear before...

I was suggesting something like :

if np.issubdtype(dtype, np.floating) :

so this would generally work.

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

LGTM!

@manupak manupak merged commit 902343a into apache:main Aug 22, 2022
@manupak
Copy link
Contributor

manupak commented Aug 22, 2022

Thanks @MichaelJKlaiber!

xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
There was a flaw in uma_lower (see issue apache#12410) that lead in some case to a different argument ordering of the cached_func and the Relay function. This results in an incorrect lowering of the primfunc and eventually a wrong result of a run-time error, in some cases.

This commit adds code to correct the described misbehavior and a unit test case to check this end-to-end functionality with a TFLITE model.
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.

3 participants