Relay quantize pass error on model from TensorFlow

Hi, I encounter error when I try to run relay.quantize.quantize() on converted module from TensorFlow slim: “FoldScaleAxis only accept dataflow-form”

Our code is like:

parser = TFParser("./data/resnet_saved_model")
graph_def = parser.parse()

module, params = relay.frontend.from_tensorflow(graph_def, layout="NCHW")

with relay.build_config(opt_level=3):
    with relay.quantize.qconfig(global_scale=8.0, skip_conv_layers=[0]):
        module = relay.quantize.quantize(module, params=params)

I find that the pass “FoldScaleAxis” is required by quantize here and this pass do not allow let node or else it will raise the error above.

# python/tvm/relay/quantize/
def prerequisite_optimize(mod, params=None):
    """ Prerequisite optimization passes for quantization. Perform
    "SimplifyInference", "FoldScaleAxis", "FoldConstant", and
    "CanonicalizeOps" optimization before quantization. """
    optimize = _transform.Sequential([_transform.SimplifyInference(),
  # ...

Print the converted module shows that module[“main”] is just a sequence of op calls without let binding, but there seems to be many unused functions like

def @map_accumr[A, B, C](%f11: fn (A, B) -> (A, C), %init1: A, %xs13: List[B]) -> (A, List[C]) {
  let %updater1: fn (B, (A, List[C])) -> (A, List[C]) = fn (%x41: B, %acc3: (A, List[C])) -> (A, List[C]) {
    %1014 = %acc3.0;
    let %f_out1: (A, C) = %f11(%1014, %x41) /* ty=(A, C) */;
    %1015 = %f_out1.0;
    %1016 = %f_out1.1;
    %1017 = %acc3.1;
    %1018 = Cons(%1016, %1017) /* ty=List[C] */;
    (%1015, %1018)
  %1019 = Nil /* ty=List[C] */;
  %1020 = (%init1, %1019);
  @foldr(%updater1, %1020, %xs13) /* ty=(A, List[C]) */

These extra functions are not used by our model and may lead to pass error of FoldScaleAxis. Can I remove these guys or disable passes on them?