You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/04/06 21:29:27 UTC

[GitHub] [tvm] anwang2009 opened a new pull request, #10922: [FIX][FQ2I] Add abs to FQ2I, fix abs implementation for int

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

   - Adds `abs` to the FakeQuantizationToInteger pass.
   - Fixes the int `abs` implementation to not overflow, but rather clip when the absolute value of the minimum representable int value is taken. Otherwise, in the fq2i test I was seeing `abs(-128) => -128`


-- 
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] AndrewZhaoLuo commented on a diff in pull request #10922: [FIX][FQ2I] Add abs to FQ2I, fix abs implementation for int

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on code in PR #10922:
URL: https://github.com/apache/tvm/pull/10922#discussion_r845307339


##########
src/tir/op/op.cc:
##########
@@ -653,7 +653,27 @@ PrimExpr abs(PrimExpr x, Span span) {
     if (px) {
       return IntImm(x.dtype(), std::abs(px->value), px->span);
     }
-    return tir::Select(x >= make_zero(x.dtype()), x, -x, span);
+

Review Comment:
   Hmm honestly I'm not sure if I like this change since it actually is a change in the semantics of abs. 
   
   E.g. abs(-128) = 128 which should overflow to -128 with only 8 bits. 
   
   IMO two solutions:
   1. For integers, make it return uint version so it never overflows.
   2. Just handle the edge case manually in fq2i 
   
   If I understand this is only important to handle the -128 --> 127 case in quantized models so I say just put it in 2.



-- 
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] anwang2009 commented on pull request #10922: [FIX][FQ2I] Add abs to FQ2I, fix abs implementation for int

Posted by GitBox <gi...@apache.org>.
anwang2009 commented on PR #10922:
URL: https://github.com/apache/tvm/pull/10922#issuecomment-1090827770

   cc @MargaretQian @sfvaroglu @AndrewZhaoLuo 


-- 
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] AndrewZhaoLuo commented on a diff in pull request #10922: [FQ2I] Add abs to FQ2I

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on code in PR #10922:
URL: https://github.com/apache/tvm/pull/10922#discussion_r845740976


##########
python/tvm/relay/transform/fake_quantization_to_integer.py:
##########
@@ -109,6 +109,32 @@ def identity(expr, type_map):
 register_unary_identity("image.resize2d")
 
 
+@register_fake_quantization_to_integer("abs")
+def abs(expr, type_map):
+    assert len(expr.args) == 1
+    arg = expr.args[0]
+    t = type_map[arg]
+
+    if t.dtype == "int8":

Review Comment:
   I suggest you use np.iinfo
   
   e.g. 
   `np.iinfo('int32').min`



-- 
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] AndrewZhaoLuo commented on a diff in pull request #10922: [FIX][FQ2I] Add abs to FQ2I, fix abs implementation for int

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on code in PR #10922:
URL: https://github.com/apache/tvm/pull/10922#discussion_r845307339


##########
src/tir/op/op.cc:
##########
@@ -653,7 +653,27 @@ PrimExpr abs(PrimExpr x, Span span) {
     if (px) {
       return IntImm(x.dtype(), std::abs(px->value), px->span);
     }
-    return tir::Select(x >= make_zero(x.dtype()), x, -x, span);
+

Review Comment:
   Hmm honestly I'm not sure if I like this change since it actually is a change in the semantics of abs. 
   
   E.g. abs(-128) = 128 which should overflow to -128 with only 8 bits. abs(-128) should not be 127 under some arguments
   
   IMO two solutions:
   1. For integers, make it return uint version so it never overflows.
   2. Just handle the edge case manually in fq2i 
   
   If I understand this is only important to handle the -128 --> 127 case in quantized models so I say just put it in 2.



-- 
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] AndrewZhaoLuo merged pull request #10922: [FQ2I] Add abs to FQ2I

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo merged PR #10922:
URL: https://github.com/apache/tvm/pull/10922


-- 
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] anwang2009 commented on a diff in pull request #10922: [FIX][FQ2I] Add abs to FQ2I, fix abs implementation for int

Posted by GitBox <gi...@apache.org>.
anwang2009 commented on code in PR #10922:
URL: https://github.com/apache/tvm/pull/10922#discussion_r845382775


##########
src/tir/op/op.cc:
##########
@@ -653,7 +653,27 @@ PrimExpr abs(PrimExpr x, Span span) {
     if (px) {
       return IntImm(x.dtype(), std::abs(px->value), px->span);
     }
-    return tir::Select(x >= make_zero(x.dtype()), x, -x, span);
+

Review Comment:
   Yeah sounds good, I'll take approach 2. 



-- 
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