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/11/11 07:04:02 UTC

[GitHub] [tvm] ibsidorenko commented on a diff in pull request #13332: [FQ2I] Add cast back to input data type after AvgPool2d

ibsidorenko commented on code in PR #13332:
URL: https://github.com/apache/tvm/pull/13332#discussion_r1019895655


##########
python/tvm/relay/transform/fake_quantization_to_integer.py:
##########
@@ -158,7 +159,10 @@ def avgpool2d(expr, type_map):
     else:
         arg = relay.op.cast(arg, "int32")
     out = relay.op.nn.avg_pool2d(arg, **expr.attrs)
-    return [out, TensorAffineType(out_t.scale, out_t.zero_point, "int32", out_t.axis)]
+    # Cast back to input dtype to preserve input dtype == output dtype.
+    out = relay.op.clip(out, a_min=np.iinfo(t.dtype).min, a_max=np.iinfo(t.dtype).max)
+    out = relay.op.cast(out, t.dtype)

Review Comment:
   Make sense. Changed on `out_t.dtype` + if condition.



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