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

修改后就可以训练了。

相关推荐
Wilber的技术分享4 天前
【大模型面试八股 3】大模型微调技术:LoRA、QLoRA等
人工智能·深度学习·面试·lora·peft·qlora·大模型微调
REDcker8 天前
Android HWASan 详解:硬件标记原理、Clang 启用与排障实践
android·linux·debug·编译·clang·asan·hwasan
Joseph Cooper14 天前
大模型微调技术完全指南:从原理到实践的系统性入门(2026 版)
人工智能·chatgpt·lora·peft·qlora·大模型微调·dpo
冬奇Lab23 天前
烧了数千美金 Token,我用 AI Agent 打通了企业级 Bug 修复全流程
人工智能·debug
Watink Cpper1 个月前
Ubuntu24.04网络图标消失导致无法上网--排查得到原因:内核和驱动版本不匹配
运维·网络·linux内核·运维开发·debug·ubuntu24.04
ListenAlone1 个月前
Visual Studio 2017 调试长时间未响应问题排查
debug·vs2017
博士僧小星1 个月前
人工智能|大模型——训练——大模型微调全栈指南:从Transformer架构、10+种PEFT原理、流程与实战(全网最详细)
人工智能·lora·大模型·微调·peft·qlora·prefix tuning
G果2 个月前
ros2工程 debug(vscode)
c++·ide·vscode·编辑器·bug·debug·ros2
蜡台2 个月前
VSCode 配置PHP开发环境
ide·vscode·php·debug·launch.json
爱吃的小肥羊2 个月前
Claude Code新功能:帮你找bug,但每次要收你20美元!
debug