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

修改后就可以训练了。

相关推荐
MrBread1 天前
微任务链式派生阻塞渲染
前端·debug
冬奇Lab3 天前
应用异常退出实战分析:一次"幽灵杀手"引发的车载系统故障排查
android·性能优化·debug
yuki_uix3 天前
为什么我的 Auth Token 藏在了 Network 面板的 Doc 里?
前端·python·debug
淡海水13 天前
【节点】[EyeSurfaceTypeDebug节点]原理解析与实际应用
unity·游戏引擎·debug·shadergraph·图形·surface·eye
十五年专注C++开发15 天前
C++中各平台表示Debug的宏
开发语言·c++·debug
小明_GLC17 天前
大模型微调 PEFT vs LLaMA-Factory
人工智能·llama·peft·大模型微调·方法对比
xiaobobo33301 个月前
EIDE的最新版本已经默认只支持debug调试STM32单片机了
stm32·单片机·debug·eide
智驾1 个月前
【瑞萨RA x Zephyr评测】四、在线调试功能
vscode·debug·瑞萨·zephyr·renesas·ra6e2·fpb-ra6e2
冬奇Lab1 个月前
稳定性性能系列之十五——系统稳定性监控体系建设:从指标到预警的完整方案
android·性能优化·debug
冬奇Lab1 个月前
稳定性性能系列之十四——电量与网络优化:Battery Historian与弱网处理实战
android·性能优化·debug