Create analyze_model.py
Browse files- analyze_model.py +23 -0
analyze_model.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
def analyze_model(model_path):
|
| 6 |
+
model = AutoModel.from_pretrained(model_path)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 8 |
+
|
| 9 |
+
print("=== Model Architecture ===")
|
| 10 |
+
print(f"Model parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 11 |
+
print(f"Layers: {len(model.encoder.layer) if hasattr(model, 'encoder') else 'N/A'}")
|
| 12 |
+
|
| 13 |
+
# Analyze attention patterns
|
| 14 |
+
if hasattr(model, 'encoder'):
|
| 15 |
+
layer = model.encoder.layer[0]
|
| 16 |
+
print(f"Attention heads: {layer.attention.self.num_attention_heads}")
|
| 17 |
+
|
| 18 |
+
return model, tokenizer
|
| 19 |
+
|
| 20 |
+
def plot_training_metrics(log_file='training.log'):
|
| 21 |
+
# Parse training logs and create plots
|
| 22 |
+
# This would read your training logs and create nice graphs
|
| 23 |
+
pass
|