# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# pylint: disable=import-error,no-name-in-module,no-member

from typing import List, Union

import megengine as mge
from megengine.traced_module import TracedModule

from ..backend.ir_to_caffe.caffe_converter import BackEnd, CaffeConverter
from ..converter_ir.ir_quantizer import IRQuantizer
from ..converter_ir.ir_transform import IRTransform, TransformerRule
from ..frontend.tm_to_ir import TM_FrontEnd
from ..frontend.tm_to_ir.tm_utils import _update_inputs_qparams


def tracedmodule_to_caffe(
    traced_module,
    prototxt="out.prototxt",
    caffemodel="out.caffemodel",
    outspec=None,
    use_empty_blobs=False,
    input_data_type: str = None,
    input_scales: Union[float, List[float]] = None,
    input_zero_points: Union[int, List[int]] = None,
    require_quantize=False,
    param_fake_quant=False,
    split_conv_relu=False,
    quantize_file_path="quant_params.json",
    convert_backend: BackEnd = BackEnd.CAFFE,
):
    """
    Convert TracedModule model to Caffe,
    and save caffe model to `prototxt` and `caffemodel`.

    :param traced_module: the file path of TracedModule model.
    :type traced_module: str
    :param prototxt: the filename used for saved model definition.
    :type prototxt: str
    :param caffemodel: the filename used for saved model weights.
    :type caffemodel: str
    :param outspec: specify the end points of the model, expect the full names of nodes.
    :type outspec: list
    """
    if isinstance(traced_module, str):
        traced_module = 
mge.load(traced_module)