[relay] mxnet ssd resnet50 compilation fails for device=arm_cpu

code

import os
import zipfile
import tvm
import nnvm
import mxnet as mx
import numpy as np

from nnvm import compiler
from nnvm.frontend import from_mxnet
from tvm import relay
from tvm.contrib.download import download
from mxnet.model import load_checkpoint


dshape = (1, 3, 512, 512)
dtype = "float32"

# Target settings
target = 'llvm -device=arm_cpu -target=armv7l-linux-gnueabihf '

target_host = None

print(target)

inf_json = "deploy_ssd_resnet50_512/deploy_ssd_resnet50_512-symbol.json"
print("mx.sym.load: " + inf_json)
sym = mx.sym.load(inf_json)

checkp = "deploy_ssd_resnet50_512/deploy_ssd_resnet50_512"

print("load_checkpoint: " + checkp)
_, arg_params, aux_params = load_checkpoint(checkp, 0)

import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
    "-f", "--frontend",
    help="Frontend for compilation, nnvm or relay",
    type=str,
    default="nnvm")
args = parser.parse_args()
if args.frontend == "relay":
    net, params = relay.frontend.from_mxnet(sym, {"data": dshape}, arg_params=arg_params, \
                                            aux_params=aux_params)
    with relay.build_config(opt_level=3):
        graph, lib, params = relay.build(net, target, params=params, target_host=target_host)
elif args.frontend == "nnvm":
    net, params = from_mxnet(sym, arg_params, aux_params)
    with compiler.build_config(opt_level=3):
        graph, lib, params = compiler.build(
            net, target, {"data": dshape}, params=params, target_host=target_host)

Error (frontend relay) (nnvm works fine):

[13:31:00] /home/dlc/tvm/src/pass/vectorize_loop.cc:362: Detect vector condition in Vectorized Loop, scalarizing...
[13:31:00] /home/dlc/tvm/src/pass/vectorize_loop.cc:362: Detect vector condition in Vectorized Loop, scalarizing...
Traceback (most recent call last):
  File "./compile.py", line 74, in <module>
    graph, lib, params = relay.build(net, target, params=params, target_host=target_host)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/build_module.py", line 303, in build
    graph_json, lowered_funcs, params = graph_gen.codegen(func)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/backend/graph_runtime_codegen.py", line 90, in codegen
    self._codegen(func)
  File "tvm/_ffi/_cython/./function.pxi", line 304, in tvm._ffi._cy3.core.FunctionBase.__call__
  File "tvm/_ffi/_cython/./function.pxi", line 239, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./function.pxi", line 228, in tvm._ffi._cy3.core.FuncCall3
  File "tvm/_ffi/_cython/./base.pxi", line 168, in tvm._ffi._cy3.core.CALL
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x4abd70) [0x7fea34f4cd70]
  [bt] (7) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x49fc99) [0x7fea34f40c99]
  [bt] (6) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x4abbb3) [0x7fea34f4cbb3]
  [bt] (5) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x4af8d0) [0x7fea34f508d0]
  [bt] (4) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x4abbb3) [0x7fea34f4cbb3]
  [bt] (3) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x4af52f) [0x7fea34f5052f]
  [bt] (2) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x48b99f) [0x7fea34f2c99f]
  [bt] (1) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x49332f) [0x7fea34f3432f]
  [bt] (0) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x8e7cbb) [0x7fea35388cbb]
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/backend/_backend.py", line 52, in lower
    f = _build.lower(sch, inputs, name=func_name)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/build_module.py", line 387, in lower
    stmt = ir_pass.VectorizeLoop(stmt)
  File "tvm/_ffi/_cython/./function.pxi", line 304, in tvm._ffi._cy3.core.FunctionBase.__call__
  File "tvm/_ffi/_cython/./function.pxi", line 239, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./function.pxi", line 228, in tvm._ffi._cy3.core.FuncCall3
  File "tvm/_ffi/_cython/./base.pxi", line 168, in tvm._ffi._cy3.core.CALL
  [bt] (8) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x3fb6a1) [0x7fea34e9c6a1]
  [bt] (7) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x3fad15) [0x7fea34e9bd15]
  [bt] (6) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::ir::IRMutator::Mutate(HalideIR::Expr)+0x5d) [0x7fea34c9b99d]
  [bt] (5) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x1ac7d2) [0x7fea34c4d7d2]
  [bt] (4) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x335df3) [0x7fea34dd6df3]
  [bt] (3) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x32c327) [0x7fea34dcd327]
  [bt] (2) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::ir::IRMutator::Mutate_(HalideIR::Internal::LE const*, HalideIR::Expr const&)+0xf0) [0x7fea34dd25e0]
  [bt] (1) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x16421e) [0x7fea34c0521e]
  [bt] (0) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x145d63) [0x7fea34be6d63]
  File "/home/dlc/tvm/3rdparty/HalideIR/src/ir/./IR.h", line 177
  File "tvm/_ffi/_cython/./function.pxi", line 55, in tvm._ffi._cy3.core.tvm_callback
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/backend/_backend.py", line 60, in lower
    raise RuntimeError(msg)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/backend/_backend.py", line 52, in lower
    f = _build.lower(sch, inputs, name=func_name)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/build_module.py", line 387, in lower
    stmt = ir_pass.VectorizeLoop(stmt)
  File "tvm/_ffi/_cython/./function.pxi", line 304, in tvm._ffi._cy3.core.FunctionBase.__call__
  File "tvm/_ffi/_cython/./function.pxi", line 239, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./function.pxi", line 228, in tvm._ffi._cy3.core.FuncCall3
  File "tvm/_ffi/_cython/./base.pxi", line 168, in tvm._ffi._cy3.core.CALL
  [bt] (8) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x3fb6a1) [0x7fea34e9c6a1]
  [bt] (7) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x3fad15) [0x7fea34e9bd15]
  [bt] (6) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::ir::IRMutator::Mutate(HalideIR::Expr)+0x5d) [0x7fea34c9b99d]
  [bt] (5) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x1ac7d2) [0x7fea34c4d7d2]
  [bt] (4) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x335df3) [0x7fea34dd6df3]
  [bt] (3) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x32c327) [0x7fea34dcd327]
  [bt] (2) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::ir::IRMutator::Mutate_(HalideIR::Internal::LE const*, HalideIR::Expr const&)+0xf0) [0x7fea34dd25e0]
  [bt] (1) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x16421e) [0x7fea34c0521e]
  [bt] (0) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x145d63) [0x7fea34be6d63]
  File "/home/dlc/tvm/3rdparty/HalideIR/src/ir/./IR.h", line 177
TVMError: Check failed: a.type() == b.type(): BinaryOp of mismatched types
During handling of the above exception, another exception occurred:

TVMError: Check failed: a.type() == b.type(): BinaryOp of mismatched types
Error during compile function
-----------------------------
v0.0.1
fn (%p0: Tensor[(1, 16, 32, 32), float32], %p1: Tensor[(1, 24, 16, 16), float32], %p2: Tensor[(1, 24, 8, 8), float32], %p3: Tensor[(1, 24, 4, 4), float32], %p4: Tensor[(1, 16, 2, 2), float32], %p5: Tensor[(1, 16, 1, 1), float32], __dict__=meta[StrMap][0]) -> Tensor[(1, 24528), float32] {
  %0 = transpose(%p0, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 32, 32, 16), float32] */
  %1 = nn.batch_flatten(%0) /* ty=Tensor[(1, 16384), float32] */
  %2 = transpose(%p1, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 16, 16, 24), float32] */
  %3 = nn.batch_flatten(%2) /* ty=Tensor[(1, 6144), float32] */
  %4 = transpose(%p2, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 8, 8, 24), float32] */
  %5 = nn.batch_flatten(%4) /* ty=Tensor[(1, 1536), float32] */
  %6 = transpose(%p3, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 4, 4, 24), float32] */
  %7 = nn.batch_flatten(%6) /* ty=Tensor[(1, 384), float32] */
  %8 = transpose(%p4, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 2, 2, 16), float32] */
  %9 = nn.batch_flatten(%8) /* ty=Tensor[(1, 64), float32] */
  %10 = transpose(%p5, axes=[0, 2, 3, 1]) /* ty=Tensor[(1, 1, 1, 16), float32] */
  %11 = nn.batch_flatten(%10) /* ty=Tensor[(1, 16), float32] */
  %12 = (%1, %3, %5, %7, %9, %11)
  concatenate(%12, axis=1) /* ty=Tensor[(1, 24528), float32] */
}
/* meta data */
{
  "root": 1, 
  "nodes": [
    {
      "type_key": ""
    }, 
    {
      "type_key": "StrMap", 
      "keys": [
        "StrMap"
      ], 
      "data": [2]
    }, 
    {
      "type_key": "Array", 
      "data": [3]
    }, 
    {
      "type_key": "StrMap", 
      "keys": [
        "Primitive"
      ], 
      "data": [4]
    }, 
    {
      "type_key": "IntImm", 
      "attrs": {
        "dtype": "int32", 
        "value": "1"
      }
    }
  ], 
  "b64ndarrays": [], 
  "attrs": {"tvm_version": "0.6.dev"}
}

I encounter the same error message mismatch type, but my case is tensroflow inception v1. I searched though the commit history, it starts failing from commit 7afbca5691fdb599cd90b043d5a5036e55cae2d6. FYI @tqchen

I’ll dig a bit more.

The failing statement for my case is:

Vectorizing loop produce tensor {
  parallel (ax0.ax1.fused.ax2.fused, 0, 1536) {
    for (ax3.outer, 0, 2) {
      vectorized (ax3.inner, 0, 8) {
        tensor[(((ax0.ax1.fused.ax2.fused*16) + (ax3.outer*8)) + ax3.inner)] = tvm_if_then_else(((((1 <= (ax0.ax1.fused.ax2.fused % 16)) && ((ax0.ax1.fused.ax2.fused % 16) < 15)) && (1 <= ((ax3.outer*8) + ax3.inner))) && (((ax3.outer*8) + ax3.inner) < 15)), max(((input0[((((((ax0.ax1.fused.ax2.fused/16)*196) + ((ax0.ax1.fused.ax2.fused % 16)*14)) + (ax3.outer*8)) + ax3.inner) - 15)]*input1[(ax0.ax1.fused.ax2.fused/16)]) + input2[(ax0.ax1.fused.ax2.fused/16)]), 0.000000f), 0.000000f)
      }
    }
  }
}

The mismatch expression is:

type mismatch: 1 int32 <> ramp((ax3.outer*8), 1, 8) int32x8