|
1 | 1 | import unittest |
2 | 2 | import numpy as np |
| 3 | +import ml_dtypes |
3 | 4 | import onnx |
4 | 5 | import torch |
5 | 6 | from onnx_diagnostic.ext_test_case import ExtTestCase |
@@ -59,7 +60,7 @@ def test_mini_onnx_builder_sequence_ort_randomize(self): |
59 | 60 | self.assertEqual((2,), got[1].shape) |
60 | 61 | self.assertEqual(np.float32, got[1].dtype) |
61 | 62 |
|
62 | | - def test_mini_onnx_builder(self): |
| 63 | + def test_mini_onnx_builder1(self): |
63 | 64 | data = [ |
64 | 65 | ( |
65 | 66 | np.array([1, 2], dtype=np.int64), |
@@ -153,6 +154,69 @@ def test_mini_onnx_builder(self): |
153 | 154 | restored = create_input_tensors_from_onnx_model(model) |
154 | 155 | self.assertEqualAny(inputs, restored) |
155 | 156 |
|
| 157 | + def test_mini_onnx_builder2(self): |
| 158 | + data = [ |
| 159 | + [], |
| 160 | + {}, |
| 161 | + tuple(), |
| 162 | + dict(one=np.array([1, 2], dtype=np.int64)), |
| 163 | + [np.array([1, 2], dtype=np.int64)], |
| 164 | + (np.array([1, 2], dtype=np.int64),), |
| 165 | + [np.array([1, 2], dtype=np.int64), 1], |
| 166 | + dict(one=np.array([1, 2], dtype=np.int64), two=1), |
| 167 | + (np.array([1, 2], dtype=np.int64), 1), |
| 168 | + ] |
| 169 | + |
| 170 | + for inputs in data: |
| 171 | + with self.subTest(types=string_type(inputs)): |
| 172 | + model = create_onnx_model_from_input_tensors(inputs) |
| 173 | + restored = create_input_tensors_from_onnx_model(model) |
| 174 | + self.assertEqualAny(inputs, restored) |
| 175 | + |
| 176 | + def test_mini_onnx_builder_type1(self): |
| 177 | + data = [ |
| 178 | + np.array([1], dtype=dtype) |
| 179 | + for dtype in [ |
| 180 | + np.float32, |
| 181 | + np.double, |
| 182 | + np.float16, |
| 183 | + np.int32, |
| 184 | + np.int64, |
| 185 | + np.int16, |
| 186 | + np.int8, |
| 187 | + np.uint8, |
| 188 | + np.uint16, |
| 189 | + np.uint32, |
| 190 | + np.uint64, |
| 191 | + np.bool_, |
| 192 | + ] |
| 193 | + ] |
| 194 | + |
| 195 | + for inputs in data: |
| 196 | + with self.subTest(types=string_type(inputs)): |
| 197 | + model = create_onnx_model_from_input_tensors(inputs) |
| 198 | + restored = create_input_tensors_from_onnx_model(model) |
| 199 | + self.assertEqualAny(inputs, restored) |
| 200 | + |
| 201 | + def test_mini_onnx_builder_type2(self): |
| 202 | + data = [ |
| 203 | + np.array([1], dtype=dtype) |
| 204 | + for dtype in [ |
| 205 | + ml_dtypes.bfloat16, |
| 206 | + ml_dtypes.float8_e4m3fn, |
| 207 | + ml_dtypes.float8_e4m3fnuz, |
| 208 | + ml_dtypes.float8_e5m2, |
| 209 | + ml_dtypes.float8_e5m2fnuz, |
| 210 | + ml_dtypes.int4, |
| 211 | + ] |
| 212 | + ] |
| 213 | + |
| 214 | + for inputs in data: |
| 215 | + with self.subTest(types=string_type(inputs)): |
| 216 | + model = create_onnx_model_from_input_tensors(inputs) |
| 217 | + restored = create_input_tensors_from_onnx_model(model) |
| 218 | + self.assertEqualAny(inputs, restored) |
| 219 | + |
156 | 220 | def test_mini_onnx_builder_transformers(self): |
157 | 221 | cache = make_dynamic_cache([(torch.ones((3, 3)), torch.ones((3, 3)) * 2)]) |
158 | 222 | dc = CacheKeyValue(cache) |
@@ -181,7 +245,7 @@ def test_mini_onnx_builder_transformers_sep(self): |
181 | 245 | restored = create_input_tensors_from_onnx_model(model, sep="#") |
182 | 246 | self.assertEqualAny(inputs, restored) |
183 | 247 |
|
184 | | - def test_specific_data(self): |
| 248 | + def test_mini_onnx_bulder_specific_data(self): |
185 | 249 | data = { |
186 | 250 | ("amain", 0, "I"): ( |
187 | 251 | ( |
@@ -221,6 +285,8 @@ def test_specific_data(self): |
221 | 285 | names, |
222 | 286 | ) |
223 | 287 | restored = create_input_tensors_from_onnx_model(model) |
| 288 | + self.assertEqual(len(data), len(restored)) |
| 289 | + self.assertEqual(list(data), list(restored)) |
224 | 290 | self.assertEqualAny(data, restored) |
225 | 291 |
|
226 | 292 |
|
|
0 commit comments