Spaces:
Runtime error
Runtime error
add utils file
Browse files
app.py
CHANGED
@@ -1,10 +1,82 @@
|
|
1 |
import streamlit as st
|
2 |
from utils import memory_moe_mlp, memory_mlp_layer, memory_for_attention_layer
|
3 |
|
4 |
-
st.title("Model Memory Usage Calculator")
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
st.
|
10 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from utils import memory_moe_mlp, memory_mlp_layer, memory_for_attention_layer
|
3 |
|
|
|
4 |
|
5 |
+
def main():
|
6 |
+
st.title("LLM Model Memory Usage Calculator")
|
7 |
|
8 |
+
st.sidebar.header("Model Parameters")
|
9 |
+
precession = st.sidebar.number_input("precession in Byte", min_value=1, max_value=4, value=2, step=2)
|
10 |
+
hidden_size = st.sidebar.number_input("Hidden Size", min_value=512, max_value=2 ** 16, value=4096, step=512)
|
11 |
+
num_heads = st.sidebar.number_input("Number of Attention Heads", min_value=4, max_value=128, value=32, step=4)
|
12 |
+
batch_size = st.sidebar.number_input("Batch Size", min_value=1, max_value=256, value=64, step=4)
|
13 |
+
seq_len = st.sidebar.number_input("Sequence Length", min_value=512, max_value=128000, value=2048, step=512)
|
14 |
+
intermediate_size = st.sidebar.number_input("Intermediate Size", min_value=1024, max_value=2 ** 18, value=11008,
|
15 |
+
step=128)
|
16 |
+
layers = st.sidebar.number_input("Number of Layers", min_value=6, max_value=48, value=30, step=1)
|
17 |
+
moe = st.sidebar.checkbox("Use Mixture of Experts (MOE)", value=False)
|
18 |
+
|
19 |
+
# Conditional rendering for MOE parameters
|
20 |
+
if moe:
|
21 |
+
top_k = st.sidebar.number_input("Number of Experts to use (Top K)", min_value=1, max_value=16, value=2, step=1)
|
22 |
+
num_experts = st.sidebar.number_input("Total Number of Experts", min_value=2, max_value=32, value=4, step=2)
|
23 |
+
else:
|
24 |
+
top_k = 2 # Default values if MOE is not used
|
25 |
+
num_experts = 4
|
26 |
+
|
27 |
+
attention_memory = memory_for_attention_layer(precession,
|
28 |
+
seq_len,
|
29 |
+
batch_size,
|
30 |
+
hidden_size,
|
31 |
+
num_heads)
|
32 |
+
|
33 |
+
dense_mlp_memory = memory_mlp_layer(precession,
|
34 |
+
seq_len,
|
35 |
+
batch_size,
|
36 |
+
hidden_size,
|
37 |
+
intermediate_size)
|
38 |
+
|
39 |
+
dense_model_memory = layers * (attention_memory + dense_mlp_memory) // (1024 ** 3)
|
40 |
+
space = st.empty()
|
41 |
+
space.markdown('<div style="height: 20px;"></div>', unsafe_allow_html=True)
|
42 |
+
|
43 |
+
st.markdown(
|
44 |
+
f'<div style="background-color: #b3f0ff; padding: 30px; border-radius: 5px;">'
|
45 |
+
f'<p style="font-weight: bold;">The memory requirement for this model is ~ {dense_model_memory} GB</p>'
|
46 |
+
f'</div>',
|
47 |
+
unsafe_allow_html=True
|
48 |
+
)
|
49 |
+
space = st.empty()
|
50 |
+
space.markdown('<div style="height: 40px;"></div>', unsafe_allow_html=True)
|
51 |
+
|
52 |
+
if moe:
|
53 |
+
moe_memory = memory_moe_mlp(precession,
|
54 |
+
seq_len,
|
55 |
+
batch_size,
|
56 |
+
hidden_size,
|
57 |
+
intermediate_size,
|
58 |
+
num_experts,
|
59 |
+
top_k)
|
60 |
+
moe_model = layers * (attention_memory + moe_memory) // (1024 ** 3)
|
61 |
+
|
62 |
+
st.markdown(
|
63 |
+
f'<div style="background-color: #99ff99; padding: 30px; border-radius: 5px;">'
|
64 |
+
f'<p style="font-weight: bold;">The memory requirement for the MOE model is ~ {moe_model} GB</p>'
|
65 |
+
f'</div>',
|
66 |
+
unsafe_allow_html=True
|
67 |
+
)
|
68 |
+
|
69 |
+
space = st.empty()
|
70 |
+
space.markdown('<div style="height: 40px;"></div>', unsafe_allow_html=True)
|
71 |
+
|
72 |
+
st.markdown(
|
73 |
+
f'<div style="background-color: #f0f0f0; padding: 30px; border-radius: 5px;">'
|
74 |
+
f'<p style="font-weight: bold;">For more information please read this article</p>'
|
75 |
+
f'<a href="https://medium.com/@khalil.hennara.247/llm-memory-usage-f62a007a509c">Article</a>'
|
76 |
+
f'</div>',
|
77 |
+
unsafe_allow_html=True
|
78 |
+
)
|
79 |
+
|
80 |
+
|
81 |
+
if __name__ == "__main__":
|
82 |
+
main()
|