CoLLiE icon indicating copy to clipboard operation
CoLLiE copied to clipboard

llama-2-7b拓展词表报错

Open skepsun opened this issue 11 months ago • 4 comments

用的dev分支,examples/further_pretrain_llama里的脚本,运行指令是

torchrun --rdzv_backend=c10d --rdzv_endpoint=localhost:29402 --nnodes=1 --nproc_per_node=8 expand_vocab.py 

只修改了llama的路径,包括config、tokenizer和model.from_pretrained。报错如下:

╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:85 in <module>   │
│                                                                                           │
│    82 │   model.get_input_embedding()[1].weight.requires_grad = True                      │
│    83 if model.get_lm_head()[1] is not None:                                              │
│    84 │   model.get_lm_head()[1].weight.requires_grad = True                              │
│ ❱  85 optimizer = torch.optim.AdamW(                                                      │
│    86 │   filter(lambda p: p.requires_grad, model.parameters()), lr=2e-4)                 │
│    87 lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(                          │
│    88 │   optimizer, T_max=config.train_epochs * len(train_dataset), eta_min=0)           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/adamw.py:50 in __init__  │
│                                                                                           │
│    47 │   │   │   differentiable=differentiable,                                          │
│    48 │   │   │   fused=fused,                                                            │
│    49 │   │   )                                                                           │
│ ❱  50 │   │   super().__init__(params, defaults)                                          │
│    51 │   │                                                                               │
│    52 │   │   if fused:                                                                   │
│    53 │   │   │   if differentiable:                                                      │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/optimizer.py:187 in      │
│ __init__                                                                                  │
│                                                                                           │
│   184 │   │                                                                               │
│   185 │   │   param_groups = list(params)                                                 │
│   186 │   │   if len(param_groups) == 0:                                                  │
│ ❱ 187 │   │   │   raise ValueError("optimizer got an empty parameter list")               │
│   188 │   │   if not isinstance(param_groups[0], dict):                                   │
│   189 │   │   │   param_groups = [{'params': param_groups}]                               │
│   190                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: optimizer got an empty parameter list
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:85 in <module>   │
│                                                                                           │
│    82 │   model.get_input_embedding()[1].weight.requires_grad = True                      │
│    83 if model.get_lm_head()[1] is not None:                                              │
│    84 │   model.get_lm_head()[1].weight.requires_grad = True                              │
│ ❱  85 optimizer = torch.optim.AdamW(                                                      │
│    86 │   filter(lambda p: p.requires_grad, model.parameters()), lr=2e-4)                 │
│    87 lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(                          │
│    88 │   optimizer, T_max=config.train_epochs * len(train_dataset), eta_min=0)           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/adamw.py:50 in __init__  │
│                                                                                           │
│    47 │   │   │   differentiable=differentiable,                                          │
│    48 │   │   │   fused=fused,                                                            │
│    49 │   │   )                                                                           │
│ ❱  50 │   │   super().__init__(params, defaults)                                          │
│    51 │   │                                                                               │
│    52 │   │   if fused:                                                                   │
│    53 │   │   │   if differentiable:                                                      │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/optimizer.py:187 in      │
│ __init__                                                                                  │
│                                                                                           │
│   184 │   │                                                                               │
│   185 │   │   param_groups = list(params)                                                 │
│   186 │   │   if len(param_groups) == 0:                                                  │
│ ❱ 187 │   │   │   raise ValueError("optimizer got an empty parameter list")               │
│   188 │   │   if not isinstance(param_groups[0], dict):                                   │
│   189 │   │   │   param_groups = [{'params': param_groups}]                               │
│   190                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: optimizer got an empty parameter list
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:77 in <module>   │
│                                                                                           │
│    74 # 准备模型并调整 embedding 层大小,设置只训练 embedding 和 lm_head 层,加速收敛     │
│    75 model = LlamaForCausalLM.from_pretrained(                                           │
│    76 │   "../../../llama-2-7b", config=config)                                           │
│ ❱  77 model.resize_token_embeddings(len(llama_tokenizer) + 7)  # 取个整                   │
│    78 for p in model.parameters():                                                        │
│    79 │   p.requires_grad = False                                                         │
│    80 # 因为 embedding 和 lm_head 在 pipeline 的情况下被分割到了不同的进程,所以要判断一  │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/models/base.py:634 in         │
│ resize_token_embeddings                                                                   │
│                                                                                           │
│   631 │   │   │   │   │   │   = lm_head.bias.data[start_pos_old:end_pos_old]              │
│   632 │   │   │   │   if end_pos_new < (new_num_tokens // env.tp_size):                   │
│   633 │   │   │   │   │   initization_method = self.collie_config.initization_method      │
│ ❱ 634 │   │   │   │   │   if self.collie_config.initization_method_params is not None:    │
│   635 │   │   │   │   │   │   initization_method = initization_method(new_lm_head.weight[ │
│   636 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   **self.collie_confi │
│   637 │   │   │   │   │   │   if lm_head.bias is not None:                                │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/config.py:206 in __getattr__  │
│                                                                                           │
│   203 │   │   self.model_config.save_pretrained(path)                                     │
│   204 │                                                                                   │
│   205 │   def __getattr__(self, name):                                                    │
│ ❱ 206 │   │   return getattr(self.model_config, name)                                     │
│   207 │                                                                                   │
│   208 │   def __setattr__(self, name: str, value: Any) -> None:                           │
│   209 │   │   if name in self.__annotations__.keys():                                     │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/transformers/configuration_utils.py: │
│ 261 in __getattribute__                                                                   │
│                                                                                           │
│   258 │   def __getattribute__(self, key):                                                │
│   259 │   │   if key != "attribute_map" and key in super().__getattribute__("attribute_ma │
│   260 │   │   │   key = super().__getattribute__("attribute_map")[key]                    │
│ ❱ 261 │   │   return super().__getattribute__(key)                                        │
│   262 │                                                                                   │
│   263 │   def __init__(self, **kwargs):                                                   │
│   264 │   │   # Attributes with defaults                                                  │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'LlamaConfig' object has no attribute 'initization_method_params'
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:77 in <module>   │
│                                                                                           │
│    74 # 准备模型并调整 embedding 层大小,设置只训练 embedding 和 lm_head 层,加速收敛     │
│    75 model = LlamaForCausalLM.from_pretrained(                                           │
│    76 │   "../../../llama-2-7b", config=config)                                           │
│ ❱  77 model.resize_token_embeddings(len(llama_tokenizer) + 7)  # 取个整                   │
│    78 for p in model.parameters():                                                        │
│    79 │   p.requires_grad = False                                                         │
│    80 # 因为 embedding 和 lm_head 在 pipeline 的情况下被分割到了不同的进程,所以要判断一  │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/models/base.py:634 in         │
│ resize_token_embeddings                                                                   │
│                                                                                           │
│   631 │   │   │   │   │   │   = lm_head.bias.data[start_pos_old:end_pos_old]              │
│   632 │   │   │   │   if end_pos_new < (new_num_tokens // env.tp_size):                   │
│   633 │   │   │   │   │   initization_method = self.collie_config.initization_method      │
│ ❱ 634 │   │   │   │   │   if self.collie_config.initization_method_params is not None:    │
│   635 │   │   │   │   │   │   initization_method = initization_method(new_lm_head.weight[ │
│   636 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   **self.collie_confi │
│   637 │   │   │   │   │   │   if lm_head.bias is not None:                                │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/config.py:206 in __getattr__  │
│                                                                                           │
│   203 │   │   self.model_config.save_pretrained(path)                                     │
│   204 │                                                                                   │
│   205 │   def __getattr__(self, name):                                                    │
│ ❱ 206 │   │   return getattr(self.model_config, name)                                     │
│   207 │                                                                                   │
│   208 │   def __setattr__(self, name: str, value: Any) -> None:                           │
│   209 │   │   if name in self.__annotations__.keys():                                     │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/transformers/configuration_utils.py: │
│ 261 in __getattribute__                                                                   │
│                                                                                           │
│   258 │   def __getattribute__(self, key):                                                │
│   259 │   │   if key != "attribute_map" and key in super().__getattribute__("attribute_ma │
│   260 │   │   │   key = super().__getattribute__("attribute_map")[key]                    │
│ ❱ 261 │   │   return super().__getattribute__(key)                                        │
│   262 │                                                                                   │
│   263 │   def __init__(self, **kwargs):                                                   │
│   264 │   │   # Attributes with defaults                                                  │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'LlamaConfig' object has no attribute 'initization_method_params'
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:85 in <module>   │
│                                                                                           │
│    82 │   model.get_input_embedding()[1].weight.requires_grad = True                      │
│    83 if model.get_lm_head()[1] is not None:                                              │
│    84 │   model.get_lm_head()[1].weight.requires_grad = True                              │
│ ❱  85 optimizer = torch.optim.AdamW(                                                      │
│    86 │   filter(lambda p: p.requires_grad, model.parameters()), lr=2e-4)                 │
│    87 lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(                          │
│    88 │   optimizer, T_max=config.train_epochs * len(train_dataset), eta_min=0)           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/adamw.py:50 in __init__  │
│                                                                                           │
│    47 │   │   │   differentiable=differentiable,                                          │
│    48 │   │   │   fused=fused,                                                            │
│    49 │   │   )                                                                           │
│ ❱  50 │   │   super().__init__(params, defaults)                                          │
│    51 │   │                                                                               │
│    52 │   │   if fused:                                                                   │
│    53 │   │   │   if differentiable:                                                      │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/optimizer.py:187 in      │
│ __init__                                                                                  │
│                                                                                           │
│   184 │   │                                                                               │
│   185 │   │   param_groups = list(params)                                                 │
│   186 │   │   if len(param_groups) == 0:                                                  │
│ ❱ 187 │   │   │   raise ValueError("optimizer got an empty parameter list")               │
│   188 │   │   if not isinstance(param_groups[0], dict):                                   │
│   189 │   │   │   param_groups = [{'params': param_groups}]                               │
│   190                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: optimizer got an empty parameter list
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:85 in <module>   │
│                                                                                           │
│    82 │   model.get_input_embedding()[1].weight.requires_grad = True                      │
│    83 if model.get_lm_head()[1] is not None:                                              │
│    84 │   model.get_lm_head()[1].weight.requires_grad = True                              │
│ ❱  85 optimizer = torch.optim.AdamW(                                                      │
│    86 │   filter(lambda p: p.requires_grad, model.parameters()), lr=2e-4)                 │
│    87 lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(                          │
│    88 │   optimizer, T_max=config.train_epochs * len(train_dataset), eta_min=0)           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/adamw.py:50 in __init__  │
│                                                                                           │
│    47 │   │   │   differentiable=differentiable,                                          │
│    48 │   │   │   fused=fused,                                                            │
│    49 │   │   )                                                                           │
│ ❱  50 │   │   super().__init__(params, defaults)                                          │
│    51 │   │                                                                               │
│    52 │   │   if fused:                                                                   │
│    53 │   │   │   if differentiable:                                                      │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/torch/optim/optimizer.py:187 in      │
│ __init__                                                                                  │
│                                                                                           │
│   184 │   │                                                                               │
│   185 │   │   param_groups = list(params)                                                 │
│   186 │   │   if len(param_groups) == 0:                                                  │
│ ❱ 187 │   │   │   raise ValueError("optimizer got an empty parameter list")               │
│   188 │   │   if not isinstance(param_groups[0], dict):                                   │
│   189 │   │   │   param_groups = [{'params': param_groups}]                               │
│   190                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: optimizer got an empty parameter list
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:77 in <module>   │
│                                                                                           │
│    74 # 准备模型并调整 embedding 层大小,设置只训练 embedding 和 lm_head 层,加速收敛     │
│    75 model = LlamaForCausalLM.from_pretrained(                                           │
│    76 │   "../../../llama-2-7b", config=config)                                           │
│ ❱  77 model.resize_token_embeddings(len(llama_tokenizer) + 7)  # 取个整                   │
│    78 for p in model.parameters():                                                        │
│    79 │   p.requires_grad = False                                                         │
│    80 # 因为 embedding 和 lm_head 在 pipeline 的情况下被分割到了不同的进程,所以要判断一  │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/models/base.py:548 in         │
│ resize_token_embeddings                                                                   │
│                                                                                           │
│   545 │   │   │   │   │   = embedding.weight.data[start_pos_old:end_pos_old, :]           │
│   546 │   │   │   │   if end_pos_new < (new_num_tokens // env.tp_size):                   │
│   547 │   │   │   │   │   initization_method = self.collie_config.initization_method      │
│ ❱ 548 │   │   │   │   │   if self.collie_config.initization_method_params is not None:    │
│   549 │   │   │   │   │   │   initization_method = initization_method(new_embedding.weigh │
│   550 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   **self.collie_confi │
│   551 │   │   │   │   │   else:                                                           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/config.py:206 in __getattr__  │
│                                                                                           │
│   203 │   │   self.model_config.save_pretrained(path)                                     │
│   204 │                                                                                   │
│   205 │   def __getattr__(self, name):                                                    │
│ ❱ 206 │   │   return getattr(self.model_config, name)                                     │
│   207 │                                                                                   │
│   208 │   def __setattr__(self, name: str, value: Any) -> None:                           │
│   209 │   │   if name in self.__annotations__.keys():                                     │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/transformers/configuration_utils.py: │
│ 261 in __getattribute__                                                                   │
│                                                                                           │
│   258 │   def __getattribute__(self, key):                                                │
│   259 │   │   if key != "attribute_map" and key in super().__getattribute__("attribute_ma │
│   260 │   │   │   key = super().__getattribute__("attribute_map")[key]                    │
│ ❱ 261 │   │   return super().__getattribute__(key)                                        │
│   262 │                                                                                   │
│   263 │   def __init__(self, **kwargs):                                                   │
│   264 │   │   # Attributes with defaults                                                  │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'LlamaConfig' object has no attribute 'initization_method_params'
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
│ /d2/data/chuxiong/collie/examples/further_pretrain_llama/expand_vocab.py:77 in <module>   │
│                                                                                           │
│    74 # 准备模型并调整 embedding 层大小,设置只训练 embedding 和 lm_head 层,加速收敛     │
│    75 model = LlamaForCausalLM.from_pretrained(                                           │
│    76 │   "../../../llama-2-7b", config=config)                                           │
│ ❱  77 model.resize_token_embeddings(len(llama_tokenizer) + 7)  # 取个整                   │
│    78 for p in model.parameters():                                                        │
│    79 │   p.requires_grad = False                                                         │
│    80 # 因为 embedding 和 lm_head 在 pipeline 的情况下被分割到了不同的进程,所以要判断一  │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/models/base.py:548 in         │
│ resize_token_embeddings                                                                   │
│                                                                                           │
│   545 │   │   │   │   │   = embedding.weight.data[start_pos_old:end_pos_old, :]           │
│   546 │   │   │   │   if end_pos_new < (new_num_tokens // env.tp_size):                   │
│   547 │   │   │   │   │   initization_method = self.collie_config.initization_method      │
│ ❱ 548 │   │   │   │   │   if self.collie_config.initization_method_params is not None:    │
│   549 │   │   │   │   │   │   initization_method = initization_method(new_embedding.weigh │
│   550 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   **self.collie_confi │
│   551 │   │   │   │   │   else:                                                           │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/collie/config.py:206 in __getattr__  │
│                                                                                           │
│   203 │   │   self.model_config.save_pretrained(path)                                     │
│   204 │                                                                                   │
│   205 │   def __getattr__(self, name):                                                    │
│ ❱ 206 │   │   return getattr(self.model_config, name)                                     │
│   207 │                                                                                   │
│   208 │   def __setattr__(self, name: str, value: Any) -> None:                           │
│   209 │   │   if name in self.__annotations__.keys():                                     │
│                                                                                           │
│ /d1/conda3/envs/scx_llm/lib/python3.10/site-packages/transformers/configuration_utils.py: │
│ 261 in __getattribute__                                                                   │
│                                                                                           │
│   258 │   def __getattribute__(self, key):                                                │
│   259 │   │   if key != "attribute_map" and key in super().__getattribute__("attribute_ma │
│   260 │   │   │   key = super().__getattribute__("attribute_map")[key]                    │
│ ❱ 261 │   │   return super().__getattribute__(key)                                        │
│   262 │                                                                                   │
│   263 │   def __init__(self, **kwargs):                                                   │
│   264 │   │   # Attributes with defaults                                                  │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'LlamaConfig' object has no attribute 'initization_method_params'

skepsun avatar Jul 19 '23 16:07 skepsun