KeyError when running the sample code snippet

#2
by yumemio - opened

Hello! I ran the sample code snippet on Colab:

import torch
from transformers import AutoTokenizer
from peft import AutoPeftModelForCausalLM

prompt_template = """### 指示:
{instruction}

### 応答:
"""

tokenizer = AutoTokenizer.from_pretrained("stockmark/stockmark-100b-instruct-v0.1")
model = AutoPeftModelForCausalLM.from_pretrained("stockmark/stockmark-100b-instruct-v0.1", device_map="auto", torch_dtype=torch.bfloat16)

But the model = AutoPeftModelForCausalLM.from_pretrained(...) line raised this error:

---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

<ipython-input-1-24fa99321ba3> in <cell line: 12>()
     10 
     11 tokenizer = AutoTokenizer.from_pretrained("stockmark/stockmark-100b-instruct-v0.1")
---> 12 model = AutoPeftModelForCausalLM.from_pretrained("stockmark/stockmark-100b-instruct-v0.1", device_map="auto", torch_dtype=torch.bfloat16)

3 frames

/usr/local/lib/python3.10/dist-packages/peft/auto.py in from_pretrained(cls, pretrained_model_name_or_path, adapter_name, is_trainable, config, **kwargs)
    126             base_model.resize_token_embeddings(len(tokenizer))
    127 
--> 128         return cls._target_peft_class.from_pretrained(
    129             base_model,
    130             pretrained_model_name_or_path,

/usr/local/lib/python3.10/dist-packages/peft/peft_model.py in from_pretrained(cls, model, model_id, adapter_name, is_trainable, config, **kwargs)
    428         else:
    429             model = MODEL_TYPE_TO_PEFT_MODEL_MAPPING[config.task_type](model, config, adapter_name)
--> 430         model.load_adapter(model_id, adapter_name, is_trainable=is_trainable, **kwargs)
    431         return model
    432 

/usr/local/lib/python3.10/dist-packages/peft/peft_model.py in load_adapter(self, model_id, adapter_name, is_trainable, torch_device, **kwargs)
   1020                 )
   1021 
-> 1022             self._update_offload(offload_index, adapters_weights)
   1023             dispatch_model_kwargs["offload_index"] = offload_index
   1024 

/usr/local/lib/python3.10/dist-packages/peft/peft_model.py in _update_offload(self, offload_index, adapters_weights)
    906                         suffix_pos = safe_key.rfind(".")
    907                         extended_prefix = prefix + block_id + safe_key[:suffix_pos]
--> 908                         safe_module = dict(self.named_modules())[extended_prefix]
    909                         if isinstance(safe_module, BaseTunerLayer):
    910                             final_key = extended_prefix + ".base_layer" + safe_key[suffix_pos:]

KeyError: 'base_model.model.model.model.layers.22.input_layernorm'

My environment:

transformers==4.41.0
peft==0.11.1

I would appreciate it if anyone could shed some light on this. Thanks!

yumemio changed discussion title from ` KeyError: 'base_model.model.model.model.layers.22.input_layernorm'` to KeyError when running the sample code snippet

Sign up or log in to comment