Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions onnxruntime/python/tools/transformers/fusion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,9 @@ def to_array(tensor: TensorProto, fill_zeros: bool = False) -> ndarray:
# When weights are in external data format but not presented, we can still test the optimizer with two changes:
# (1) set fill_zeros = True (2) change load_external_data=False in optimizer.py
if fill_zeros:
from onnx import mapping

return ndarray(
shape=tensor.dims,
dtype=mapping.TENSOR_TYPE_TO_NP_TYPE[tensor.data_type],
dtype=helper.tensor_dtype_to_np_dtype(tensor.data_type),
)

return numpy_helper.to_array(tensor)
2 changes: 1 addition & 1 deletion onnxruntime/test/onnx/gen_test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def generate_size_op_test(type, X, test_folder):


def generate_reducesum_op_test(X, test_folder):
type = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[X.dtype]
type = helper.np_dtype_to_tensor_dtype(X.dtype)
data_dir = os.path.join(test_folder, "test_data_0")
os.makedirs(data_dir, exist_ok=True)
# Create one output (ValueInfoProto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def prepare_dir(path):
def _extract_value_info(arr, name, ele_type=None):
return onnx.helper.make_tensor_value_info(
name=name,
elem_type=ele_type if ele_type else onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[arr.dtype],
elem_type=ele_type if ele_type else onnx.helper.np_dtype_to_tensor_dtype(arr.dtype),
shape=arr.shape,
)

Expand Down
4 changes: 1 addition & 3 deletions onnxruntime/test/python/onnxruntime_test_python_iobinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from numpy.testing import assert_almost_equal
from onnx import TensorProto, helper
from onnx.defs import onnx_opset_version
from onnx.mapping import TENSOR_TYPE_MAP

import onnxruntime as onnxrt
from onnxruntime.capi._pybind_state import OrtDevice as C_OrtDevice # pylint: disable=E0611
Expand Down Expand Up @@ -168,8 +167,7 @@ def test_bind_onnx_types_supported_by_numpy(self):
TensorProto.UINT64,
]:
with self.subTest(onnx_dtype=onnx_dtype, inner_device=str(inner_device)):
assert onnx_dtype in TENSOR_TYPE_MAP
np_dtype = TENSOR_TYPE_MAP[onnx_dtype].np_dtype
np_dtype = helper.tensor_dtype_to_np_dtype(onnx_dtype)
x = np.arange(8).reshape((-1, 2)).astype(np_dtype)

# create onnx graph
Expand Down
6 changes: 3 additions & 3 deletions tools/python/ort_test_dir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import onnxruntime as ort


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

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

np_type = onnx.mapping.TENSOR_TYPE_TO_NP_TYPE[onnx_type]
np_type = onnx.helper.tensor_dtype_to_np_dtype(onnx_type)
data = data.astype(np_type)

name_input_map[input.name] = data
Expand Down
Loading