|
1 | 1 | import unittest
|
2 | 2 | import numpy as np
|
3 | 3 | from onnx import TensorProto
|
| 4 | +from onnx.checker import check_model |
4 | 5 | from onnx.helper import (
|
5 | 6 | make_function,
|
6 | 7 | make_graph,
|
|
9 | 10 | make_opsetid,
|
10 | 11 | make_tensor_value_info,
|
11 | 12 | )
|
| 13 | +from onnx.numpy_helper import from_array |
12 | 14 | from onnx.parser import parse_model
|
13 | 15 | from onnx_array_api.ext_test_case import ExtTestCase
|
14 | 16 | from onnx_array_api.reference import (
|
@@ -422,13 +424,13 @@ def test_distance_sequence_str(self):
|
422 | 424 | text = dc.to_str(s1, s2, align)
|
423 | 425 | self.assertIn("OUTPUT", text)
|
424 | 426 | expected = """
|
425 |
| - 001=|INPUTfloat322x2ABCDA|INPUTfloat322x2ABCDA |
426 |
| - 002=|INPUTfloat322x2ABCDB|INPUTfloat322x2ABCDB |
427 |
| - 003~|INPUTfloat322x3ABCDX|INPUTfloat322x2ABCDX |
428 |
| - 004-|RESULTfloat322x2CEIOExpH| |
429 |
| - 005=|RESULTfloat322x2CEIOLinearRegrY1|RESULTfloat322x2CEIOLinearRegrY1 |
430 |
| - 006~|RESULTfloat322x2CEIOAbsY|RESULTfloat322x3CEIPAbsZ |
431 |
| - 007~|OUTPUTfloat322x2CEIOY|OUTPUTfloat322x2CEIPY |
| 427 | + 001=|INPUTfloat322:2x2ABCDA|INPUTfloat322:2x2ABCDA |
| 428 | + 002=|INPUTfloat322:2x2ABCDB|INPUTfloat322:2x2ABCDB |
| 429 | + 003~|INPUTfloat322:2x3ABCDX|INPUTfloat322:2x2ABCDX |
| 430 | + 004-|RESULTfloat322:2x2CEIOExpH| |
| 431 | + 005=|RESULTfloat322:2x2CEIOLinearRegressioY1|RESULTfloat322:2x2CEIOLinearRegressioY1 |
| 432 | + 006~|RESULTfloat322:2x2CEIOAbsY|RESULTfloat322:2x3CEIPAbsZ |
| 433 | + 007~|OUTPUTfloat322:2x2CEIOY|OUTPUTfloat322:2x2CEIPY |
432 | 434 | """.replace(
|
433 | 435 | " ", ""
|
434 | 436 | ).strip(
|
@@ -460,6 +462,68 @@ def test_compare_execution(self):
|
460 | 462 | self.assertIn("CAAA Constant", text)
|
461 | 463 | self.assertEqual(len(align), 5)
|
462 | 464 |
|
| 465 | + def test_no_execution(self): |
| 466 | + model = make_model( |
| 467 | + make_graph( |
| 468 | + [ |
| 469 | + make_node("Unsqueeze", ["X", "zero"], ["xu1"]), |
| 470 | + make_node("Unsqueeze", ["xu1", "un"], ["xu2"]), |
| 471 | + make_node("Reshape", ["xu2", "shape1"], ["xm1"]), |
| 472 | + make_node("Reshape", ["Y", "shape2"], ["xm2c"]), |
| 473 | + make_node("Cast", ["xm2c"], ["xm2"], to=1), |
| 474 | + make_node("MatMul", ["xm1", "xm2"], ["xm"]), |
| 475 | + make_node("Reshape", ["xm", "shape3"], ["Z"]), |
| 476 | + ], |
| 477 | + "dummy", |
| 478 | + [ |
| 479 | + make_tensor_value_info("X", TensorProto.FLOAT, [32, 128]), |
| 480 | + make_tensor_value_info("Y", TensorProto.FLOAT, [3, 5, 128, 64]), |
| 481 | + ], |
| 482 | + [make_tensor_value_info("Z", TensorProto.FLOAT, [3, 5, 32, "N"])], |
| 483 | + [ |
| 484 | + from_array(np.array([0], dtype=np.int64), name="zero"), |
| 485 | + from_array(np.array([1], dtype=np.int64), name="un"), |
| 486 | + from_array(np.array([1, 32, 128], dtype=np.int64), name="shape1"), |
| 487 | + from_array(np.array([15, 128, 64], dtype=np.int64), name="shape2"), |
| 488 | + from_array(np.array([3, 5, 32, 64], dtype=np.int64), name="shape3"), |
| 489 | + ], |
| 490 | + ) |
| 491 | + ) |
| 492 | + check_model(model) |
| 493 | + res1, res2, align, dc = compare_onnx_execution(model, model, mode="nodes") |
| 494 | + text = dc.to_str(res1, res2, align) |
| 495 | + self.assertIn("012 = | NODE", text) |
| 496 | + |
| 497 | + model2 = make_model( |
| 498 | + make_graph( |
| 499 | + [ |
| 500 | + make_node("Unsqueeze", ["X", "zero"], ["xu1"]), |
| 501 | + make_node("Unsqueeze", ["xu1", "un"], ["xu2"]), |
| 502 | + make_node("Reshape", ["xu2", "shape1"], ["xm1"]), |
| 503 | + make_node("Reshape", ["Y", "shape2"], ["xm2c"]), |
| 504 | + make_node("MatMul", ["xm1", "xm2c"], ["xm"]), |
| 505 | + make_node("Reshape", ["xm", "shape3"], ["Z"]), |
| 506 | + ], |
| 507 | + "dummy", |
| 508 | + [ |
| 509 | + make_tensor_value_info("X", TensorProto.FLOAT, [32, 128]), |
| 510 | + make_tensor_value_info("Y", TensorProto.FLOAT, [3, 5, 128, 64]), |
| 511 | + ], |
| 512 | + [make_tensor_value_info("Z", TensorProto.FLOAT, [3, 5, 32, "N"])], |
| 513 | + [ |
| 514 | + from_array(np.array([0], dtype=np.int64), name="zero"), |
| 515 | + from_array(np.array([1], dtype=np.int64), name="un"), |
| 516 | + from_array(np.array([1, 32, 128], dtype=np.int64), name="shape1"), |
| 517 | + from_array(np.array([15, 128, 64], dtype=np.int64), name="shape2"), |
| 518 | + from_array(np.array([3, 5, 32, 64], dtype=np.int64), name="shape3"), |
| 519 | + ], |
| 520 | + ) |
| 521 | + ) |
| 522 | + check_model(model2) |
| 523 | + res1, res2, align, dc = compare_onnx_execution(model, model2, mode="nodes") |
| 524 | + text = dc.to_str(res1, res2, align) |
| 525 | + self.assertIn("012 = | NODE", text) |
| 526 | + |
463 | 527 |
|
464 | 528 | if __name__ == "__main__":
|
465 | 529 | unittest.main(verbosity=2)
|
0 commit comments