You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "mehrdadh (via GitHub)" <gi...@apache.org> on 2023/01/23 22:37:39 UTC

[GitHub] [tvm] mehrdadh commented on a diff in pull request #12873: [Hexagon] Float and quantized dense operators with schedules

mehrdadh commented on code in PR #12873:
URL: https://github.com/apache/tvm/pull/12873#discussion_r1084641685


##########
tests/python/contrib/test_hexagon/topi/slice_op/test_dense_slice.py:
##########
@@ -0,0 +1,297 @@
+# 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 pytest
+import numpy as np
+
+from tvm import te, topi
+
+import tvm.testing
+from tvm.topi import testing
+from tvm.contrib.hexagon.build import HexagonLauncher
+from tvm.contrib.hexagon.session import Session
+import tvm.topi.hexagon.qnn as qnn
+import tvm.topi.hexagon.slice_ops as sl
+from ...infrastructure import transform_numpy, quantize_np
+from tvm.contrib.hexagon import allocate_hexagon_array
+
+
+@tvm.testing.fixture
+def input_np(input_shape, dtype):
+    if "int" in dtype:
+        data = np.random.random(input_shape).astype("float32")
+    elif "float" in dtype:
+        data = np.random.random(input_shape).astype(dtype)
+    return data
+
+
+@tvm.testing.fixture
+def weight_np(weight_shape, dtype):
+    if "int" in dtype:
+        weight = np.random.random(weight_shape).astype("float32")
+    elif "float" in dtype:
+        weight = np.random.random(weight_shape).astype(dtype)
+    return weight
+
+
+@tvm.testing.fixture
+def input_quant(input_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(input_np, dtype)
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def weight_quant(weight_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(weight_np, "int8")
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def bias_np(bias_shape, bias, dtype):
+    if bias:
+        if "int" in dtype:
+            data = np.random.randint(-128, 127, size=bias_shape).astype("int32")
+        elif "float" in dtype:
+            data = np.random.random(bias_shape).astype(dtype)
+        return data
+    else:
+        return None
+
+
+@tvm.testing.fixture
+def quant_arr(input_quant, weight_quant):
+    if input_quant is None:
+        return None
+    arr = np.empty((6,), dtype="float32")
+    arr[0] = input_quant["zero"]
+    arr[1] = input_quant["scale"]
+    arr[2] = weight_quant["zero"]
+    arr[3] = weight_quant["scale"]
+    return arr
+
+
+@tvm.testing.fixture
+def transformed_expected_output_np(expected_output_np, layout):
+    return transform_numpy(expected_output_np, "nc", layout)
+
+
+@tvm.testing.fixture
+def transformed_input_np(input_np, layout):
+    return transform_numpy(input_np, "nc", layout)
+
+
+# TODO(joshherr-quic): transforming weight forces us to put it in vtcm. Crashes at runtime in vtcm
+# @tvm.testing.fixture
+# def transformed_weight_np(weight_np, layout):
+#     return transform_numpy(weight_np, "nc", layout)
+
+
+@tvm.testing.fixture
+def transformed_input_quant(input_quant, layout):
+    if input_quant is None:
+        return None
+    input_quant["data"] = transform_numpy(input_quant["data"], "nc", layout)
+    return input_quant
+
+
+# @tvm.testing.fixture
+# def transformed_weight_quant(weight_quant, layout):
+#     weight_quant["data"] = transform_numpy(weight_quant["data"], "nc", layout)
+#     return weight_quant
+
+# Test combinations of the following:

Review Comment:
   These comments are also not needed, testing parameters show the combination



##########
tests/python/contrib/test_hexagon/topi/slice_op/test_dense_slice.py:
##########
@@ -0,0 +1,297 @@
+# 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 pytest
+import numpy as np
+
+from tvm import te, topi
+
+import tvm.testing
+from tvm.topi import testing
+from tvm.contrib.hexagon.build import HexagonLauncher
+from tvm.contrib.hexagon.session import Session
+import tvm.topi.hexagon.qnn as qnn
+import tvm.topi.hexagon.slice_ops as sl
+from ...infrastructure import transform_numpy, quantize_np
+from tvm.contrib.hexagon import allocate_hexagon_array
+
+
+@tvm.testing.fixture
+def input_np(input_shape, dtype):
+    if "int" in dtype:
+        data = np.random.random(input_shape).astype("float32")
+    elif "float" in dtype:
+        data = np.random.random(input_shape).astype(dtype)
+    return data
+
+
+@tvm.testing.fixture
+def weight_np(weight_shape, dtype):
+    if "int" in dtype:
+        weight = np.random.random(weight_shape).astype("float32")
+    elif "float" in dtype:
+        weight = np.random.random(weight_shape).astype(dtype)
+    return weight
+
+
+@tvm.testing.fixture
+def input_quant(input_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(input_np, dtype)
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def weight_quant(weight_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(weight_np, "int8")
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def bias_np(bias_shape, bias, dtype):
+    if bias:
+        if "int" in dtype:
+            data = np.random.randint(-128, 127, size=bias_shape).astype("int32")
+        elif "float" in dtype:
+            data = np.random.random(bias_shape).astype(dtype)
+        return data
+    else:
+        return None
+
+
+@tvm.testing.fixture
+def quant_arr(input_quant, weight_quant):
+    if input_quant is None:
+        return None
+    arr = np.empty((6,), dtype="float32")
+    arr[0] = input_quant["zero"]
+    arr[1] = input_quant["scale"]
+    arr[2] = weight_quant["zero"]
+    arr[3] = weight_quant["scale"]
+    return arr
+
+
+@tvm.testing.fixture
+def transformed_expected_output_np(expected_output_np, layout):
+    return transform_numpy(expected_output_np, "nc", layout)
+
+
+@tvm.testing.fixture
+def transformed_input_np(input_np, layout):
+    return transform_numpy(input_np, "nc", layout)
+
+
+# TODO(joshherr-quic): transforming weight forces us to put it in vtcm. Crashes at runtime in vtcm
+# @tvm.testing.fixture
+# def transformed_weight_np(weight_np, layout):
+#     return transform_numpy(weight_np, "nc", layout)
+
+
+@tvm.testing.fixture
+def transformed_input_quant(input_quant, layout):
+    if input_quant is None:
+        return None
+    input_quant["data"] = transform_numpy(input_quant["data"], "nc", layout)
+    return input_quant
+
+
+# @tvm.testing.fixture

Review Comment:
   same here



##########
tests/python/contrib/test_hexagon/topi/slice_op/test_dense_slice.py:
##########
@@ -0,0 +1,297 @@
+# 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 pytest
+import numpy as np
+
+from tvm import te, topi
+
+import tvm.testing
+from tvm.topi import testing
+from tvm.contrib.hexagon.build import HexagonLauncher
+from tvm.contrib.hexagon.session import Session
+import tvm.topi.hexagon.qnn as qnn
+import tvm.topi.hexagon.slice_ops as sl
+from ...infrastructure import transform_numpy, quantize_np
+from tvm.contrib.hexagon import allocate_hexagon_array
+
+
+@tvm.testing.fixture
+def input_np(input_shape, dtype):
+    if "int" in dtype:
+        data = np.random.random(input_shape).astype("float32")
+    elif "float" in dtype:
+        data = np.random.random(input_shape).astype(dtype)
+    return data
+
+
+@tvm.testing.fixture
+def weight_np(weight_shape, dtype):
+    if "int" in dtype:
+        weight = np.random.random(weight_shape).astype("float32")
+    elif "float" in dtype:
+        weight = np.random.random(weight_shape).astype(dtype)
+    return weight
+
+
+@tvm.testing.fixture
+def input_quant(input_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(input_np, dtype)
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def weight_quant(weight_np, dtype):
+    if "float" in dtype:
+        return None
+    quant, scale, zp = quantize_np(weight_np, "int8")
+    return {"zero": zp, "scale": scale, "data": quant}
+
+
+@tvm.testing.fixture
+def bias_np(bias_shape, bias, dtype):
+    if bias:
+        if "int" in dtype:
+            data = np.random.randint(-128, 127, size=bias_shape).astype("int32")
+        elif "float" in dtype:
+            data = np.random.random(bias_shape).astype(dtype)
+        return data
+    else:
+        return None
+
+
+@tvm.testing.fixture
+def quant_arr(input_quant, weight_quant):
+    if input_quant is None:
+        return None
+    arr = np.empty((6,), dtype="float32")
+    arr[0] = input_quant["zero"]
+    arr[1] = input_quant["scale"]
+    arr[2] = weight_quant["zero"]
+    arr[3] = weight_quant["scale"]
+    return arr
+
+
+@tvm.testing.fixture
+def transformed_expected_output_np(expected_output_np, layout):
+    return transform_numpy(expected_output_np, "nc", layout)
+
+
+@tvm.testing.fixture
+def transformed_input_np(input_np, layout):
+    return transform_numpy(input_np, "nc", layout)
+
+
+# TODO(joshherr-quic): transforming weight forces us to put it in vtcm. Crashes at runtime in vtcm

Review Comment:
   please remove these comments.



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