Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

训练时使用的QLoRA 4rank,进行cuda模型合并导出时出现,KeyError: 'base_model.model.model.model.layers.14.mlp.down_proj' #2213

Open
4 tasks
xiaoheiyue opened this issue Nov 14, 2024 · 4 comments

Comments

@xiaoheiyue
Copy link

System Info

File "/home/mukuro/projects/LLaMA-Factory/src/llamafactory/model/adapter.py", line 299, in init_adapter
model = _setup_lora_tuning(
^^^^^^^^^^^^^^^^^^^
File "/home/mukuro/projects/LLaMA-Factory/src/llamafactory/model/adapter.py", line 181, in _setup_lora_tuning
model: "LoraModel" = PeftModel.from_pretrained(model, adapter, **init_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mukuro/softwares/miniconda3/envs/qwen2.5/lib/python3.11/site-packages/peft/peft_model.py", line 545, in from_pretrained
model.load_adapter(
File "/home/mukuro/softwares/miniconda3/envs/qwen2.5/lib/python3.11/site-packages/peft/peft_model.py", line 1151, in load_adapter
self._update_offload(offload_index, adapters_weights)
File "/home/mukuro/softwares/miniconda3/envs/qwen2.5/lib/python3.11/site-packages/peft/peft_model.py", line 1028, in _update_offload
safe_module = dict(self.named_modules())[extended_prefix]
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'base_model.model.model.model.layers.14.mlp.down_proj'

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder
  • My own task or dataset (give details below)

Reproduction

llamafactory 使用 peft 0.12.0

Expected behavior

我希望能解决这个问题正常合并

@JINO-ROHIT
Copy link
Contributor

looks like some mismatch, can you ensure using

print(dict(model.named_modules()).keys())

@xiaoheiyue
Copy link
Author

looks like some mismatch, can you ensure using

print(dict(model.named_modules()).keys())

是查看原模型的吗?训练的 LoRA adapter 和模型层数是一样的,每个层 att qkv 还有 mlp 的 那些也都有。

@xiaoheiyue
Copy link
Author

image
少了一个 .model 的前缀。

@xiaoheiyue
Copy link
Author

      if index:
            print("index", index)
            print('model.layers.14.mlp.gate_proj.weight' in index)				
            offload_index = {
                p: {
                    "safetensors_file": index[p]["safetensors_file"],
                    "weight_name": p,
                    "dtype": str(weight_map[p].dtype).replace("torch.", ""),
                }
                for p in weight_map.keys()
                if p in disk_modules
            }
            kwargs["offload_index"] = offload_index

    if (getattr(model, "hf_device_map", None) is not None) and len(
        set(model.hf_device_map.values()).intersection({"cpu", "disk"})
    ) > 0:
        remove_hook_from_submodules(model)

这是不是意味着原始模型少了 14 层

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants