spcl / pymlir

Python interface for MLIR - the Multi-Level Intermediate Representation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parse error in onnx mlir

vasanthaganeshk opened this issue · comments

Model:

module  {
  func @main_graph(%arg0: tensor<?x1x5x5xf32>) -> tensor<?x1x3x3xf32> attributes {input_names = ["conv2d_input"], output_names = ["conv2d"]} {
    %cst = constant unit
    %0 = "onnx.Constant"() {value = dense<[[[[-0.184168547, 0.380746067, -0.299985915], [0.182676792, 0.086410582, 0.571638823], [-0.120835036, 0.374882519, 0.118288457]]]]> : tensor<1x1x3x3xf32>} : () -> tensor<1x1x3x3xf32>
    %1 = "onnx.Conv"(%arg0, %0, %cst) {auto_pad = "NOTSET", dilations = [1, 1], group = 1 : si64, kernel_shape = [3, 3], onnx_node_name = "StatefulPartitionedCall/sequential/conv2d/Conv2D", pads = [0, 0, 0, 0], strides = [1, 1]} : (tensor<?x1x5x5xf32>, tensor<1x1x3x3xf32>, none) -> tensor<?x1x3x3xf32>
    return %1 : tensor<?x1x3x3xf32>
  }
  "onnx.EntryPoint"() {func = @main_graph, numInputs = 1 : i32, numOutputs = 1 : i32, signature = "[    { \22type\22 : \22float\22 , \22dims\22 : [-1 , 1 , 5 , 5]  }\0A\0A]\00@[   { \22type\22 : \22float\22 , \22dims\22 : [-1 , 1 , 3 , 3]  }\0A\0A]\00"} : () -> ()
}

Traceback:

Traceback (most recent call last):
  File "gpxResultValidator.py", line 1426, in <module>
    format_output_and_print(*main(model_mlir, input_path), wtm_width)
  File "gpxResultValidator.py", line 1310, in main
    m = mlir.parse_path(model_mlir)
  File "/home/vasantha/.local/lib/python3.8/site-packages/mlir/parser.py", line 159, in parse_path
    return parse_file(fp, dialects)
  File "/home/vasantha/.local/lib/python3.8/site-packages/mlir/parser.py", line 146, in parse_file
    return parse_string(file.read(), dialects)
  File "/home/vasantha/.local/lib/python3.8/site-packages/mlir/parser.py", line 133, in parse_string
    return parser.parse(code)
  File "/home/vasantha/.local/lib/python3.8/site-packages/mlir/parser.py", line 93, in parse
    tree = self.parser.parse(code)
  File "/home/vasantha/.local/lib/python3.8/site-packages/lark/lark.py", line 581, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "/home/vasantha/.local/lib/python3.8/site-packages/lark/parser_frontends.py", line 106, in parse
    return self.parser.parse(stream, chosen_start, **kw)
  File "/home/vasantha/.local/lib/python3.8/site-packages/lark/parsers/earley.py", line 297, in parse
    to_scan = self._parse(lexer, columns, to_scan, start_symbol)
  File "/home/vasantha/.local/lib/python3.8/site-packages/lark/parsers/xearley.py", line 144, in _parse
    to_scan = scan(i, to_scan)
  File "/home/vasantha/.local/lib/python3.8/site-packages/lark/parsers/xearley.py", line 118, in scan
    raise UnexpectedCharacters(stream, i, text_line, text_column, {item.expect.name for item in to_scan},
lark.exceptions.UnexpectedCharacters: No terminal matches '%' in the current parser context, at line 4 col 5

    %0 = "onnx.Constant"() {value = dense<[[
    ^
Expected one of: 
	* __ANON_4
	* __ANON_0
	* DOT
	* __ANON_7
	* __ANON_8

Hi, I'm trying to parse the mlir file mentioned above, I think the line %cst = constant unit is not getting parsed properly. I don't think this is an issue with the mlir file's syntax as I was able to compile the mlir file with onnx-mlir. I saw in issue #19 that we can bypass this by adding a new dialect. Can you give some pointers on how to fix this in either pymlir or how to create a dialect for this?

Thank you,
Vasanth.

I was able to use the tutorial mentioned in the docs and create a new dialect. Thanks.