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

修改后就可以训练了。

相关推荐
Pomelo_刘金10 天前
Rust : 无法通过 Cargo 拉取私有代码仓库解决方式 failed to load source for dependency
rust·debug
EniacCheng15 天前
【Vulkan入门】04-开启Debug输出
debug·vulkan
John_Snowww18 天前
6.824/6.5840 Lab 1: MapReduce
mapreduce·debug·6.824·6.5840
Swift社区25 天前
工具与技术在 Debug 中的应用
前端·typescript·debug
HuggingFace1 个月前
介绍 GGUF-my-LoRA
lora·peft·gguf
写点什么啦1 个月前
[debug]不同的window连接ubuntu的vscode后无法正常加载kernel
linux·vscode·ubuntu·debug
mingshili1 个月前
[python] 如何debug python脚本中C++后端的core dump
c++·python·debug
ViatorSun2 个月前
「图文详解」Pycharm 远程服务器Debug
python·深度学习·算法·pycharm·debug·1024程序员节
tekin2 个月前
图解 微信开发者工具 小程序源码 调试、断点标记方法 , 微信小程序调试器,真机调试断点调试方法,小程序网络API请求调试方法 总结
微信小程序·debug·调试·断点·真机调试·miniapp·网络api请求调试方法
云卷风舒2 个月前
Fedora40使用Timeshift恢复数据后无法启动(解决办法)
linux·debug·fedora