def run_sequential_model(model_fn, input_shape): def get_input(shape): _input = np.random.uniform(0, 1, shape).astype(dtype="float32") return _input def save_and_reload(_model): with tempfile.TemporaryDirectory() as model_path: tf.saved_model.save(_model, model_path) loaded = tf.saved_model.load(model_path) func = loaded.signatures["serving_default"] frozen_func = convert_variables_to_constants_v2(func) return frozen_func def model_graph(model, input_shape): _input = get_input(input_shape) f = save_and_reload(model(input_shape)) _output = run_tf_code(f, _input) gdef = f.graph.as_graph_def(add_shapes=True) return gdef, _input, _output compare_tf_tvm(*model_graph(model_fn, input_shape), runtime="vm")
def run_model_graph(TestClass): compare_tf_tvm(*_model_graph(TestClass), runtime="vm")
def run_func_graph(TestClass, runtime="vm"): compare_tf_tvm(*_function_graph(TestClass), runtime=runtime)
def run_model_graph(TestClass, outputs=None): compare_tf_tvm(*_model_graph(TestClass), runtime="vm", output_tensors=outputs)
def run_func_graph(TestClass, runtime="vm", outputs=None): compare_tf_tvm(*_function_graph(TestClass), runtime=runtime, output_tensors=outputs)