[ERROR] Error while compiling mobilenet_v1_1.0_224.tflite on opencl target


I was trying execute following code:

tflite_model_file = os.path.join("mobilenet_v1_1.0_224.tflite")
tflite_model_buf = open(tflite_model_file, "rb").read()

      import tflite
      tflite_model = tflite.Model.GetRootAsModel(tflite_model_buf, 0)
  except AttributeError:
      import tflite.Model
      tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0)

shape_dict = {'input': (1, 244, 244, 3)}

sym, params = tvm.relay.frontend.from_tflite(tflite_model, shape_dict=shape_dict, dtype_dict={'input': 'float32'})

graph, lib, params = tvm.relay.build(sym, target='opencl', params=params)

and I get following error.

VMError: Check failed: match: iter_var(threadIdx.x, , threadIdx.x) domain already inferred, cannot prove their extents are the same 256 vs 128

How to troubleshoot this issue?

Thank you for help in advance.

Best Regards

Marcin Sielski

Your problem is similar to mine. I think that my solution can be applied to the problem.

I compile a TFLite model according to the following TVM tutorial: Deploy a Framework-prequantized Model with TVM with the TVM commit da27e6d9a466263a9a0025aba92086a8bf837edb on 2020/8/7

The tutorial run successfully with “llvm” target; however, it fails with “opencl” target, and I get an error message similar to yours. Note that, to run the tutorial with “opencl” target, the modification is as follows:

target = 'opencl'
ctx = tvm.cl(0)
rt_mod = graph_runtime.GraphModule(lib['default'](tvm.cl(0)))

To solve the problem, at first I convert the layout into NCHW after relay.frontend.from_tflite:

desired_layouts = {'nn.conv2d': ['NCHW', 'default'], 'qnn.conv2d': ['NCHW', 'default']}
seq = tvm.transform.Sequential([relay.transform.RemoveUnusedFunctions(),
with tvm.transform.PassContext(opt_level=3):
    mod = seq(mod)

Then, I remove topi.cuda.conv2d_nchw_int8 form python/tvm/relay/op/strategy/cuda.py because TVM uses cuda’s schedules for scheduling opencl, and I find that conv2d_nchw.cuda and depthwise_conv2d_nchw.cuda are stable enough to run the MobileNet model.

Finally, we can run the modified tutorial successfully and get the following result:

TVM Top-5 labels: [387 102 386 349 341]
TFLite Top-5 labels: [387 102 386 341 880]
Elapsed average ms: 2.1388191100000005