`AttributeError: 'ModuleDict' object has no attribute 'get_input_embeddings'` when finetuning
#7
by
						
matorus
	
							
						- opened
							
					
When trying to finetune using Mosaic's composer train.py (with a more or less default finetuning yaml) I get: AttributeError: 'ModuleDict' object has no attribute 'get_input_embeddings'
Any ideas how to circumvent the issue?
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ /home/matthias/src/replit-finetune/../llm-foundry/scripts/train/train.py:326 in <module>         โ
โ                                                                                                  โ
โ   323 โ   โ   yaml_cfg = om.load(f)                                                              โ
โ   324 โ   cli_cfg = om.from_cli(args_list)                                                       โ
โ   325 โ   cfg = om.merge(yaml_cfg, cli_cfg)                                                      โ
โ โฑ 326 โ   main(cfg)                                                                              โ
โ   327                                                                                            โ
โ                                                                                                  โ
โ /home/matthias/src/replit-finetune/../llm-foundry/scripts/train/train.py:215 in main             โ
โ                                                                                                  โ
โ   212 โ   โ   โ   โ   cfg.model, cfg.lora, tokenizer)                                            โ
โ   213 โ   โ   โ   print_trainable_parameters(model)  # should not be 100%                        โ
โ   214 โ   โ   else:  # standard model                                                            โ
โ โฑ 215 โ   โ   โ   model = build_composer_model(cfg.model, tokenizer)                             โ
โ   216 โ   cfg.n_params = sum(p.numel() for p in model.parameters())                              โ
โ   217 โ   print(f'{cfg.n_params=:.2e}')                                                          โ
โ   218                                                                                            โ
โ                                                                                                  โ
โ /home/matthias/src/replit-finetune/../llm-foundry/scripts/train/train.py:70 in                   โ
โ build_composer_model                                                                             โ
โ                                                                                                  โ
โ    67 โ   if model_cfg.name not in COMPOSER_MODEL_REGISTRY:                                      โ
โ    68 โ   โ   raise ValueError(                                                                  โ
โ    69 โ   โ   โ   f'Not sure how to build model with name={model_cfg.name}')                     โ
โ โฑ  70 โ   return COMPOSER_MODEL_REGISTRY[model_cfg.name](model_cfg, tokenizer)                   โ
โ    71                                                                                            โ
โ    72                                                                                            โ
โ    73 def build_composer_peft_model(                                                             โ
โ                                                                                                  โ
โ /home/matthias/src/llm-foundry/llmfoundry/models/hf/hf_causal_lm.py:181 in __init__              โ
โ                                                                                                  โ
โ   178 โ   โ   โ   โ   f'om_model_config must be either a DictConfig, PeftModel, or PreTrainedM   โ
โ   179 โ   โ   โ   )                                                                              โ
โ   180 โ   โ                                                                                      โ
โ โฑ 181 โ   โ   composer_model = super().__init__(model=model,                                     โ
โ   182 โ   โ   โ   โ   โ   โ   โ   โ   โ   โ     shift_labels=True,                               โ
โ   183 โ   โ   โ   โ   โ   โ   โ   โ   โ   โ     tokenizer=tokenizer,                             โ
โ   184 โ   โ   โ   โ   โ   โ   โ   โ   โ   โ     metrics=train_metrics,                           โ
โ                                                                                                  โ
โ /home/matthias/src/llm-foundry/llmfoundry/models/hf/model_wrapper.py:65 in __init__              โ
โ                                                                                                  โ
โ    62 โ   โ                                                                                      โ
โ    63 โ   โ   # Note: We need to add the FSDP related attributes to the model AFTER the super    โ
โ    64 โ   โ   # so that the (possible) embedding resizing doesn't destroy them                   โ
โ โฑ  65 โ   โ   prepare_hf_model_for_fsdp(self.model, init_device)                                 โ
โ    66 โ   โ                                                                                      โ
โ    67 โ   โ   # This provides support for meta initialization when using FSDP                    โ
โ    68 โ   โ   self.model.param_init_fn = lambda module: self.model._init_weights(                โ
โ                                                                                                  โ
โ /home/matthias/src/llm-foundry/llmfoundry/models/hf/hf_fsdp.py:118 in prepare_hf_model_for_fsdp  โ
โ                                                                                                  โ
โ   115 โ   else:                                                                                  โ
โ   116 โ   โ   # many common decoder-only model do not set the flag                               โ
โ   117 โ   โ   # model.config.is_decoder, so we can't trust it                                    โ
โ โฑ 118 โ   โ   prepare_hf_causal_lm_model_for_fsdp(model, init_device)                            โ
โ   119                                                                                            โ
โ   120                                                                                            โ
โ   121 def prepare_hf_causal_lm_model_for_fsdp(model: PreTrainedModel,                            โ
โ                                                                                                  โ
โ /home/matthias/src/llm-foundry/llmfoundry/models/hf/hf_fsdp.py:136 in                            โ
โ prepare_hf_causal_lm_model_for_fsdp                                                              โ
โ                                                                                                  โ
โ   133 โ   lm_head = model.get_output_embeddings()                                                โ
โ   134 โ   # some models (OPT) implement .get_input_embeddings for the causal subclass            โ
โ   135 โ   # but all of them implement it for the base model                                      โ
โ โฑ 136 โ   tied_embeddings = causal_base_model.get_input_embeddings()  # type: ignore             โ
โ   137 โ   modules = {                                                                            โ
โ   138 โ   โ   'base_model': causal_base_model,                                                   โ
โ   139 โ   โ   'model_block': model_block,                                                        โ
โ                                                                                                  โ
โ /home/matthias/src/replit-finetune/env/lib/python3.10/site-packages/torch/nn/modules/module.py:1 โ
โ 614 in __getattr__                                                                               โ
โ                                                                                                  โ
โ   1611 โ   โ   โ   modules = self.__dict__['_modules']                                           โ
โ   1612 โ   โ   โ   if name in modules:                                                           โ
โ   1613 โ   โ   โ   โ   return modules[name]                                                      โ
โ โฑ 1614 โ   โ   raise AttributeError("'{}' object has no attribute '{}'".format(                  โ
โ   1615 โ   โ   โ   type(self).__name__, name))                                                   โ
โ   1616 โ                                                                                         โ
โ   1617 โ   def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:             โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
AttributeError: 'ModuleDict' object has no attribute 'get_input_embeddings'