From 536e48da79ee374527c669f77ad9e0a0776a0bb8 Mon Sep 17 00:00:00 2001 From: Fei Wang Date: Tue, 9 Oct 2018 23:40:00 -0400 Subject: [PATCH] untest resnet (too expensive for regular test) --- src/test/scala/lantern/test_onnx.scala | 122 ++++++++++++------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/test/scala/lantern/test_onnx.scala b/src/test/scala/lantern/test_onnx.scala index 2059ff1c..5be0118f 100644 --- a/src/test/scala/lantern/test_onnx.scala +++ b/src/test/scala/lantern/test_onnx.scala @@ -508,65 +508,65 @@ class ONNXTest extends LanternFunSuite { runTest(training_func) } - test("resnet_inference") { - - val model_file = model_file_all("resnet50") - val model_dir = model_dir_all("resnet50") - System.out.println(s"testing reading ONNX model using library from $model_file") - - val inference_func = new LanternDriverC[String, Unit] with ONNXLib { - - @virtualize - def snippet(a: Rep[String]): Rep[Unit] = { - val model = readONNX(model_file) - val (func, x_dims) = (model.inference_func, model.x_dims) - - // get test data as TensorProto - val input_file = model_dir + "test_data_set_0/input_0.pb" - val output_file = model_dir + "test_data_set_0/output_0.pb" - val input = readTensor(input_file).tensor - val output = readTensor(output_file).tensor - val output1 = func(input) - Tensor.assertEqual(output, output1) - } - } - val resnet_file = new PrintWriter(new File(gene_dir + "resnet.cpp")) - resnet_file.println(inference_func.code) - resnet_file.flush() - runTest(inference_func) - } - - test("resnet_training") { - - val model_file = model_file_all("resnet50") - val model_dir = model_dir_all("resnet50") - System.out.println(s"testing reading ONNX model using library from $model_file for training") - - val training_func = new LanternDriverC[String, Unit] with ONNXLib { - - @virtualize - def snippet(a: Rep[String]): Rep[Unit] = { - val model = readONNX(model_file) - val (func, x_dims, y_dims) = (model.training_func, model.x_dims, model.y_dims) - - // fake input and target - val input_file = model_dir + "test_data_set_0/input_0.pb" - val output_file = model_dir + "test_data_set_0/output_0.pb" - val input = readTensor(input_file).tensor - val output = readTensor(output_file).tensor - - val target = NewArray[Int](x_dims(0)) - for (i <- DataLoop(x_dims(0))) target(i) = 1 - def lossFun(dummy: TensorR) = func(TensorR(input)).nllLossB(target).sum() - - val loss = gradR_loss(lossFun)(Tensor.zeros(1)) - println(loss.data(0)) - } - } - - val resnet_file = new PrintWriter(new File(gene_dir + "resnetTraining.cpp")) - resnet_file.println(training_func.code) - resnet_file.flush() - // runTest(training_func) - } + // test("resnet_inference") { + + // val model_file = model_file_all("resnet50") + // val model_dir = model_dir_all("resnet50") + // System.out.println(s"testing reading ONNX model using library from $model_file") + + // val inference_func = new LanternDriverC[String, Unit] with ONNXLib { + + // @virtualize + // def snippet(a: Rep[String]): Rep[Unit] = { + // val model = readONNX(model_file) + // val (func, x_dims) = (model.inference_func, model.x_dims) + + // // get test data as TensorProto + // val input_file = model_dir + "test_data_set_0/input_0.pb" + // val output_file = model_dir + "test_data_set_0/output_0.pb" + // val input = readTensor(input_file).tensor + // val output = readTensor(output_file).tensor + // val output1 = func(input) + // Tensor.assertEqual(output, output1) + // } + // } + // val resnet_file = new PrintWriter(new File(gene_dir + "resnet.cpp")) + // resnet_file.println(inference_func.code) + // resnet_file.flush() + // runTest(inference_func) + // } + + // test("resnet_training") { + + // val model_file = model_file_all("resnet50") + // val model_dir = model_dir_all("resnet50") + // System.out.println(s"testing reading ONNX model using library from $model_file for training") + + // val training_func = new LanternDriverC[String, Unit] with ONNXLib { + + // @virtualize + // def snippet(a: Rep[String]): Rep[Unit] = { + // val model = readONNX(model_file) + // val (func, x_dims, y_dims) = (model.training_func, model.x_dims, model.y_dims) + + // // fake input and target + // val input_file = model_dir + "test_data_set_0/input_0.pb" + // val output_file = model_dir + "test_data_set_0/output_0.pb" + // val input = readTensor(input_file).tensor + // val output = readTensor(output_file).tensor + + // val target = NewArray[Int](x_dims(0)) + // for (i <- DataLoop(x_dims(0))) target(i) = 1 + // def lossFun(dummy: TensorR) = func(TensorR(input)).nllLossB(target).sum() + + // val loss = gradR_loss(lossFun)(Tensor.zeros(1)) + // println(loss.data(0)) + // } + // } + + // val resnet_file = new PrintWriter(new File(gene_dir + "resnetTraining.cpp")) + // resnet_file.println(training_func.code) + // resnet_file.flush() + // // runTest(training_func) + // } } \ No newline at end of file