Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# pylint: disable=C0115,W0212,C0103,C0114
 
import unittest
 
import numpy as np
from helper import get_name
from numpy.testing import assert_almost_equal
from onnx import TensorProto, helper
 
import onnxruntime as onnxrt
from onnxruntime.capi._pybind_state import OrtDevice as C_OrtDevice  # pylint: disable=E0611
from onnxruntime.capi._pybind_state import OrtValue as C_OrtValue
from onnxruntime.capi._pybind_state import OrtValueVector, SessionIOBinding
 
test_params = [
    ("cuda", "CUDAExecutionProvider", C_OrtDevice.cuda),
    ("dml", "DmlExecutionProvider", C_OrtDevice.dml),
]
 
# Highest ai.onnx opset that has been *released* by the installed onnx package.
# Avoid onnx.defs.onnx_opset_version(), which returns the in-development next opset
# (ORT's loader rejects un-released opsets unless ALLOW_RELEASED_ONNX_OPSET_ONLY=0).
_LAST_RELEASED_AI_ONNX_OPSET = max(v for (d, v) in helper.OP_SET_ID_VERSION_MAP if d == "ai.onnx")
 
 
class TestIOBinding(unittest.TestCase):
    def test_cuda_rms_norm_fp16_offset_buffers(self):
        """RMSNorm must accept FP16 CUDA buffers offset by one element without corrupting their padding."""
        if "CUDAExecutionProvider" not in onnxrt.get_available_providers():
            self.skipTest("CUDAExecutionProvider unavailable")
 
        epsilon = 1e-5
        options = onnxrt.SessionOptions()
        options.graph_optimization_level = onnxrt.GraphOptimizationLevel.ORT_DISABLE_ALL
        options.add_session_config_entry("session.disable_cpu_ep_fallback", "1")
        for width in (32, 512):
            shape = [2, width]
            inputs = [
                helper.make_tensor_value_info("X", TensorProto.FLOAT16, shape),
                helper.make_tensor_value_info("scale", TensorProto.FLOAT16, [width]),
            ]
            outputs = [helper.make_tensor_value_info("Y", TensorProto.FLOAT16, shape)]
            node = helper.make_node("RMSNormalization", ["X", "scale"], ["Y"], axis=-1, epsilon=epsilon)
            model = helper.make_model(
                helper.make_graph([node], "rms-norm-offset-buffers", inputs, outputs),
                opset_imports=[helper.make_opsetid("", 23)],
                ir_version=10,
            )
            session = onnxrt.InferenceSession(model.SerializeToString(), options, providers=["CUDAExecutionProvider"])
            values = np.linspace(-2, 2, 2 * width).astype(np.float16).reshape(shape)
            scale = np.linspace(0.5, 1.5, width).astype(np.float16)
            reference = values.astype(np.float64)
            reference = reference * scale / np.sqrt(np.mean(reference**2, axis=-1, keepdims=True) + epsilon)
            for offsets in ((0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 1)):
                with self.subTest(width=width, offsets=offsets):
                    buffers = []
                    binding = session.io_binding()
                    for name, data, offset in zip(("X", "scale", "Y"), (values, scale, values), offsets, strict=True):
                        padded = np.full(data.size + 2, 123, dtype=np.float16)
                        if name != "Y":
                            padded[offset : offset + data.size] = data.ravel()
                        buffer = onnxrt.OrtValue.ortvalue_from_numpy(padded, "cuda", 0)
                        buffers.append(buffer)
                        pointer = buffer.data_ptr() + offset * padded.itemsize
                        self.assertEqual(pointer % 4, offset * padded.itemsize)
                        bind = binding.bind_output if name == "Y" else binding.bind_input
                        bind(name, "cuda", 0, np.float16, data.shape, pointer)
                    session.run_with_iobinding(binding)
                    binding.synchronize_outputs()
                    output = buffers[2].numpy()
                    start = offsets[2]
                    actual = output[start : start + values.size].reshape(shape)
                    np.testing.assert_allclose(actual, reference, rtol=1e-3, atol=1e-3)
                    np.testing.assert_array_equal(output[:start], np.float16(123))
                    np.testing.assert_array_equal(output[start + values.size :], np.float16(123))
                    for buffer, data, offset in zip(buffers[:2], (values, scale), offsets[:2], strict=True):
                        np.testing.assert_array_equal(buffer.numpy()[offset : offset + data.size], data.ravel())
 
    def _create_ortvalue_input_on_gpu(self, device):
        return onnxrt.OrtValue.ortvalue_from_numpy(
            np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32), device, 0
        )
 
    def _create_ortvalue_alternate_input_on_gpu(self, device):
        return onnxrt.OrtValue.ortvalue_from_numpy(
            np.array([[2.0, 4.0], [6.0, 8.0], [10.0, 12.0]], dtype=np.float32),
            device,
            0,
        )
 
    def _create_uninitialized_ortvalue_input_on_gpu(self, device):
        return onnxrt.OrtValue.ortvalue_from_shape_and_type([3, 2], np.float32, device, 0)
 
    def _create_numpy_input(self):
        return np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32)
 
    def _create_expected_output(self):
        return np.array([[1.0, 4.0], [9.0, 16.0], [25.0, 36.0]], dtype=np.float32)
 
    def _create_expected_output_alternate(self):
        return np.array([[2.0, 8.0], [18.0, 32.0], [50.0, 72.0]], dtype=np.float32)
 
    def test_bind_input_to_cpu_arr(self):
        session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
        io_binding = session.io_binding()
 
        # Bind Numpy object (input) that's on CPU to wherever the model needs it
        io_binding.bind_cpu_input("X", self._create_numpy_input())
 
        # Bind output to CPU
        io_binding.bind_output("Y")
 
        # Invoke Run
        session.run_with_iobinding(io_binding)
 
        # Sync if different streams
        io_binding.synchronize_outputs()
 
        # Get outputs over to CPU (the outputs which were bound to the GPU will get copied over to the host here)
        ort_output = io_binding.copy_outputs_to_cpu()[0]
 
        # Validate results
        self.assertTrue(np.array_equal(self._create_expected_output(), ort_output))
 
    def test_bind_input_types(self):
        for device, execution_provider, generate_device in test_params:
            with self.subTest(execution_provider):
                if execution_provider not in onnxrt.get_available_providers():
                    self.skipTest(f"Skipping on {device.upper()}.")
 
                opset = _LAST_RELEASED_AI_ONNX_OPSET
                devices = [
                    (
                        C_OrtDevice(C_OrtDevice.cpu(), C_OrtDevice.default_memory(), 0),
                        ["CPUExecutionProvider"],
                    ),
                    (
                        C_OrtDevice(generate_device(), C_OrtDevice.default_memory(), 0),
                        [execution_provider],
                    ),
                ]
 
                for inner_device, provider in devices:
                    for dtype in [
                        np.float32,
                        np.float64,
                        np.int32,
                        np.uint32,
                        np.int64,
                        np.uint64,
                        np.int16,
                        np.uint16,
                        np.int8,
                        np.uint8,
                        np.float16,
                        np.bool_,
                    ]:
                        with self.subTest(dtype=dtype, inner_device=str(inner_device)):
                            x = np.arange(8).reshape((-1, 2)).astype(dtype)
                            proto_dtype = helper.np_dtype_to_tensor_dtype(x.dtype)
 
                            X = helper.make_tensor_value_info("X", proto_dtype, [None, x.shape[1]])  # noqa: N806
                            Y = helper.make_tensor_value_info("Y", proto_dtype, [None, x.shape[1]])  # noqa: N806
 
                            # inference
                            node_add = helper.make_node("Identity", ["X"], ["Y"])
 
                            # graph
                            graph_def = helper.make_graph([node_add], "lr", [X], [Y], [])
                            model_def = helper.make_model(
                                graph_def,
                                producer_name="dummy",
                                ir_version=7,
                                producer_version="0",
                                opset_imports=[helper.make_operatorsetid("", opset)],
                            )
 
                            sess = onnxrt.InferenceSession(model_def.SerializeToString(), providers=provider)
 
                            bind = SessionIOBinding(sess._sess)
                            ort_value = C_OrtValue.ortvalue_from_numpy(x, inner_device)
                            bind.bind_ortvalue_input("X", ort_value)
                            bind.bind_output("Y", inner_device)
                            sess._sess.run_with_iobinding(bind, None)
                            ortvaluevector = bind.get_outputs()
                            self.assertIsInstance(ortvaluevector, OrtValueVector)
                            ortvalue = bind.get_outputs()[0]
                            y = ortvalue.numpy()
                            assert_almost_equal(x, y)
 
                            bind = SessionIOBinding(sess._sess)
                            bind.bind_input("X", inner_device, dtype, x.shape, ort_value.data_ptr())
                            bind.bind_output("Y", inner_device)
                            sess._sess.run_with_iobinding(bind, None)
                            ortvalue = bind.get_outputs()[0]
                            y = ortvalue.numpy()
                            assert_almost_equal(x, y)
 
    def test_bind_onnx_types_supported_by_numpy(self):
        opset = _LAST_RELEASED_AI_ONNX_OPSET
        devices = [
            (
                C_OrtDevice(C_OrtDevice.cpu(), C_OrtDevice.default_memory(), 0),
                ["CPUExecutionProvider"],
            ),
        ]
 
        for inner_device, provider in devices:
            for onnx_dtype in [
                TensorProto.FLOAT,
                TensorProto.UINT8,
                TensorProto.INT8,
                TensorProto.UINT16,
                TensorProto.INT16,
                TensorProto.INT32,
                TensorProto.INT64,
                TensorProto.BOOL,
                TensorProto.FLOAT16,
                TensorProto.DOUBLE,
                TensorProto.UINT32,
                TensorProto.UINT64,
            ]:
                with self.subTest(onnx_dtype=onnx_dtype, inner_device=str(inner_device)):
                    np_dtype = helper.tensor_dtype_to_np_dtype(onnx_dtype)
                    x = np.arange(8).reshape((-1, 2)).astype(np_dtype)
 
                    # create onnx graph
                    X = helper.make_tensor_value_info("X", onnx_dtype, [None, x.shape[1]])  # noqa: N806
                    Y = helper.make_tensor_value_info("Y", onnx_dtype, [None, x.shape[1]])  # noqa: N806
                    node_add = helper.make_node("Identity", ["X"], ["Y"])
                    graph_def = helper.make_graph([node_add], "lr", [X], [Y], [])
                    model_def = helper.make_model(
                        graph_def,
                        producer_name="dummy",
                        ir_version=7,
                        producer_version="0",
                        opset_imports=[helper.make_operatorsetid("", opset)],
                    )
 
                    ort_value_x = C_OrtValue.ortvalue_from_numpy(x, inner_device)
                    ort_value_y = onnxrt.OrtValue.ortvalue_from_shape_and_type(x.shape, onnx_dtype)
 
                    sess = onnxrt.InferenceSession(model_def.SerializeToString(), providers=provider)
                    bind = SessionIOBinding(sess._sess)
                    bind.bind_input("X", inner_device, onnx_dtype, x.shape, ort_value_x.data_ptr())
                    bind.bind_output("Y", inner_device, onnx_dtype, x.shape, ort_value_y.data_ptr())
                    sess._sess.run_with_iobinding(bind, None)
                    assert_almost_equal(x, ort_value_y.numpy())
 
    # Test I/O binding with onnx types like bfloat16 and float8, which are not supported in numpy.
    def test_bind_onnx_types_not_supported_by_numpy(self):
        try:
            import torch  # noqa: PLC0415
        except ImportError:
            self.skipTest("Skipping since PyTorch is not installed.")
 
        opset = _LAST_RELEASED_AI_ONNX_OPSET
        devices = [
            (
                C_OrtDevice(C_OrtDevice.cpu(), C_OrtDevice.default_memory(), 0),
                ["CPUExecutionProvider"],
            ),
        ]
 
        onnx_to_torch_type_map = {TensorProto.BFLOAT16: torch.bfloat16}
        # Float8 support requires torch >= 2.1.0
        if hasattr(torch, "float8_e4m3fn") and hasattr(torch, "float8_e5m2"):
            onnx_to_torch_type_map.update(
                {
                    TensorProto.FLOAT8E4M3FN: torch.float8_e4m3fn,
                    TensorProto.FLOAT8E5M2: torch.float8_e5m2,
                }
            )
 
        for inner_device, provider in devices:
            for onnx_dtype, torch_dtype in onnx_to_torch_type_map.items():
                with self.subTest(onnx_dtype=onnx_dtype, inner_device=str(inner_device)):
                    # Create onnx graph with dynamic axes
                    X = helper.make_tensor_value_info("X", onnx_dtype, [None])  # noqa: N806
                    Y = helper.make_tensor_value_info("Y", onnx_dtype, [None])  # noqa: N806
                    node_add = helper.make_node("Identity", ["X"], ["Y"])
                    graph_def = helper.make_graph([node_add], "lr", [X], [Y], [])
                    model_def = helper.make_model(
                        graph_def,
                        producer_name="dummy",
                        ir_version=10,
                        producer_version="0",
                        opset_imports=[helper.make_operatorsetid("", opset)],
                    )
 
                    sess = onnxrt.InferenceSession(model_def.SerializeToString(), providers=provider)
 
                    x = torch.arange(8).to(torch_dtype)
                    y = torch.empty(8, dtype=torch_dtype)
 
                    bind = sess.io_binding()
                    bind.bind_input("X", x.device.type, 0, onnx_dtype, x.shape, x.data_ptr())
                    bind.bind_output("Y", y.device.type, 0, onnx_dtype, y.shape, y.data_ptr())
                    sess.run_with_iobinding(bind)
                    if onnx_dtype != TensorProto.BFLOAT16:
                        # torch has no cpu equal implementation of float8, so we compare them after casting to float.
                        self.assertTrue(torch.equal(x.to(torch.float), y.to(torch.float)))
                    else:
                        self.assertTrue(torch.equal(x, y))
 
    def test_bind_input_only(self):
        for device, execution_provider, _ in test_params:
            with self.subTest(execution_provider):
                if execution_provider not in onnxrt.get_available_providers():
                    self.skipTest(f"Skipping on {device.upper()}.")
                input = self._create_ortvalue_input_on_gpu(device)
 
                session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
                io_binding = session.io_binding()
 
                # Bind input to the GPU
                io_binding.bind_input("X", device, 0, np.float32, [3, 2], input.data_ptr())
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Bind output to CPU
                io_binding.bind_output("Y")
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # Get outputs over to CPU (the outputs which were bound to the GPU will get copied over to the host
                # here)
                ort_output = io_binding.copy_outputs_to_cpu()[0]
 
                # Validate results
                self.assertTrue(np.array_equal(self._create_expected_output(), ort_output))
 
    def test_bind_input_and_preallocated_output(self):
        for device, execution_provider, _ in test_params:
            with self.subTest(execution_provider):
                if execution_provider not in onnxrt.get_available_providers():
                    self.skipTest(f"Skipping on {device.upper()}.")
 
                input = self._create_ortvalue_input_on_gpu(device)
 
                session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
                io_binding = session.io_binding()
 
                # Bind input to the GPU
                io_binding.bind_input("X", device, 0, np.float32, [3, 2], input.data_ptr())
 
                # Bind output to the GPU
                output = self._create_uninitialized_ortvalue_input_on_gpu(device)
                io_binding.bind_output("Y", device, 0, np.float32, [3, 2], output.data_ptr())
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # Get outputs over to CPU (the outputs which were bound to the GPU will get copied over to the host
                # here)
                ort_output_vals = io_binding.copy_outputs_to_cpu()[0]
                # Validate results
                self.assertTrue(np.array_equal(self._create_expected_output(), ort_output_vals))
 
                # Validate if ORT actually wrote to pre-allocated buffer by copying the allocated buffer
                # to the host and validating its contents
                ort_output_vals_in_cpu = output.numpy()
                # Validate results
                self.assertTrue(np.array_equal(self._create_expected_output(), ort_output_vals_in_cpu))
 
    def test_bind_input_and_non_preallocated_output(self):
        for device, execution_provider, _ in test_params:
            with self.subTest(execution_provider):
                if execution_provider not in onnxrt.get_available_providers():
                    self.skipTest(f"Skipping on {device.upper()}.")
 
                session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
                io_binding = session.io_binding()
 
                input = self._create_ortvalue_input_on_gpu(device)
 
                # Bind input to the GPU
                io_binding.bind_input(
                    "X",
                    device,
                    0,
                    np.float32,
                    [3, 2],
                    input.data_ptr(),
                )
 
                # Bind output to the GPU
                io_binding.bind_output("Y", device)
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # This call returns an OrtValue which has data allocated by ORT on the GPU
                ort_outputs = io_binding.get_outputs()
                self.assertEqual(len(ort_outputs), 1)
                self.assertEqual(ort_outputs[0].device_name(), device)
                # Validate results (by copying results to CPU by creating a Numpy object)
                self.assertTrue(np.array_equal(self._create_expected_output(), ort_outputs[0].numpy()))
 
                # We should be able to repeat the above process as many times as we want - try once more
                ort_outputs = io_binding.get_outputs()
                self.assertEqual(len(ort_outputs), 1)
                self.assertEqual(ort_outputs[0].device_name(), device)
                # Validate results (by copying results to CPU by creating a Numpy object)
                self.assertTrue(np.array_equal(self._create_expected_output(), ort_outputs[0].numpy()))
 
                input = self._create_ortvalue_alternate_input_on_gpu(device)
 
                # Change the bound input and validate the results in the same bound OrtValue
                # Bind alternate input to the GPU
                io_binding.bind_input(
                    "X",
                    device,
                    0,
                    np.float32,
                    [3, 2],
                    input.data_ptr(),
                )
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # This call returns an OrtValue which has data allocated by ORT on the GPU
                ort_outputs = io_binding.get_outputs()
                self.assertEqual(len(ort_outputs), 1)
                self.assertEqual(ort_outputs[0].device_name(), device)
                # Validate results (by copying results to CPU by creating a Numpy object)
                self.assertTrue(np.array_equal(self._create_expected_output_alternate(), ort_outputs[0].numpy()))
 
    def test_bind_input_and_bind_output_with_ortvalues(self):
        for device, execution_provider, _ in test_params:
            with self.subTest(execution_provider):
                if execution_provider not in onnxrt.get_available_providers():
                    self.skipTest(f"Skipping on {device.upper()}.")
 
                session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
                io_binding = session.io_binding()
 
                # Bind ortvalue as input
                input_ortvalue = self._create_ortvalue_input_on_gpu(device)
                io_binding.bind_ortvalue_input("X", input_ortvalue)
 
                # Bind ortvalue as output
                output_ortvalue = self._create_uninitialized_ortvalue_input_on_gpu(device)
                io_binding.bind_ortvalue_output("Y", output_ortvalue)
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # Inspect contents of output_ortvalue and make sure that it has the right contents
                self.assertTrue(np.array_equal(self._create_expected_output(), output_ortvalue.numpy()))
 
                # Bind another ortvalue as input
                input_ortvalue_2 = self._create_ortvalue_alternate_input_on_gpu(device)
                io_binding.bind_ortvalue_input("X", input_ortvalue_2)
 
                # Sync if different streams
                io_binding.synchronize_inputs()
 
                # Invoke Run
                session.run_with_iobinding(io_binding)
 
                # Sync if different streams
                io_binding.synchronize_outputs()
 
                # Inspect contents of output_ortvalue and make sure that it has the right contents
                self.assertTrue(np.array_equal(self._create_expected_output_alternate(), output_ortvalue.numpy()))
 
    def test_bind_input_rejects_string_tensor(self):
        # Binding a string tensor via a raw, non-owning pointer is unsafe: the backing buffer
        # has no live std::string objects, which previously caused out-of-bounds writes when
        # the tensor was later read or destroyed. Both overloads of bind_input (ONNX int
        # element_type and numpy dtype) must reject string tensors explicitly.
        session = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=onnxrt.get_available_providers())
        io_binding = session.io_binding()
 
        # Use a real allocation just to have a valid pointer; the type check happens before
        # the pointer is dereferenced.
        scratch = np.zeros(4, dtype=np.uint8)
        scratch_ptr = scratch.ctypes.data
 
        # Overload 1: int32 ONNX element type.
        with self.assertRaisesRegex(RuntimeError, "Only binding non-string Tensors"):
            io_binding.bind_input("X", "cpu", 0, int(TensorProto.STRING), [1], scratch_ptr)
 
        # Overload 2: numpy dtype. NPY_UNICODE, NPY_STRING and NPY_OBJECT all map to
        # std::string in NumpyTypeToOnnxRuntimeTensorType, so each of them must be rejected.
        for dtype in (np.dtype("U1"), np.dtype("S1"), np.dtype(object)):
            with (
                self.subTest(dtype=dtype),
                self.assertRaisesRegex(RuntimeError, "Only binding non-string Tensors"),
            ):
                io_binding.bind_input("X", "cpu", 0, dtype, [1], scratch_ptr)
 
 
if __name__ == "__main__":
    unittest.main()