0rn0 commited on
Commit
7d126df
·
verified ·
1 Parent(s): 1568d7c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +1 -50
README.md CHANGED
@@ -70,56 +70,7 @@ cd monday_morning_moral
70
  uv sync
71
  ```
72
 
73
- ### Loading and Generating
74
-
75
- ```python
76
- import torch
77
- import tiktoken
78
- from models.gpt2 import GPT2
79
- from generate import generate, text_to_token_ids, token_ids_to_text
80
- from huggingface_hub import hf_hub_download
81
-
82
- # Download weights from Hugging Face
83
- model_path = hf_hub_download(
84
- repo_id="0rn0/gpt2-125m-tinystories",
85
- filename="model.safetensors"
86
- )
87
-
88
- # Create model with correct config
89
- model = GPT2(
90
- dropout_rate=0.1,
91
- vocab_size=50257,
92
- context_length=512,
93
- embedding_dim=768,
94
- num_layers=12,
95
- num_heads=12
96
- )
97
-
98
- # Load weights
99
- checkpoint = torch.load(model_path, map_location="cpu")
100
- if isinstance(checkpoint, dict) and "model_state_dict" in checkpoint:
101
- model.load_state_dict(checkpoint["model_state_dict"])
102
- else:
103
- model.load_state_dict(checkpoint)
104
- model.eval()
105
-
106
- # Setup tokenizer
107
- tokenizer = tiktoken.get_encoding("gpt2")
108
-
109
- # Generate text
110
- prompt = "Once upon a time"
111
- input_ids = text_to_token_ids(prompt, tokenizer)
112
- output_ids = generate(
113
- model=model,
114
- idx=input_ids,
115
- max_new_tokens=200,
116
- context_size=512,
117
- temperature=0.8,
118
- top_k=40,
119
- eos_id=50256,
120
- )
121
- print(token_ids_to_text(output_ids, tokenizer))
122
- ```
123
 
124
  ## Limitations
125
 
 
70
  uv sync
71
  ```
72
 
73
+ See the [GitHub repository](https://github.com/aryandeore/monday_morning_moral) for usage examples and the full API reference.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  ## Limitations
76