You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "zxybazh (via GitHub)" <gi...@apache.org> on 2023/02/25 05:38:24 UTC

[GitHub] [tvm] zxybazh opened a new pull request, #14127: [Unity][Legalize] Fix Scalar Constant Legalization

zxybazh opened a new pull request, #14127:
URL: https://github.com/apache/tvm/pull/14127

   This PR fixes the issue of loss of data type during Legalization. Previously, if we use a constant scalar in operators like `multiply`, it will automatically be converted to a python data type variable, which may lose its original data type. For example, `float16` may become python `float` and be interpreted as `float32` later.
   
   This is now fixed by avoiding scalar value conversion. The conversion could be added back once we have better support for scalar prim value.
   
   Co-authored by @sunggg and @vinx13.
   
   CC: @MasterJH5574 @tqchen 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] sunggg commented on a diff in pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "sunggg (via GitHub)" <gi...@apache.org>.
sunggg commented on code in PR #14127:
URL: https://github.com/apache/tvm/pull/14127#discussion_r1120341738


##########
python/tvm/relax/transform/legalize_ops/common.py:
##########
@@ -39,9 +39,11 @@
 ##################### Utilities #####################
 
 
-def _try_convert_to_scalar_const(expr: Expr) -> Union[Expr, bool, float, int]:
+def _try_convert_to_scalar_const(
+    expr: Expr, python_native: bool = False
+) -> Union[Expr, bool, float, int]:

Review Comment:
   Also, it would be nice to add this potential problem we found with python_native approach.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] sunggg commented on pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "sunggg (via GitHub)" <gi...@apache.org>.
sunggg commented on PR #14127:
URL: https://github.com/apache/tvm/pull/14127#issuecomment-1447539458

   Given that some tests fail, I think it would be better to fix this. 
   @zxybazh, can we track how we generate TIR function with constants? 
   Also, it seems like we also have `float64`. 
   In this case, if we convert it to generic float, we may lose some accuracy. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "zxybazh (via GitHub)" <gi...@apache.org>.
zxybazh commented on PR #14127:
URL: https://github.com/apache/tvm/pull/14127#issuecomment-1447663997

   Thanks @MasterJH5574 and @sunggg, I think Ruihang's suggestion makes sense and we can preserve the data type via IntImm and FloatImm. I also added an extra argument of whether to return native python type, because in some cases, e.g. `full` operator, we may want to get the python native value. This should also work with most of the current tests.
   
   For Sung's concern of preserving float type, please see the first added unit test where fp16 can be preserved. I think `fp64` can be preserved in the same way.
   
   Please take another look at your convenience, thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "zxybazh (via GitHub)" <gi...@apache.org>.
zxybazh commented on PR #14127:
URL: https://github.com/apache/tvm/pull/14127#issuecomment-1448698320

   Thanks for the advice! Type annotation has been fixed and I added docs explaining loss of data type with use of `python_native=True`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] MasterJH5574 commented on a diff in pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 commented on code in PR #14127:
URL: https://github.com/apache/tvm/pull/14127#discussion_r1120143514


##########
python/tvm/relax/transform/legalize_ops/common.py:
##########
@@ -39,9 +39,11 @@
 ##################### Utilities #####################
 
 
-def _try_convert_to_scalar_const(expr: Expr) -> Union[Expr, bool, float, int]:
+def _try_convert_to_scalar_const(
+    expr: Expr, python_native: bool = False
+) -> Union[Expr, bool, float, int]:

Review Comment:
   Would you mind adding IntImm/FloatImm to the return annotation here, and add some doc string for `python_native`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] MasterJH5574 merged pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 merged PR #14127:
URL: https://github.com/apache/tvm/pull/14127


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] MasterJH5574 commented on pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 commented on PR #14127:
URL: https://github.com/apache/tvm/pull/14127#issuecomment-1447545072

   Thanks for catching this and sorry for the late reply. Here the place where we turn scalars into Python native POD value is here
   https://github.com/apache/tvm/blob/ec868ebc58175431250c5f56af10749b77347f51/python/tvm/relax/transform/legalize_ops/common.py#L60
   
   Considering this issue, I suppose changing the logic here to “create and return IntImm/FloatImm/...” instead of directly returning Python POD value will work. Would be great if you can help try and confirm this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tvm-bot commented on pull request #14127: [Unity][Legalize] Fix Scalar Constant Legalization

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14127:
URL: https://github.com/apache/tvm/pull/14127#issuecomment-1445001239

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @quic-sanirudh <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org