The metric_for_best_model training argument is set to ‘eval_loss‘, which is not found in the evaluat

eval_loss not found when training a peft model The metric_for_best_model training argument is set to ‘eval_loss’, which is not found in the evaluation metrics

记录lora微调qwen 2.5 VL加上验证集碰到的一个bug,加了验证集但是返回的 evaluation metrics没有eval_loss

KeyError: “The metric_for_best_model training argument is set to ‘eval_loss’, which is not found in the evaluation metrics. The available evaluation metrics are: [‘eval_runtime’, ‘eval_samples_per_second’, ‘eval_steps_per_second’, ‘epoch’, ‘memory_allocated (GB)’, ‘max_memory_allocated (GB)’, ‘total_memory_available (GB)’]. Consider changing the metric_for_best_model via the TrainingArguments.”

解决方案:
修改Transformer库 trainer函数
Class Trainer init 函数里面大概第782行左右

        if _is_peft_model(self.model) and self.args.label_names is None:
            logger.warning(
                f"No label_names provided for model class `{self.model.__class__.__name__}`."
                " Since `PeftModel` hides base models input arguments, if label_names is not given, label_names can't be set automatically within `Trainer`."
                " Note that empty label_names list will be used instead."
            )
        default_label_names = find_labels(self.model.__class__)
        self.label_names = default_label_names if self.args.label_names is None else self.args.label_names
        self.can_return_loss = can_return_loss(self.model.__class__)
        self.control = self.callback_handler.on_init_end(self.args, self.state, self.control)

改成

        if _is_peft_model(self.model):
            if hasattr(self.model, "get_base_model"):
                model_to_inspect = self.model.get_base_model()
                default_label_names = find_labels(model_to_inspect.__class__)
                self.can_return_loss = can_return_loss(model_to_inspect.__class__)
        else:
            default_label_names = find_labels(self.model.__class__)
            self.can_return_loss = can_return_loss(self.model.__class__)

        self.label_names = default_label_names if self.args.label_names is None else self.args.label_names
        self.control = self.callback_handler.on_init_end(self.args, self.state, self.control)

参考:
eval_loss not found when training a peft model using trainer.py https://github.com/huggingface/transformers/issues/33420

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值