ValueError: You cannot perform fine-tuning on purely quantized models.

在使用peft 微调8bit 或者4bit 模型的时候,可能会报错:

You cannot perform fine-tuning on purely quantized models. Please attach trainable adapters on top of the quantized model to correctly perform fine-tuning. Please see: https://huggingface.co/docs/transformers/peft for more details"

查看trainer.py 代码

python 复制代码
# At this stage the model is already loaded
if _is_quantized_and_base_model and not _is_peft_model(model):
    raise ValueError(
        "You cannot perform fine-tuning on purely quantized models. Please attach trainable adapters on top of"
        " the quantized model to correctly perform fine-tuning. Please see: https://huggingface.co/docs/transformers/peft"
        " for more details"
    )

_is_quantized_and_base_model检查是否是量化模型

python 复制代码
 _is_quantized_and_base_model = getattr(model, "is_quantized", False) and not getattr(
     model, "_hf_peft_config_loaded", False
 )

_is_peft_model检查是否是PeftModel或者PeftMixedModel

python 复制代码
def _is_peft_model(model):
    if is_peft_available():
        classes_to_check = (PeftModel,) if is_peft_available() else ()
        # Here we also check if the model is an instance of `PeftMixedModel` introduced in peft>=0.7.0: https://github.com/huggingface/transformers/pull/28321
        if version.parse(importlib.metadata.version("peft")) >= version.parse("0.7.0"):
            from peft import PeftMixedModel

            classes_to_check = (*classes_to_check, PeftMixedModel)
        return isinstance(model, classes_to_check)
    return False

DEBUG:

1.加载模型的时候已经设置了量化参数,确定是量化模型;

2.使用了model = get_peft_model(model, config),为什么不是PeftModel,那model是什么类型呢?

python 复制代码
<class 'src.peft.peft_model.PeftModelForCausalLM'>

这是因为在测试peft代码的时候,设置了使用本地peft代码,而不是安装的peft库,就导致类型出现了错误。

python 复制代码
from src.peft import LoraConfig, TaskType, get_peft_model
改为
from peft import LoraConfig, TaskType, get_peft_model

修改后就可以训练了。

相关推荐
XYiFfang3 天前
【Python+requests】解决Python requests中的ProxyError:SSL版本错误问题详解
python·debug·ssl·常见错误·代理配置
青草地溪水旁5 天前
C++ 登录状态机项目知识笔记
c++·ubuntu·debug·vscode远程调试
大千AI助手6 天前
COLA:大型语言模型高效微调的革命性框架
人工智能·语言模型·自然语言处理·lora·peft·cola·残差学习
快乐肚皮10 天前
IntelliJ IDEA Debug 模式功能指南
java·ide·intellij-idea·debug
AAA修煤气灶刘哥18 天前
日志排查不用慌!从采集到 ELK 实战,手把手教你搞定线上问题
后端·面试·debug
摸着石头过河的石头18 天前
前端调试全攻略:从PC到移动端的一站式实战指南
前端·debug
大熊猫侯佩19 天前
「内力探查术」:用 Instruments 勘破 SwiftUI 卡顿迷局
swiftui·debug·xcode
每天开心1 个月前
🐞一次由事件冒泡引发的 React 弹窗关闭 Bug 排查与解决
前端·javascript·debug
爱分享的飘哥1 个月前
第五十五章:AI模型的“专属定制”:LoRA微调原理与高效合并技巧
人工智能·lora·微调·ai训练·peft·代码实战·模型定制
zero_face1 个月前
记录一次Spring5中事件通知机制bug引起的生产事故
后端·spring·debug