You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/function_libs/torch_lib/README.md
+57-5Lines changed: 57 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,19 @@
1
-
# Test op correctness by comparing with PyTorch results
1
+
# Test op correctness by comparing with PyTorch results using OpInfo
2
+
3
+
`OpInfo` is PyTorch's standard mechanism for composing test data for operators.
4
+
Read more about them on https://github.com/pytorch/pytorch/blob/ce4a097bf769d753712a1fd969b446c59e29d8b9/torch/testing/_internal/opinfo/core.py#L362.
@@ -25,4 +28,53 @@ in onnxruntime by running the inference sessions in a separate process.
25
28
26
29
## How to add a new operator test
27
30
28
-
See _usage_ in [ops_test_data.py](./ops_test_data.py)
31
+
See _usage_ in [`ops_test_data.py`](./ops_test_data.py)
32
+
33
+
## How to add custom OpInfo tests
34
+
35
+
Sometimes, there is no existing OpInfo that fits our need to test an operator. You want to create a custom OpInfo for it.
36
+
37
+
Follow the steps below to create new OpInfo tests:
38
+
39
+
1. Use the implementation for`ops.aten.slice_scatter` as a reference (https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/extra_opinfo.py#L2412-L2418) to declare an OpInfoin [`extra_opinfo.py`](./extra_opinfo.py)
- The first argument should be the operator name under the `torch.ops` namespace. For example, if you want to test the `prims.var` op, then put `"ops.prims.var"`. It should almost always start with `ops.`.
52
+
- Follow existing examples to specify the `dtypes` you want to test the op on.
53
+
- Specify `op=`if the target operator is not the same as the OpInfo name (first arg). For example https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/extra_opinfo.py#L2065-L2068.
54
+
55
+
```py
56
+
opinfo_core.OpInfo(
57
+
"ops.aten.bernoulli.p_deterministic",
58
+
op=torch.ops.aten.bernoulli.p,
59
+
```
60
+
61
+
The op is `torch.ops.aten.bernoulli.p`, which is different from the name `ops.aten.bernoulli.p_deterministic`. OpInfo names need to be globally unique in a test suite. When `op` is not specified, it will look forthe opin`torch.` using its name.
62
+
63
+
2. Implement the `sample_inputs_func`. (Ref: https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/extra_opinfo.py#L1242-L1268)
64
+
1. Copy the functionand decide what the input shapes should be. Use `make_arg` to generate a torch.Tensor. Alternatively you could also use `torch.tensor` to generate the tensor yourself. Be sure to double check the dtype and device. Finally yield each test cases with
`input` is the first arg. The rest of the args are in`args`.
71
+
3. Enable the testcasein [`ops_test_data.py`](./ops_test_data.py)
72
+
1. Add a `TorchLibOpInfo` entry to the `TESTED_TORCHLIB_OPS` list. (For example https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/ops_test_data.py#L2116)
You can additionally specify dtype tolerance (https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/ops_test_data.py#L539) or conditional skips (https://github.com/microsoft/onnxscript/blob/e67335101e4a06b8cc98cb4129935a9af5062c77/tests/function_libs/torch_lib/ops_test_data.py#L586-L590).
79
+
80
+
Now that the test is added, you may run the test like mentioned above. Set `CREATE_REPRODUCTION_REPORT=1` to get markdown reports and view failing input combinations should any testcase fails.
0 commit comments