Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def plot_forecast(num_param,
|
| 8 |
# Convert number (input as B)
|
| 9 |
num_param = float(num_param) * 1e9
|
| 10 |
|
|
@@ -12,21 +10,20 @@ def plot_forecast(num_param, batch_size, precision, seq_len):
|
|
| 12 |
precision = {"float32": 4, "float16": 2, "bfloat16": 2}[precision]
|
| 13 |
|
| 14 |
# Model Parameters: N×precision
|
| 15 |
-
y1 = num_param * precision /
|
| 16 |
|
| 17 |
# Optimizer States: 2×N×precision
|
| 18 |
-
y2 = 2 * num_param * precision /
|
| 19 |
|
| 20 |
# Activations: B×Sequence Length×K×precision
|
| 21 |
K = 4.6894e-4 * num_param + 1.8494e6
|
| 22 |
-
|
| 23 |
-
y3 = batch_size * seq_len * K * precision / (1000**3)
|
| 24 |
|
| 25 |
# Gradients: N×precision
|
| 26 |
-
y4 = num_param * precision /
|
| 27 |
|
| 28 |
# Optimizer intermediates: N×precision
|
| 29 |
-
y5 = num_param * precision /
|
| 30 |
|
| 31 |
# Calculate total memory
|
| 32 |
total_memory = y1 + y2 + max(y3, y4 + y5)
|
|
@@ -44,10 +41,36 @@ def plot_forecast(num_param, batch_size, precision, seq_len):
|
|
| 44 |
|
| 45 |
# Add text labels inside the bars
|
| 46 |
ax.text(0, y1 / 2, f"Model Parameters ({y1:.1f} GB)", ha="center", va="center", color="white", fontweight="bold")
|
| 47 |
-
ax.text(
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
ax.text(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Or as title
|
| 53 |
ax.set_title(f"Total Memory: {total_memory:.1f} GB", fontweight="bold")
|
|
@@ -66,10 +89,10 @@ def plot_forecast(num_param, batch_size, precision, seq_len):
|
|
| 66 |
demo = gr.Interface(
|
| 67 |
plot_forecast,
|
| 68 |
[
|
| 69 |
-
gr.Number(
|
| 70 |
-
gr.Radio([1, 2, 4, 8, 16, 32, 64, 128], value=8, label="Batch size"),
|
| 71 |
gr.Radio(["float32", "float16", "bfloat16"], value="float32", label="Precision"),
|
| 72 |
-
gr.Slider(1,
|
|
|
|
| 73 |
],
|
| 74 |
gr.Plot(label="forecast", format="png"),
|
| 75 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def plot_forecast(num_param, precision, batch_size, seq_len):
|
| 6 |
# Convert number (input as B)
|
| 7 |
num_param = float(num_param) * 1e9
|
| 8 |
|
|
|
|
| 10 |
precision = {"float32": 4, "float16": 2, "bfloat16": 2}[precision]
|
| 11 |
|
| 12 |
# Model Parameters: N×precision
|
| 13 |
+
y1 = num_param * precision / 1e9
|
| 14 |
|
| 15 |
# Optimizer States: 2×N×precision
|
| 16 |
+
y2 = 2 * num_param * precision / 1e9
|
| 17 |
|
| 18 |
# Activations: B×Sequence Length×K×precision
|
| 19 |
K = 4.6894e-4 * num_param + 1.8494e6
|
| 20 |
+
y3 = batch_size * seq_len * K * precision / 1e9
|
|
|
|
| 21 |
|
| 22 |
# Gradients: N×precision
|
| 23 |
+
y4 = num_param * precision / 1e9
|
| 24 |
|
| 25 |
# Optimizer intermediates: N×precision
|
| 26 |
+
y5 = num_param * precision / 1e9
|
| 27 |
|
| 28 |
# Calculate total memory
|
| 29 |
total_memory = y1 + y2 + max(y3, y4 + y5)
|
|
|
|
| 41 |
|
| 42 |
# Add text labels inside the bars
|
| 43 |
ax.text(0, y1 / 2, f"Model Parameters ({y1:.1f} GB)", ha="center", va="center", color="white", fontweight="bold")
|
| 44 |
+
ax.text(
|
| 45 |
+
0, y1 + y2 / 2, f"Optimizer States ({y2:.1f} GB)", ha="center", va="center", color="white", fontweight="bold"
|
| 46 |
+
)
|
| 47 |
+
ax.text(
|
| 48 |
+
-bar_width / 4,
|
| 49 |
+
y1 + y2 + y3 / 2,
|
| 50 |
+
f"Activations\n({y3:.1f} GB)",
|
| 51 |
+
ha="center",
|
| 52 |
+
va="center",
|
| 53 |
+
color="white",
|
| 54 |
+
fontweight="bold",
|
| 55 |
+
)
|
| 56 |
+
ax.text(
|
| 57 |
+
bar_width / 4,
|
| 58 |
+
y1 + y2 + y4 / 2,
|
| 59 |
+
f"Gradients\n({y4:.1f} GB)",
|
| 60 |
+
ha="center",
|
| 61 |
+
va="center",
|
| 62 |
+
color="white",
|
| 63 |
+
fontweight="bold",
|
| 64 |
+
)
|
| 65 |
+
ax.text(
|
| 66 |
+
bar_width / 4,
|
| 67 |
+
y1 + y2 + y4 + y5 / 2,
|
| 68 |
+
f"Optimizer\nintermediates\n({y5:.1f} GB)",
|
| 69 |
+
ha="center",
|
| 70 |
+
va="center",
|
| 71 |
+
color="white",
|
| 72 |
+
fontweight="bold",
|
| 73 |
+
)
|
| 74 |
|
| 75 |
# Or as title
|
| 76 |
ax.set_title(f"Total Memory: {total_memory:.1f} GB", fontweight="bold")
|
|
|
|
| 89 |
demo = gr.Interface(
|
| 90 |
plot_forecast,
|
| 91 |
[
|
| 92 |
+
gr.Number(3, label="Number of parameters (B)"),
|
|
|
|
| 93 |
gr.Radio(["float32", "float16", "bfloat16"], value="float32", label="Precision"),
|
| 94 |
+
gr.Slider(1, 128, label="Batch size", step=1, value=8),
|
| 95 |
+
gr.Slider(1, 1000, label="Sequence Length", step=1, value=256),
|
| 96 |
],
|
| 97 |
gr.Plot(label="forecast", format="png"),
|
| 98 |
)
|