forked from sleepingcat4/TinyStories
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinystories.py
More file actions
24 lines (18 loc) · 773 Bytes
/
Copy pathtinystories.py
File metadata and controls
24 lines (18 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import GPT2Model, GPT2Config
# Configuring the model for 28M param
# my code implements a 29M but still very close and you can twinker with the hidden layers to get a perfect 28M
# this code provides the method to config a model for 28M
config = GPT2Config(
vocab_size=50257, # Vocabulary size of the GPT-2 model
n_embd=240, # Hidden size of the transformer embeddings
n_layer=10, # Number of transformer layers
n_head=10, # Number of attention heads
n_positions=1024, # Maximum sequence length
)
# creating the model
model = GPT2Model(config)
params = model.state_dict()
# calc the total param
total_params = sum(p.numel() for p in params.values())
# printing the number of params
print("Total Parameters:", total_params)