The Wayback Machine - https://web.archive.org/web/20201129080822/https://github.com/onnx/onnx/issues/2992
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

ONNX helper tests fail on big endian #2992

Open
JonTriebenbach opened this issue Sep 2, 2020 · 1 comment
Open

ONNX helper tests fail on big endian #2992

JonTriebenbach opened this issue Sep 2, 2020 · 1 comment

Comments

@JonTriebenbach
Copy link

@JonTriebenbach JonTriebenbach commented Sep 2, 2020

Bug Report

These tests were run on s390x. s390x is big-endian architecture.

Failure log for helper_test.py

________________________________________________ TestHelperTensorFunctions.test_make_tensor ________________________________________________

self = <helper_test.TestHelperTensorFunctions testMethod=test_make_tensor>

    def test_make_tensor(self):  # type: () -> None
        np_array = np.random.randn(2, 3).astype(np.float32)
    
        tensor = helper.make_tensor(
            name='test',
            data_type=TensorProto.FLOAT,
            dims=(2, 3),
            vals=np_array.reshape(6).tolist()
        )
        self.assertEqual(tensor.name, 'test')
        np.testing.assert_equal(np_array, numpy_helper.to_array(tensor))
    
        # use raw_data field to store the data
        tensor = helper.make_tensor(
            name='test',
            data_type=TensorProto.FLOAT,
            dims=(2, 3),
            vals=np_array.reshape(6).tobytes(),
            raw=True,
        )
>       np.testing.assert_equal(np_array, numpy_helper.to_array(tensor))
E       AssertionError: 
E       Arrays are not equal
E       
E       Mismatched elements: 6 / 6 (100%)
E       Max absolute difference: 1.5065837e+35
E       Max relative difference: 4.5463473e+17
E        x: array([[-0.529978,  0.220067,  2.51422 ],
E              [ 0.053094,  0.312179, -0.14148 ]], dtype=float32)
E        y: array([[-1.165722e-18,  4.713674e-17, -1.506584e+35],
E              [ 3.989577e+03, -3.152505e+22,  4.173543e-07]], dtype=float32)

helper_test.py:297: AssertionError

The helper_test.py code needs to account for generating the raw data on a big endian architecture while the ONNX internals always expects little endian values.

Attached is the patch file for fixing the issue in the testcase helper_test.py code.

onnx-helper-test.patch.zip

A pull request can be submitted if needed.

@JonTriebenbach JonTriebenbach added the bug label Sep 2, 2020
@faxu
Copy link

@faxu faxu commented Sep 3, 2020

Please feel free to submit the PR for the community to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.