Skip to content

Commit fb37338

Browse files
justinchubyvraspar
authored andcommitted
Remove deprecated onnx.mapping usage (#24484)
`onnx.mapping` was deprecated and is being removed. This PR updates removes deprecated usage. @MaanavD would be good if this can make it into 1.22.0 for forward ONNX release (1.19+) compatibility.
1 parent 9df2495 commit fb37338

File tree

5 files changed

+7
-11
lines changed

5 files changed

+7
-11
lines changed

onnxruntime/python/tools/transformers/fusion_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,9 @@ def to_array(tensor: TensorProto, fill_zeros: bool = False) -> ndarray:
309309
# When weights are in external data format but not presented, we can still test the optimizer with two changes:
310310
# (1) set fill_zeros = True (2) change load_external_data=False in optimizer.py
311311
if fill_zeros:
312-
from onnx import mapping
313-
314312
return ndarray(
315313
shape=tensor.dims,
316-
dtype=mapping.TENSOR_TYPE_TO_NP_TYPE[tensor.data_type],
314+
dtype=helper.tensor_dtype_to_np_dtype(tensor.data_type),
317315
)
318316

319317
return numpy_helper.to_array(tensor)

onnxruntime/test/onnx/gen_test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def generate_size_op_test(type, X, test_folder):
9494

9595

9696
def generate_reducesum_op_test(X, test_folder):
97-
type = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[X.dtype]
97+
type = helper.np_dtype_to_tensor_dtype(X.dtype)
9898
data_dir = os.path.join(test_folder, "test_data_0")
9999
os.makedirs(data_dir, exist_ok=True)
100100
# Create one output (ValueInfoProto)

onnxruntime/test/python/contrib_ops/onnx_contrib_ops_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def prepare_dir(path):
2323
def _extract_value_info(arr, name, ele_type=None):
2424
return onnx.helper.make_tensor_value_info(
2525
name=name,
26-
elem_type=ele_type if ele_type else onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[arr.dtype],
26+
elem_type=ele_type if ele_type else onnx.helper.np_dtype_to_tensor_dtype(arr.dtype),
2727
shape=arr.shape,
2828
)
2929

onnxruntime/test/python/onnxruntime_test_python_iobinding.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from numpy.testing import assert_almost_equal
1010
from onnx import TensorProto, helper
1111
from onnx.defs import onnx_opset_version
12-
from onnx.mapping import TENSOR_TYPE_MAP
1312

1413
import onnxruntime as onnxrt
1514
from onnxruntime.capi._pybind_state import OrtDevice as C_OrtDevice # pylint: disable=E0611
@@ -168,8 +167,7 @@ def test_bind_onnx_types_supported_by_numpy(self):
168167
TensorProto.UINT64,
169168
]:
170169
with self.subTest(onnx_dtype=onnx_dtype, inner_device=str(inner_device)):
171-
assert onnx_dtype in TENSOR_TYPE_MAP
172-
np_dtype = TENSOR_TYPE_MAP[onnx_dtype].np_dtype
170+
np_dtype = helper.tensor_dtype_to_np_dtype(onnx_dtype)
173171
x = np.arange(8).reshape((-1, 2)).astype(np_dtype)
174172

175173
# create onnx graph

tools/python/ort_test_dir_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import onnxruntime as ort
1111

1212

13-
def _get_numpy_type(model_info, name):
13+
def _get_numpy_type(model_info, name) -> np.dtype:
1414
for i in model_info:
1515
if i.name == name:
1616
type_name = i.type.WhichOneof("value")
1717
if type_name == "tensor_type":
18-
return onnx.mapping.TENSOR_TYPE_TO_NP_TYPE[i.type.tensor_type.elem_type]
18+
return onnx.helper.tensor_dtype_to_np_dtype(i.type.tensor_type.elem_type)
1919
else:
2020
raise ValueError(f"Type is not handled: {type_name}")
2121

@@ -65,7 +65,7 @@ def _create_missing_input_data(model_inputs, name_input_map, symbolic_dim_values
6565
if onnx_type not in [TensorProto.FLOAT, TensorProto.BFLOAT16, TensorProto.DOUBLE, TensorProto.FLOAT16]:
6666
data *= 256
6767

68-
np_type = onnx.mapping.TENSOR_TYPE_TO_NP_TYPE[onnx_type]
68+
np_type = onnx.helper.tensor_dtype_to_np_dtype(onnx_type)
6969
data = data.astype(np_type)
7070

7171
name_input_map[input.name] = data

0 commit comments

Comments
 (0)