Skip to content

Commit

Permalink
Deploy onnx/onnx-mlir to github.com/onnx/onnx-mlir.git:gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
traviscibot committed Nov 17, 2020
1 parent 6a355ca commit 651b4ab
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Testing.md
Expand Up @@ -20,13 +20,33 @@ With BACKEND_TEST specified, the intermedia result, the .onnx file and .so file,

When the ONNX-to-Krnl conversion of an operator is added, the corresponding backend tests for this operator should be added to test.py. The available test cases can be found in third_part/onnx/onnx/backend/test/case/node. Please note to add suffix `_cpu` to the onnx test name.

The onnx node tests usually have known dimension size for input tensors. To test tensor with unknown dimension, the model importer (Build/FrontendONNXTransformer.cpp) provides a functionality to generate such cases. When the environment variable, `IMPORTER_FORCE_DYNAMIC`, is set, the frontend import will turn the first dimension of every input tensor of the model into -1. For example:
The onnx node tests usually have known dimension size for input tensors. To test tensor with unknown dimension, the model importer (Build/FrontendONNXTransformer.cpp) provides a functionality to generate such cases. When the environment variable, `IMPORTER_FORCE_DYNAMIC`, is set, the frontend import will turn the first dimension (by default) of some input tensor of the model into -1.
```
IMPORTER_FORCE_DYNAMIC=-1 all the inputs will be changed
IMPORTER_FORCE_DYNAMIC=0 the first input will be changed
IMPORTER_FORCE_DYNAMIC=n input[n] will be changed
```
For example, the default model for test_add_cpu is:

`func @main_graph(%arg0: tensor<3x4x5xf32>, %arg1: tensor<3x4x5xf32>) -> tensor<3x4x5xf32>`

with IMPORTER_FORCE_DYNAMIC=-1, the result is:

`@test_add(%arg0 : tensor<2x4xf32>, %arg1 : tensor<4xf32>)`
`func @main_graph(%arg0: tensor<?x4x5xf32>, %arg1: tensor<?x4x5xf32>) -> tensor<?x4x5xf32>`

will become
with IMPORTER_FORCE_DYNAMIC=0, the result is:

`func @main_graph(%arg0: tensor<?x4x5xf32>, %arg1: tensor<3x4x5xf32>) -> tensor<3x4x5xf32>`.

Which dimension to be changed can be specified with env variable `IMPORTER_FORCE_DYNAMIC`.
```
IMPORTER_FORCE_DYNAMIC_DIM=-1 all the dimensions to be changed
IMPORTER_FORCE_DYNAMIC_DIM=0 the first dimension
IMPORTER_FORCE_DYNAMIC_DIM=n the n+1 th dimension
```
For example, with `IMPORTER_FORCE_DYNAMIC=0 IMPORTER_FORCE_DYNAMIC_DIM=1`, the result is:

`@test_add(%arg0 : tensor<?x4xf32>, %arg1 : tensor<?xf32>)`.
`func @main_graph(%arg0: tensor<3x?x5xf32>, %arg1: tensor<3x4x5xf32>) -> tensor<3x4x5xf32> `

This is a way to use existing node test for dynamic tensors. Since not all test case can pass with dynamic tensor, there is a list in test/backend/test.py, test_not_for_dynamic, to specify which test can not pass with IMPORTER_FORCE_DYNAMIC is defined.

Expand Down

0 comments on commit 651b4ab

Please sign in to comment.