Repository: PaddlePaddle/PaddleNLP
Pull request: [BugFix]update vocab_size in init_config
### PR types
Bug fixes

### PR changes
Models

### Description
try to fix: https://github.com/PaddlePaddle/PaddleNLP/issues/3254


Problem statement:
增加special tokens后，save_pretrained保存的model_config，vocab size没有改变
问题：增加special tokens后，进行resize_token_embeddings，save_pretrained保存的model_config，vocab size没有改变，导致from_pretrained的时候，embedding层加载有误，而且没有warning。

版本：PaddleNLP develop

复现代码：
```python
import os
from paddlenlp.transformers import GPTModel, GPTTokenizer

model = GPTModel(**GPTModel.pretrained_init_configuration['gpt2-en'])
print(model.embeddings.word_embeddings.weight.shape) # [50257, 768]

tokenizer = GPTTokenizer.from_pretrained('gpt2-en')
tokenizer.add_tokens(['gongenlei'], True)
print(len(tokenizer)) # 50258

model.resize_token_embeddings(len(tokenizer))
print(model.embeddings.word_embeddings.weight.shape) # [50258, 768]

model.save_pretrained('test')
os.system('cat test/model_config.json')
```
HF没有此问题

Hints from issue discussion:
## 问题分析

此问题源于`resize_token_embeddings`中对于`vocab_size`信息的修改是基于[`config`](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/paddlenlp/transformers/model_utils.py#L130)，可是系统当中还存储的有：[`init_config`](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/paddlenlp/transformers/utils.py#L163). 

在模型`save_pretrained`的时候是针对于`init_config`进行保存，所以就导致了保存结果不一致的问题。

其实init_config此信息是需要进行删除的，且在整个项目中的引用只有21处，都可以调整成: `self.base_model.config`

Commit message: update vocab_size in init_config

Patch to review:
diff --git a/paddlenlp/transformers/model_utils.py b/paddlenlp/transformers/model_utils.py
index db5c57cc79bf..11ea3f559774 100644
--- a/paddlenlp/transformers/model_utils.py
+++ b/paddlenlp/transformers/model_utils.py
@@ -546,6 +546,20 @@ def resize_token_embeddings(self,
         self.base_model.config['vocab_size'] = new_num_tokens
         self.vocab_size = new_num_tokens
 
+        # update init_config
+        def update_init_config_vocab_size_field(sub_dict: dict):
+            if 'vocab_size' in sub_dict:
+                sub_dict['vocab_size'] = new_num_tokens
+                return
+            models = [
+                arg for arg in sub_dict.get('init_args', [])
+                if isinstance(arg, PretrainedModel)
+            ]
+            if models:
+                update_init_config_vocab_size_field(models[0].init_config)
+
+        update_init_config_vocab_size_field(self.init_config)
+
         # TODO(westfish@126.com): add tie_weight.
         # TODO(westfish) Add tie_weight to tie the weights between the input embeddings and the output embeddings if needed.
 


Code review comments:
diff_hunk: @@ -546,6 +546,20 @@ def resize_token_embeddings(self,
         self.base_model.config['vocab_size'] = new_num_tokens
         self.vocab_size = new_num_tokens
 
+        # update init_config
+        def update_init_config_vocab_size_field(sub_dict: dict):
+            if 'vocab_size' in sub_dict:
+                sub_dict['vocab_size'] = new_num_tokens
+                return
+            models = [
+                arg for arg in sub_dict.get('init_args', [])
+                if isinstance(arg, PretrainedModel)
+            ]
+            if models:
+                update_init_config_vocab_size_field(models[0].init_config)
+
+        update_init_config_vocab_size_field(self.init_config)
+
path: paddlenlp/transformers/model_utils.py
text: @author:
我们貌似也可以把这个方法提出来，做成一个通用的函数，这样就可以修改其他字段了。