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 2021/04/11 08:04:45 UTC

[GitHub] [tvm] jcf94 commented on a change in pull request #7814: [Topi & Relay] Add quantization support for the vision transform model in GPU

jcf94 commented on a change in pull request #7814:
URL: https://github.com/apache/tvm/pull/7814#discussion_r611146143



##########
File path: python/tvm/relay/op/strategy/cuda.py
##########
@@ -722,12 +722,20 @@ def dense_strategy_cuda(attrs, inputs, out_type, target):
 def batch_matmul_strategy_cuda(attrs, inputs, out_type, target):
     """batch_matmul cuda strategy"""
     strategy = _op.OpStrategy()
-    strategy.add_implementation(
-        wrap_compute_batch_matmul(topi.cuda.batch_matmul),
-        wrap_topi_schedule(topi.cuda.schedule_batch_matmul),
-        name="batch_matmul.cuda",
-        plevel=10,
-    )
+    x, y = inputs
+    if x.dtype == "int8" and y.dtype == "int8" and out_type.dtype == "int32":
+        strategy.add_implementation(
+            wrap_compute_batch_matmul(topi.cuda.batch_matmul_int8, need_out_dtype=True),
+            wrap_topi_schedule(topi.cuda.schedule_batch_matmul_int8),
+            name="batch_matmul_int8.cuda",

Review comment:
       Add a proper plevel for this implementation.

##########
File path: tests/python/nightly/quantization/test_quantization_accuracy_for_vit.py
##########
@@ -0,0 +1,129 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import tvm
+import os
+from tvm import relay
+from tvm.relay import quantize as qtz
+import logging
+import onnx
+import tvm.testing
+import mxnet as mx
+from test_quantization_accuracy import Config, get_val_data, eval_acc
+
+logging.basicConfig(level=logging.INFO)
+
+
+def calibrate_dataset(model_name, rec_val, batch_size, calibration_samples):
+    val_data, _ = get_val_data(model_name, rec_val=rec_val, batch_size=batch_size)
+    val_data.reset()
+    for i, batch in enumerate(val_data):
+        if i * batch_size >= calibration_samples:
+            break
+        data = batch.data[0].asnumpy()
+        yield {"data": data}
+
+
+def get_onnx_model(model_name, batch_size, qconfig, target=None, original=False, dataset=None):
+
+    assert model_name == "vit32", "Only support vit32 model!"
+    logfile = "gtx1660_vit_B32_224.log"
+    onnx_path = "vit_B32_224.onnx"
+
+    if not os.path.exists(logfile):
+        os.system("wget https://github.com/TheGreatCold/tvm-vit/raw/master/{}".format(logfile))
+    if not os.path.exists(onnx_path):
+        os.system("wget https://github.com/TheGreatCold/tvm-vit/raw/master/{}".format(onnx_path))

Review comment:
       As a unit test, I'm thinking that this may not be so good to involve a resource outside. (Network problem or changes to the `tvm-vit` repo may break the UT. At least use git commit instad of branch like: `https://github.com/TheGreatCold/tvm-vit/raw/d2aa1e60eef42e2fdedbd1e13aa85ac5faf0a7fc/vit_B32_224.onnx` will be better)
   I'm not sure if there's any better solution for this. @tqchen Do you have any suggestion?




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

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