dchauhan-arm commented on a change in pull request #9623:
URL: https://github.com/apache/tvm/pull/9623#discussion_r760240256
##########
File path: tests/python/contrib/test_ethosu/test_codegen.py
##########
@@ -183,83 +288,28 @@ def test_tflite_depthwise_conv2d(
dilation,
activation,
):
- dtype = "int8"
-
- def create_tflite_graph():
- class Model(tf.Module):
- @tf.function
- def depthwise_conv2d(self, x):
- weight_shape = [kernel_shape[0], kernel_shape[1],
ifm_shape[3], 1]
- weight = tf.constant(np.random.uniform(size=weight_shape),
dtype=tf.float32)
- # The input strides to the TensorFlow API needs to be of shape
1x4
- tf_strides = [1, strides[0], strides[1], 1]
- op = tf.nn.depthwise_conv2d(
- x, weight, strides=tf_strides, padding=padding,
dilations=dilation
- )
- if activation:
- op = tf.nn.relu(op)
- return op
-
- model = Model()
- concrete_func = model.depthwise_conv2d.get_concrete_function(
- tf.TensorSpec(ifm_shape, dtype=tf.float32)
+ @tf.function
+ def depthwise_conv2d(x):
+ weight_shape = [kernel_shape[0], kernel_shape[1], ifm_shape[3], 1]
+ weight = tf.constant(np.random.uniform(size=weight_shape),
dtype=tf.float32)
+ # The input strides to the TensorFlow API needs to be of shape 1x4
+ tf_strides = [1, strides[0], strides[1], 1]
+ op = tf.nn.depthwise_conv2d(
+ x, weight, strides=tf_strides, padding=padding, dilations=dilation
)
+ if activation:
+ op = tf.nn.relu(op)
+ return op
- # Convert the model
- def representative_dataset():
- for _ in range(100):
- data = np.random.rand(*tuple(ifm_shape))
- yield [data.astype(np.float32)]
-
- converter =
tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
- converter.optimizations = [tf.lite.Optimize.DEFAULT]
- converter.representative_dataset = representative_dataset
- converter.target_spec.supported_ops =
[tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
- converter.inference_input_type = tf.int8
- converter.inference_output_type = tf.int8
- tflite_model = converter.convert()
- return tflite_model
-
- tflite_graph = create_tflite_graph()
- tflite_model = tflite.Model.Model.GetRootAsModel(tflite_graph, 0)
-
- relay_module, params = relay.frontend.from_tflite(
- tflite_model,
- shape_dict={"input": ifm_shape},
- dtype_dict={"input": dtype},
- )
- mod = partition_for_ethosu(relay_module, params)
-
- # Generate reference data
- input_data, output_data = infra.generate_ref_data_tflite(tflite_graph)
-
- compiled_models = infra.build_source(
- mod,
- input_data,
- output_data,
- accel_type,
- )
-
- # Assumes only two runtime.Modules are created -- i.e. single offload
module
- imported_modules = compiled_models[0].executor_factory.lib.imported_modules
- assert len(imported_modules) == 2
- ethosu_module = imported_modules[0]
-
- # Verify generated C source
- get_cs = tvm._ffi.get_global_func("runtime.module.ethos-u.getcs")
- cmms = get_cs(ethosu_module)
- cmms = bytes.fromhex(cmms)
-
- infra.print_payload(cmms)
- infra.verify_source(compiled_models, accel_type)
+ _compare_tvm_with_tflite(depthwise_conv2d, [ifm_shape], accel_type)
@pytest.mark.parametrize(
"accel_type",
ACCEL_TYPES,
)
@pytest.mark.parametrize("pooling_type", ["MAX", "AVG"])
[email protected]("ifm_shape", [[1, 3, 4, 3], [1, 4, 5, 2]])
[email protected]("ifm_shape", [[1, 10, 10, 24], [1, 4, 5, 2]])
Review comment:
Same as above re: ifm_shape
--
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]