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

修改后就可以训练了。

相关推荐
爱睡觉的咋5 天前
error: RPC failed; HTTP 408 curl 22 The requested URL returned error: 408
python·debug
GuokLiu12 天前
250405-VSCode编辑launch.json实现Debug调试Open-WebUI
vscode·debug·open-webui
啊波次得饿佛哥17 天前
C# debug和release模式问题
visualstudio·debug·release
千里马学框架20 天前
android studio调试aosp手机userdebug版本无法查看局部变量和参数问题如何解决?
android·智能手机·车载系统·android studio·debug·调试·系统开发
ssshooter1 个月前
浏览器 67 个实用 Debug 技巧
前端·javascript·debug
|Ringleader|1 个月前
【Unity Bug 随记】使用Rider debug功能时Unity Reload Domain卡死问题
unity·bug·debug·rider·reload domain
JQShan1 个月前
iOS符号表:崩溃日志中的“翻译官”,开发中的隐藏高手
面试·debug·swift
辰尘_星启1 个月前
【vscode】一键编译运行c/c++程序
c语言·c++·vscode·debug·cmake
天启A1 个月前
变量命名不规范&我被deepseek骗了
debug·软件工程日报
开出南方的花3 个月前
大模型微调介绍-Prompt-Tuning
人工智能·自然语言处理·lora·llm·prompt·peft·adapter