onnx / onnx/optimizer

Multiple ONNX optimizer tests fail on big-endian

Open
#8 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
834
Forks
109
Avg merge
6h 55m
Merged PRs (30d)
2

Description

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

Example failure log from pytest:

_________________________________________________ TestOptimizer.test_fuse_pad_into_conv_1d _________________________________________________

self = <optimizer_test.TestOptimizer testMethod=test_fuse_pad_into_conv_1d>

    def test_fuse_pad_into_conv_1d(self):  # type: () -> None
        pad = helper.make_node(
            "Pad",
            ["X", "Pads"],
            ["P"],
            mode="constant"
        )
        conv = helper.make_node("Conv", ["P", "Y"], ["Z"])
        graph = helper.make_graph(
            [pad, conv],
            "test",
            [helper.make_tensor_value_info("X", TensorProto.FLOAT, (1, 5, 30)),
             helper.make_tensor_value_info("Pads", TensorProto.INT64, (6,)),
             helper.make_tensor_value_info("Y", TensorProto.FLOAT, (16, 5, 32))],
            [helper.make_tensor_value_info("Z", TensorProto.FLOAT, (1, 16, 1))],
            [helper.make_tensor("Pads", TensorProto.INT64,
             dims=(6,),
             vals=np.array([0, 0, 1, 0, 0, 1]).astype(np.int64).tobytes(),
             raw=True)])
        optimized_model = self._optimized(graph, ["fuse_pad_into_conv"])
    
        assert len(list(optimized_model.graph.node)) == 1
        assert optimized_model.graph.node[0].op_type == "Conv"
        assert optimized_model.graph.node[0].attribute[0].name == "pads"
>       assert list(optimized_model.graph.node[0].attribute[0].ints) == [1, 1]
E       AssertionError: assert [720575940379...7594037927936] == [1, 1]
E         At index 0 diff: 72057594037927936 != 1
E         Use -v to get the full diff

optimizer_test.py:1038: AssertionError

Notice the big integers: 720575940379. Viewing the number in hex shows an endian swapping issue.

Attached is the patch file for fixing the issue in the testcase helper.py code. The helper.py code needs to account for generating the raw data on a big endian architecture while the ONNX internals always expects little endian values.

A pull request can be submitted if needed.

Attaching corrected patch below.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in helper.py, then run the failing pytest case in optimizer_test.py around line 1038 on a big-endian environment or inspect the attached failure log. Verify that generated raw tensor data is interpreted consistently with ONNX's little-endian expectations and that the optimizer tests produce the expected pad values.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.