Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -83,56 +83,7 @@ cd monday_morning_moral
|
|
| 83 |
uv sync
|
| 84 |
```
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
```python
|
| 89 |
-
import torch
|
| 90 |
-
import tiktoken
|
| 91 |
-
from models.gpt2 import GPT2
|
| 92 |
-
from generate import generate, text_to_token_ids, token_ids_to_text
|
| 93 |
-
from huggingface_hub import hf_hub_download
|
| 94 |
-
|
| 95 |
-
# Download weights from Hugging Face
|
| 96 |
-
model_path = hf_hub_download(
|
| 97 |
-
repo_id="0rn0/gpt2-30m-tinystories",
|
| 98 |
-
filename="model.safetensors"
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
# Create model with correct config
|
| 102 |
-
model = GPT2(
|
| 103 |
-
dropout_rate=0.1,
|
| 104 |
-
vocab_size=50257,
|
| 105 |
-
context_length=512,
|
| 106 |
-
embedding_dim=384,
|
| 107 |
-
num_layers=6,
|
| 108 |
-
num_heads=6
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
# Load weights
|
| 112 |
-
checkpoint = torch.load(model_path, map_location="cpu")
|
| 113 |
-
if isinstance(checkpoint, dict) and "model_state_dict" in checkpoint:
|
| 114 |
-
model.load_state_dict(checkpoint["model_state_dict"])
|
| 115 |
-
else:
|
| 116 |
-
model.load_state_dict(checkpoint)
|
| 117 |
-
model.eval()
|
| 118 |
-
|
| 119 |
-
# Setup tokenizer
|
| 120 |
-
tokenizer = tiktoken.get_encoding("gpt2")
|
| 121 |
-
|
| 122 |
-
# Generate text
|
| 123 |
-
prompt = "Once upon a time"
|
| 124 |
-
input_ids = text_to_token_ids(prompt, tokenizer)
|
| 125 |
-
output_ids = generate(
|
| 126 |
-
model=model,
|
| 127 |
-
idx=input_ids,
|
| 128 |
-
max_new_tokens=200,
|
| 129 |
-
context_size=512,
|
| 130 |
-
temperature=0.8,
|
| 131 |
-
top_k=40,
|
| 132 |
-
eos_id=50256,
|
| 133 |
-
)
|
| 134 |
-
print(token_ids_to_text(output_ids, tokenizer))
|
| 135 |
-
```
|
| 136 |
|
| 137 |
## Limitations
|
| 138 |
|
|
|
|
| 83 |
uv sync
|
| 84 |
```
|
| 85 |
|
| 86 |
+
See the [GitHub repository](https://github.com/aryandeore/monday_morning_moral) for usage examples and the full API reference.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
## Limitations
|
| 89 |
|