Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes s390x byteswapping issues #6183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

tehbone
Copy link
Contributor

@tehbone tehbone commented Jun 15, 2024

Description

Updates the mapping of the datatypes to also indicate the element size when stored as a raw tensor. This is separate from the storage dtype, which appears to correspond to the type used when the data is an attribute.

This also updates the testcases which use make_tensor with raw=True to perform byteswapping on big endian systems if the datatype is at least 2 bytes.

Motivation and Context

This fixes the failures identified in issue #6181 as well as a handful of other related s390x specific failures not otherwise identified in the issue. This will be one step closer to a clean testsuite on s390x.

@tehbone tehbone requested a review from a team as a code owner June 15, 2024 00:00
Copy link

codecov bot commented Jun 15, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 57.04%. Comparing base (83194ed) to head (d027563).
Report is 47 commits behind head on main.

Files Patch % Lines
onnx/numpy_helper.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6183      +/-   ##
==========================================
+ Coverage   56.95%   57.04%   +0.08%     
==========================================
  Files         506      506              
  Lines       30467    30965     +498     
  Branches     4592     4599       +7     
==========================================
+ Hits        17353    17663     +310     
- Misses      12285    12477     +192     
+ Partials      829      825       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# Raw_bytes support: using frombuffer.
raw_data = tensor.raw_data
if sys.byteorder == "big":
# Convert endian from little to big
raw_data = np.frombuffer(raw_data, dtype=np_dtype).byteswap().tobytes()
raw_data = np.frombuffer(raw_data, dtype=storage_np_dtype).byteswap().tobytes()

Check failure

Code scanning / lintrunner

MYPY/call-overload Error

No overload variant of "frombuffer" matches argument types "bytes", "int" To disable, use # type: ignore[call-overload]
@@ -288,6 +287,10 @@

return np.frombuffer(raw_data, dtype=np_dtype).reshape(dims) # type: ignore[no-any-return]

# dtype for raw data is determined by the storage_dtype
storage_np_dtype = helper.tensor_dtype_to_np_dtype(

Check failure

Code scanning / lintrunner

MYPY/assignment Error

Incompatible types in assignment (expression has type "dtype[Any]", variable has type "int") To disable, use # type: ignore[assignment]
@@ -1563,6 +1563,16 @@
"""
return mapping.TENSOR_TYPE_MAP[tensor_dtype].storage_dtype

def tensor_dtype_to_storage_np_dtype(tensor_dtype: int) -> int:
"""Convert a TensorProto's data_type to corresponding data_type for raw storage.

Check warning

Code scanning / lintrunner

RUFF/W293 Warning


Args:
tensor_dtype: TensorProto's data_type

Check warning

Code scanning / lintrunner

RUFF/W293 Warning

@@ -1563,6 +1563,16 @@
"""
return mapping.TENSOR_TYPE_MAP[tensor_dtype].storage_dtype

def tensor_dtype_to_storage_np_dtype(tensor_dtype: int) -> int:
"""Convert a TensorProto's data_type to corresponding data_type for raw storage.

Check warning

Code scanning / lintrunner

EDITORCONFIG-CHECKER/editorconfig Warning

Trailing whitespace

Args:
tensor_dtype: TensorProto's data_type

Check warning

Code scanning / lintrunner

EDITORCONFIG-CHECKER/editorconfig Warning

Trailing whitespace
Returns:
numpy's data_type for the raw storage
"""
return mapping.TENSOR_TYPE_MAP[tensor_dtype].storage_np_dtype

Check failure

Code scanning / lintrunner

MYPY/return-value Error

Incompatible return value type (got "dtype[Any]", expected "int") To disable, use # type: ignore[return-value]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

None yet

1 participant