|
import os |
|
import torch |
|
from transformers import BertTokenizer, BertModel, GPT2Tokenizer, GPTNeoForCausalLM |
|
|
|
|
|
print(f"Current Working Directory: {os.getcwd()}") |
|
|
|
|
|
import chat_with_tars |
|
print(f"chat_with_tars file path: {chat_with_tars.__file__}") |
|
|
|
def patch_pad_token(model_name, tokenizer_class, model_class): |
|
print(f"π Loading tokenizer and model: {model_name}...") |
|
tokenizer = tokenizer_class.from_pretrained(model_name) |
|
model = model_class.from_pretrained(model_name) |
|
|
|
|
|
print(f"Tokenizer Configuration: {tokenizer}") |
|
print(f"Model Configuration: {model.config}") |
|
|
|
|
|
tokenizer.add_special_tokens({'pad_token': '[PAD]'}) |
|
model.resize_token_embeddings(len(tokenizer)) |
|
|
|
|
|
print(f"New Vocabulary Size: {len(tokenizer)}") |
|
|
|
|
|
model.save_pretrained(model_name) |
|
tokenizer.save_pretrained(model_name) |
|
|
|
print("β
Padding token added and model resized.") |
|
print("β
Model saved with padding token patched.") |
|
|
|
if __name__ == "__main__": |
|
|
|
gpt_model_name = 'EleutherAI/gpt-neo-125M' |
|
patch_pad_token(gpt_model_name, GPT2Tokenizer, GPTNeoForCausalLM) |
|
|
|
|
|
bert_model_name = 'bert-base-uncased' |
|
patch_pad_token(bert_model_name, BertTokenizer, BertModel) |