Quantization fails with segmentation fault for some SSD models

Issue description

Quantization of some pretrained GluonCV SSD models fails with segmentation fault.

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 model ssd_512_resnet50_v1_voc from GluonCV with gluoncv.model_zoo.get_model()
  5. Convert the model to a TVM Relay graph with tvm.relay.frontend.from_mxnet()
  6. Quantize the model with tvm.relay.quantize.quantize()

What’s the expected result?

  • Quantization succeeds

What’s the actual result?

  • Quantization fails with a segmentation fault

Additional details

  • The error occurs in the function tvm::relay::GetValidCountRel(), in the call dshape.size() where dshape is an Array object representing the shape of an input tensor
  • Confirmed for models ssd_512_resnet50_v1_voc and ssd_512_mobilenet1.0_voc
  • Confirmed for TVM commits 0ea99698 and 151f3f5a
  • If SimplifyInference is removed from the list of passes applied in prerequisite_optimize() called from the function tvm.relay.quantize.quantize() before the main quantization passes, quantization succeeds and inference may be successfully executed for TVM commit 0ea99698, whereas for TVM commit 151f3f5a quantization fails due to the issue Quantization fails with recent master commits of TVM

Suggested solutions

  • Add support in TVM for quantization of the GluonCV pretrained models ssd_512_resnet50_v1_voc and ssd_512_mobilenet1.0_voc

@anijain2305 maybe you’re interested in this