sunshinemyson commented on a change in pull request #9046: URL: https://github.com/apache/tvm/pull/9046#discussion_r713974334
########## File path: tests/python/contrib/test_vsi_npu/test_operations.py ########## @@ -0,0 +1,1673 @@ +# 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. +#from python.tvm.relay.qnn.op.qnn import dequantize +import tvm +from tvm import relay +from tvm.relay import testing +import numpy as np +from infrastructure import verify_vsi_result + +def _single_operation_test(relay_nn_func, dtype, data_shape, out_shape, + *args, **kargs): + op_name = relay_nn_func.__name__.upper() + print("Testing {0: <50}".format(op_name), end="") + data = relay.var("data", shape=data_shape, dtype=dtype) + + out = relay_nn_func(data, *args, **kargs) + + args = relay.analysis.free_vars(out) + net = relay.Function(args, out) + + mod, params = relay.testing.init.create_workload(net) + + verify_vsi_result(mod, params, data_shape, out_shape, dtype) + +def test_global_avg_pool2d(): + func = relay.nn.global_avg_pool2d + + dtype = "float32" + data_shape = (1, 20, 12, 9) + out_shape = (1, 20, 1, 1) + _single_operation_test(func, dtype, data_shape, out_shape) + +def test_global_max_pool2d(): + func = relay.nn.global_max_pool2d + + dtype = "float32" + data_shape = (1, 20, 12, 9) + out_shape = (1, 20, 1, 1) + _single_operation_test(func, dtype, data_shape, out_shape) + +def test_avg_pool2d(): + func = relay.nn.avg_pool2d + + dtype = "float32" + data_shape = (1, 1, 20, 20) + out_shape = (1, 1, 10, 10) + _single_operation_test(func, dtype, data_shape, out_shape, pool_size=(3, 3), + strides=(2, 2), padding=(1,1,1,1)) + +def test_max_pool2d(): + func = relay.nn.max_pool2d + + dtype = "float32" + data_shape = (1, 1, 20, 20) + out_shape = (1, 1, 10, 10) + _single_operation_test(func, dtype, data_shape, out_shape, pool_size=(2, 2), + strides=(2, 2), padding=(0,0,0,0)) + +def test_softmax(): + func = relay.nn.softmax + + dtype = "float32" + data_shape = (1, 20, 12, 9) + out_shape = data_shape + _single_operation_test(func, dtype, data_shape, out_shape) + +def test_relu(): + func = relay.nn.relu + + dtype = "float32" + data_shape = (1, 20, 12, 9) + out_shape = data_shape + _single_operation_test(func, dtype, data_shape, out_shape) + +def test_add(): + dtype = "float32" + data_shape = (1, 20, 12, 9) + out_shape = data_shape + + def get_workload(data_shape, dtype="float32"): + '''customized keywords(like data0,data1...) are not supported in \ + relay.testing.init.create_workload + ''' + data0 = relay.var("data", shape=data_shape, dtype=dtype) + data1 = relay.var("weight", shape=data_shape, dtype=dtype) + + out = relay.add(data0, data1) + + args = relay.analysis.free_vars(out) + net = relay.Function(args, out) + + return relay.testing.init.create_workload(net) + + print("Testing {0: <50}".format("ADD"), end="") Review comment: Acutally, we didn't use pytest in the test scripts. I think we need refactor all the tests with pytest? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
