def load_pretrained_model(nmt_model, pretrain_path, device, exclude_prefix=None):
    "\n    Args:\n        nmt_model: model.\n        pretrain_path ('str'): path to pretrained model.\n        map_dict ('dict'): mapping specific parameter names to those names\n            in current model.\n        exclude_prefix ('dict'): excluding parameters with specific names\n            for pretraining.\n\n    Raises:\n        ValueError: Size not match, parameter name not match or others.\n\n    "
    if (exclude_prefix is None):
        exclude_prefix = []
    if (pretrain_path != ''):
        INFO('Loading pretrained model from {}'.format(pretrain_path))
        pretrain_params = torch.load(pretrain_path, map_location=device)
        for (name, params) in pretrain_params.items():
            flag = False
            for pp in exclude_prefix:
                if name.startswith(pp):
                    flag = True
                    break
            if flag:
                continue
            INFO('Loading param: {}...'.format(name))
            try:
                nmt_model.load_state_dict({name: params}, strict=False)
            except Exception as e:
                WARN('{}: {}'.format(str(Exception), e))
        INFO('Pretrained model loaded.')
Args:
    nmt_model: model.
    pretrain_path ('str'): path to pretrained model.
    map_dict ('dict'): mapping specific parameter names to those names
        in current model.
    exclude_prefix ('dict'): excluding parameters with specific names
        for pretraining.

Raises:
    ValueError: Size not match, parameter name not match or others.
def load_pretrained_model(nmt_model, pretrain_path, device, exclude_prefix=None):
    "\n    Args:\n        nmt_model: model.\n        pretrain_path ('str'): path to pretrained model.\n        map_dict ('dict'): mapping specific parameter names to those names\n            in current model.\n        exclude_prefix ('dict'): excluding parameters with specific names\n            for pretraining.\n\n    Raises:\n        ValueError: Size not match, parameter name not match or others.\n\n    "
    if (exclude_prefix is None):
        exclude_prefix = []
    if (pretrain_path != ):
        INFO('Loading pretrained model from {}'.format(pretrain_path))
        pretrain_params = torch.load(pretrain_path, map_location=device)
        for (name, params) in pretrain_params.items():
            flag = False
            for pp in exclude_prefix:
                if name.startswith(pp):
                    flag = True
                    break
            if flag:
                continue
            INFO('Loading param: {}...'.format(name))
            try:
                nmt_model.load_state_dict({name: params}, strict=False)
            except Exception as e:
                WARN('{}: {}'.format(str(Exception), e))
        INFO('Pretrained model loaded.')