Refer to
https://github.com/VJyzCELERY/GPT2-StoryGenerator for the model source
To use the model simply do :
1import torch
2from src.model import Config,GPT
3from src.inference import GPTInfer
4from huggingface_hub import hf_hub_download
5model_path = hf_hub_download(
6 repo_id="VJyzCELERY/GPT2-GutenbergStoryGenerator",
7 filename="GPT2-GutenbergStoryGenerator.pt"
8)
9checkpoint = torch.load(model_path, weights_only=False)
10model = GPT(config=checkpoint['config'])
11model.load_state_dict(checkpoint['model'])
12model = model.to(device)
13token_encoder = tiktoken.get_encoding('gpt2')
14generator = GPTInfer(model, token_encoder, device)