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

import order cause core dump #32

Closed
allenling opened this issue Nov 16, 2019 · 4 comments
Closed

import order cause core dump #32

allenling opened this issue Nov 16, 2019 · 4 comments

Comments

@allenling
Copy link

pytorch1.3.0, onnx1.6.0, onnxsim0.2.0

a simple test case



import torch
import onnx     # type: ignore
import onnxsim


def main():
    class TestNet(torch.nn.Module):
        def __init__(self):
            super(TestNet, self).__init__()
            self.conv = torch.nn.Conv1d(2, 3, kernel_size=(1,))
            return
        def forward(self, x):
            res = self.conv(x)
            return res
    net = TestNet()
    it = torch.randn(1, 2, 3)
    torch.onnx.export(net, it, "test_sim.onnx", export_params=True, verbose=True, input_names=["data"])
    model_opt = onnxsim.simplify(
        "test_sim.onnx"
        )
    print("export done")

    onnx.save(model_opt, "test_sim_simple.onnx")
    print("Ok!")


if __name__ == '__main__':
    main()

outputs

graph(%data : Float(1, 2, 3),
      %conv.weight : Float(3, 2, 1),
      %conv.bias : Float(3)):
  %3 : Float(1, 3, 3) = onnx::Conv[dilations=[1], group=1, kernel_shape=[1], pads=[0, 0], strides=[1]](%data, %conv.weight, %conv.bias), scope: TestNet/Conv1d[conv] # /usr/local/lib/python3.5/dist-packages/torch/nn/modules/conv.py:202:0
  return (%3)

Segmentation fault (core dumped)

but it works after i import torch after onnx

import torch
import onnx     # type: ignore
import onnxsim

change to

import onnx     # type: ignore
# import torch after onnx
import torch
import onnxsim
@allenling allenling changed the title core dump import order cause core dump Nov 16, 2019
@daquexian
Copy link
Owner

daquexian commented Nov 16, 2019 via email

@allenling
Copy link
Author

onnx.checker.check_model fail

def simplify(model_ori: Union[str, onnx.ModelProto], check_n: int = 0, perform_optimization: bool = True,
             input_shapes: TensorShapes = {}) \
        -> onnx.ModelProto:
    if type(model_ori) == str:
        model_ori = onnx.load(model_ori)
    # ===========>core dump here
    onnx.checker.check_model(model_ori)

guess it is a bug in torch/onnx, onnxsim is clean...

import torch
import onnx 


def main():
    class TestNet(torch.nn.Module):
        def __init__(self):
            super(TestNet, self).__init__()
            self.conv = torch.nn.Conv1d(2, 3, kernel_size=(1,))
            return
        def forward(self, x):
            res = self.conv(x)
            return res
    net = TestNet()
    it = torch.randn(1, 2, 3)
    torch.onnx.export(net, it, "test_sim.onnx", export_params=True, verbose=True, input_names=["data"])
    print("export done")
    model_ori = onnx.load("test_sim.onnx")
    onnx.checker.check_model(model_ori)
    print("Ok!")


if __name__ == '__main__':
    main()

core dump without onnxsim

@allenling
Copy link
Author

issue in onnx onnx/onnx#2431

@daquexian
Copy link
Owner

issue in onnx onnx/onnx#2431

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants