Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModel
|
3 |
+
import torch
|
4 |
+
|
5 |
+
def count_parameters(model_path):
|
6 |
+
try:
|
7 |
+
# Load model on CPU
|
8 |
+
model = AutoModel.from_pretrained(model_path, device_map="cpu")
|
9 |
+
|
10 |
+
# Count trainable parameters
|
11 |
+
trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
|
12 |
+
|
13 |
+
# Count total parameters
|
14 |
+
total_params = sum(p.numel() for p in model.parameters())
|
15 |
+
|
16 |
+
# Format numbers with commas for readability
|
17 |
+
return f"""
|
18 |
+
Total Parameters: {total_params:,}
|
19 |
+
Trainable Parameters: {trainable_params:,}
|
20 |
+
"""
|
21 |
+
except Exception as e:
|
22 |
+
return f"Error loading model: {str(e)}"
|
23 |
+
|
24 |
+
# Create Gradio interface
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=count_parameters,
|
27 |
+
inputs=gr.Textbox(
|
28 |
+
label="Enter Hugging Face Model Path",
|
29 |
+
placeholder="e.g., bert-base-uncased"
|
30 |
+
),
|
31 |
+
outputs=gr.Textbox(label="Parameter Count"),
|
32 |
+
title="Hugging Face Model Parameter Counter",
|
33 |
+
description="Enter a Hugging Face model path to see its parameter count.",
|
34 |
+
examples=[
|
35 |
+
["bert-base-uncased"],
|
36 |
+
["gpt2"],
|
37 |
+
["roberta-base"]
|
38 |
+
]
|
39 |
+
)
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch()
|