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/01/19 21:30:32 UTC

[GitHub] [tvm] sfvaroglu commented on a change in pull request #9982: [QNN] Add qnn.rsqrt op

sfvaroglu commented on a change in pull request #9982:
URL: https://github.com/apache/tvm/pull/9982#discussion_r788154887



##########
File path: tests/python/relay/test_pass_fake_quantization_to_integer.py
##########
@@ -303,6 +303,19 @@ def test_fake_quantize_global_avg_pool():
     compare_fq_to_int(op, [x_np], True)
 
 
+def test_fake_quantize_rsqrt():
+    x = relay.var("x", shape=[1, 3, 224, 224], dtype="int8")
+    zero = relay.const(0)
+
+    x = relay.qnn.op.dequantize(x, relay.const(2.0), zero)
+    op = relay.rsqrt(x)
+    op = relay.qnn.op.quantize(op, relay.const(2.0), zero)
+
+    x_np = np.random.randint(-128, 127, size=[1, 3, 224, 224], dtype="int8")
+
+    compare_fq_to_int(op, [x_np], True)

Review comment:
       It lowers to qnn.rsqrt
   
   ```
   def @main(%x: Tensor[(1, 3, 224, 224), int8]) -> Tensor[(1, 3, 224, 224), int8] {
     %0 = qnn.dequantize(%x, 2f /* ty=float32 */, 0 /* ty=int32 */, Tensor[(1, 3, 224, 224), int8], float32, int32) /* ty=Tensor[(1, 3, 224, 224), float32] */;
     %1 = rsqrt(%0, Tensor[(1, 3, 224, 224), float32]) /* ty=Tensor[(1, 3, 224, 224), float32] */;
     qnn.quantize(%1, 2f /* ty=float32 */, 0 /* ty=int32 */, Tensor[(1, 3, 224, 224), float32], float32, int32, out_dtype="int8") /* ty=Tensor[(1, 3, 224, 224), int8] */
   }
   ```
   vs.
   ```
    def @main(%x: Tensor[(1, 3, 224, 224), int8]) -> Tensor[(1, 3, 224, 224), int8] {
     qnn.rsqrt(%x, 2f /* ty=float32 */, 0 /* ty=int32 */, 2f /* ty=float32 */, 0 /* ty=int32 */, Tensor[(1, 3, 224, 224), int8], float32, int32, float32, int32) /* ty=Tensor[(1, 3, 224, 224), int8] */
   }
   ```




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