ziwang-com / zero-lora

zero零训练llm调参

Home Page:http://www.m-f.vip

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

加载 LoRa 大小不匹配 49954 与 32000

ziwang-com opened this issue · comments

oobabooga/text-generation-webui#959

我尝试从 https://github.com/ymcui/Chinese-LLaMA-Alpaca
加载 lora,https://huggingface.co/ziqingyang/chinese-llama-lora-7b
它报告了以下错误:

RuntimeError('Error(s) in load state_dict for {}:\n\t{}'.format(
RuntimeError: Errors in loading state_dict for PeftModelForCausalLM: size 不匹配 for base_model.model.model.embed_tokens.weight:
使用形状火炬复制参数。尺寸([49954, 4096]) 从检查点开始,当前模型中的形状是割炬。大小([32000, 4096])。
base_model.model.lm_head.weight的大小不匹配:使用形状火炬复制参数。尺寸([49954, 4096]) 从检查点开始,当前模型中的形状是割炬。大小([32000, 4096])。

从错误消息来看,模型检查点的大小是正确的 (49954),但初始化的模型嵌入是 32000,因此它不会加载,问题应该只在 config.json 中。

我尝试在config.json中将vocab_size从32000修改为49954,但仍然报告上述错误。
就像https://github.com/ymcui/Chinese-LLaMA-Alpaca/issues/87一样,但是他可以在将vocab_size修改为49954后成功加载Lora,他没有使用文本生成webui。

这是否存在现有问题?

此解决方案解决了这个问题,需要替换 tokenizer.model 并调整 tokenizer 的大小。
ymcui/Chinese-LLaMA-Alpaca#136

将下载的 lora 权重放入 loras 文件夹
ls loras/chinaese-alpaca-lora-7b
adapter_config.json adapter_model.bin special_tokens_map.json tokenizer_config.json tokenizer.model

将拥抱脸格式的骆驼-7B模型文件放入模型文件夹中
ls models/llama-7b-hf
pytorch_model-00001-of-00002.bin pytorch_model-00002-of-00002.bin config.json pytorch_model.bin.index.json generation_config.json

将 lora 权重的分词器复制到模型/美洲驼-7b-hf
cp loras/**羊驼-lora-7b/tokenizer.model models/llama-7b-hf/ cp loras/chinaese-alpaca-lora-7b/special_tokens_map.json models/llama-7b-hf/ cp loras/chinaese-alpaca-lora-7b/tokenizer_config.json models/llama-7b-hf/

修改 /modules/LoRA.py 文件,大约第 28 行
shared.model.resize_token_embeddings(49954) assert shared.model.get_input_embeddings().weight.size(0) == 49954 shared.model = PeftModel.from_pretrained(
shared.model, Path(f“{shared.args.lora_dir}/{lora_name}”), **params)

接下来你可以开心地跑了,参考 https://github.com/oobabooga/text-generation-webui/wiki/Using-LoRAs
蟒蛇 server.py --模型美洲驼-7b-hf --劳拉**羊驼-劳拉-7b