from transformers import GPT2LMHeadModel, GPT2Tokenizer | |
# Model name to download | |
model_name = "gpt2" | |
# Download the GPT-2 model and tokenizer | |
model = GPT2LMHeadModel.from_pretrained(model_name) | |
tokenizer = GPT2Tokenizer.from_pretrained(model_name) | |
# Save the model and tokenizer files locally | |
model.save_pretrained("./gpt2_model") | |
tokenizer.save_pretrained("./gpt2_tokenizer") | |