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 代码

# 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检查是否是量化模型

 _is_quantized_and_base_model = getattr(model, "is_quantized", False) and not getattr(
     model, "_hf_peft_config_loaded", False
 )

_is_peft_model检查是否是PeftModel或者PeftMixedModel

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是什么类型呢?

<class 'src.peft.peft_model.PeftModelForCausalLM'>

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

from src.peft import LoraConfig, TaskType, get_peft_model
改为
from peft import LoraConfig, TaskType, get_peft_model

修改后就可以训练了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值