Skip to content

新手遇到问题留言一下!出现“Model name 'model_train' not found in the model mapping”的解决方法 #1523

@Alanble

Description

@Alanble

就是在微调完embedding模型之后,我想利用自己准备的数据来评估一下模型效果,但是输入模型权重路径之后一直显示“Model name 'model_train' not found in the model mapping”错误。

然后查了很久,发现是:在FlagEmbedding 的设计里,它需要同时知道 模型类型 和 权重路径:
模型类型(例如 bge-m3、bge-base-zh 等)告诉框架要用哪个类来实例化模型(BGEM3FlagModel 等)。
权重路径告诉框架用你保存的 checkpoint 来初始化模型参数。
框架在读取 --embedder_name_or_path 时,会把最后一层目录名当作模型名去 AUTO_EMBEDDER_MAPPING 查找。如果目录名是 checkpoint-2110,框架就会把 "checkpoint-2110" 当作模型名去找,但映射里没有这个名字,所以报错。

所以我们还需要加上一句 “ --embedder_model_class encoder-only-base \” 命令。
我当时是用“bge-base-en-v1.5”模型微调的,对应的模型类型就是“encoder-only-base”

如果不确定模型是哪个类型,可以输入“python -m FlagEmbedding.evaluation.custom --help”,会发现:
class EmbedderModelClass(Enum):
ENCODER_ONLY_BASE = "encoder-only-base"
ENCODER_ONLY_M3 = "encoder-only-m3"
DECODER_ONLY_BASE = "decoder-only-base"
DECODER_ONLY_ICL = "decoder-only-icl"
一共4个类型,再根据自己选择的模型对应一下就行!

加上之后就可以成功加载模型权重啦!

我是第一次复现代码,有错误理解的地方也请大佬们指正!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions