-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams.py
More file actions
52 lines (41 loc) · 1.59 KB
/
Copy pathparams.py
File metadata and controls
52 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import torch
from minGRU_pytorch.minGRULM import minGRULM
# Model parameters (same as your training script)
num_tokens = 256
dim = 512 * 7
depth = 8
ff_mult = 4
min_gru_expansion = 1.5
conv_kernel_size = 3
# Create the model
model = minGRULM(
num_tokens=num_tokens,
dim=dim,
depth=depth,
ff_mult=ff_mult,
min_gru_expansion=min_gru_expansion,
conv_kernel_size=conv_kernel_size
)
# Calculate total parameters
total_params = sum(p.numel() for p in model.parameters())
print(f"Total number of parameters: {total_params}")
# Calculate approximate size in MB (assuming float32)
size_mb = total_params * 4 / (1024**2) # 4 bytes per float32 parameter
print(f"Approximate size (float32): {size_mb:.2f} MB")
# If you save the model with half-precision (float16), the size would be roughly halved.
size_mb_fp16 = size_mb / 2
print(f"Approximate size (float16): {size_mb_fp16:.2f} MB")
# You can also break down the parameter count per layer/module for more detailed analysis:
def count_parameters(module):
return sum(p.numel() for p in module.parameters())
print("\nParameter breakdown:")
print(f"Embedding: {count_parameters(model.token_emb)}")
for i, layer in enumerate(model.layers):
print(f"Layer {i+1}:")
print(f" Conv: {count_parameters(layer[0])}")
print(f" RMSNorm 1: {count_parameters(layer[1])}")
print(f" minGRU: {count_parameters(layer[2])}")
print(f" RMSNorm 2: {count_parameters(layer[3])}")
print(f" FeedForward: {count_parameters(layer[4])}")
print(f"Final RMSNorm: {count_parameters(model.norm)}")
print(f"Logits Layer: {count_parameters(model.to_logits)}")