KeyError for missing key attrs when converting some SSD INT8 models to Relay graph

Issue description

Conversion of pretrained quantized GluonCV models ssd_512_resnet50_v1_voc_int8 and ssd_512_mobilenet1.0_voc_int8 to TVM Relay graphs fails with KeyError for missing key “attrs”.

Steps to reproduce the issue

  1. Prepare hardware and environment that meet the requirements for TVM
  2. Install MXNet 1.5.1 or 1.6.0, GluonCV 0.7.0, and the latest MKL-DNN library
  3. Build TVM with USE_MKLDNN ON
  4. Download pretrained INT8 model ssd_512_resnet50_v1_voc_int8 or ssd_512_mobilenet1.0_voc_int8 from GluonCV with gluoncv.model_zoo_get_model()
  5. Convert the model to a TVM Relay graph with tvm.relay.frontend.from_mxnet()

What’s the expected result?

  • Graph conversion succeeds

What’s the actual result?

  • Graph conversion fails with the following KeyError:

    File "/usr/tvm/python/tvm/relay/frontend/mxnet.py", line 1589, in _get_bn_alpha_coeff
    bn_attrs = _get_subgraph_op(subgraphs, 'BatchNorm')['attrs']
    KeyError: 'attrs'
    

Additional details

  • The offending graph node is a BatchNorm node in a subgraph of operator _sg_mkldnn_conv
  • _qnn_conv in relay/frontend/mxnet.py expects a key “attrs” in all BatchNorm nodes in this operator
  • The error occurs because the BatchNorm nodes ssd0_expand_* in this operator have no key “attrs”

Suggested solutions

  • Fix TVM graph conversion of quantized models so as not to cause KeyError