Spaces:
Runtime error
Runtime error
Commit
·
a6d7fbc
1
Parent(s):
b31a1d5
Update app.py
Browse files
app.py
CHANGED
|
@@ -117,93 +117,92 @@ for i in range(n_start, n):
|
|
| 117 |
|
| 118 |
st.write("Multi-Head Attention: " + str(mha_total_time))
|
| 119 |
st.write("Multi-Query Attention: " + str(mqa_total_time))
|
|
|
|
| 120 |
|
| 121 |
-
st.header(
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
st.caption("Multi-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
c1, c2 = st.columns([2, 3])
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
st.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
st.
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
st.caption("Multi-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
c1, c2 = st.columns([2, 3])
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
st.
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
st.caption("Multi-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
c1, c2 = st.columns([2, 3])
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
st.
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
c1, c2 = st.columns([2, 3])
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
st.subheader('
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
st.
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
st.
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
c1, c2
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
st.subheader('
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
c1, c2 = st.columns([2, 3])
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
st.subheader('
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
st.
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
st.write("MHA exec time (ms): " + str(mha_total_time))
|
| 209 |
-
st.write("MQA exec time (ms): " + str(mqa_total_time))
|
|
|
|
| 117 |
|
| 118 |
st.write("Multi-Head Attention: " + str(mha_total_time))
|
| 119 |
st.write("Multi-Query Attention: " + str(mqa_total_time))
|
| 120 |
+
st.write("Speed-up MQA over MHA: " + str(mha_total_time/mqa_total_time))
|
| 121 |
|
| 122 |
+
st.header("Memory consumption")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
breakdown = st.checkbox("Show breakdown per layer")
|
| 127 |
+
if breakdown:
|
| 128 |
+
st.header('Attention layer')
|
| 129 |
+
|
| 130 |
+
st.subheader('QKV projection')
|
| 131 |
+
st.caption("Multi-Head Attention")
|
| 132 |
+
mha_flop = 2*bs*1*d*3*d
|
| 133 |
+
mha_bytes = 2*bs*1*d + 2*3*d*d + 2*bs*1*3*d
|
| 134 |
+
c1, c2 = st.columns([2, 3])
|
| 135 |
+
qkv_mha_time = print_kernel_execution(c1, c2, mha_flop, mha_bytes)
|
| 136 |
+
|
| 137 |
+
st.caption("Multi-Query Attention")
|
| 138 |
+
mqa_flop = 2*bs*1*d*(1+2/h)*d
|
| 139 |
+
mqa_bytes = 2*bs*1*d + 2*(2/h)*d*d + 2*bs*1*(2/h)*d
|
| 140 |
+
c1, c2 = st.columns([2, 3])
|
| 141 |
+
qkv_mqa_time = print_kernel_execution(c1, c2, mqa_flop, mqa_bytes)
|
| 142 |
+
|
| 143 |
+
st.subheader('QK gemm')
|
| 144 |
+
st.write("Note that calculation depends on sequence length (n)")
|
| 145 |
+
|
| 146 |
+
st.caption("Multi-Head Attention")
|
| 147 |
+
mha_flop = 2*bs*h*(d/h)*n
|
| 148 |
+
mha_bytes = 2*bs*h*(d/h) + 2*bs*h*n*(d/h) + 2*bs*h*n
|
| 149 |
+
c1, c2 = st.columns([2, 3])
|
| 150 |
+
att1_mha_time = print_kernel_execution(c1, c2, mha_flop, mha_bytes)
|
| 151 |
+
|
| 152 |
+
st.caption("Multi-Query Attention")
|
| 153 |
+
mqa_flop = 2*bs*h*(d/h)*n
|
| 154 |
+
mqa_bytes = 2*bs*h*(d/h) + 2*bs*n*(d/h) + 2*bs*h*n
|
| 155 |
+
c1, c2 = st.columns([2, 3])
|
| 156 |
+
att1_mqa_time = print_kernel_execution(c1, c2, mqa_flop, mqa_bytes)
|
| 157 |
+
|
| 158 |
+
st.subheader('Attention-value gemm')
|
| 159 |
+
st.write("Calculation depends on sequence length. We show numbers for maximum sequence length n.")
|
| 160 |
+
st.caption("Multi-Head Attention")
|
| 161 |
+
mha_flop = 2*bs*h*n*(d/h)
|
| 162 |
+
mha_bytes = 2*bs*h*n + 2*bs*h*n*(d/h) + 2*bs*h*(d/h)
|
| 163 |
+
c1, c2 = st.columns([2, 3])
|
| 164 |
+
att2_mha_time = print_kernel_execution(c1, c2, mha_flop, mha_bytes)
|
| 165 |
+
|
| 166 |
+
st.caption("Multi-Query Attention")
|
| 167 |
+
mqa_flop = 2*bs*h*n*(d/h)
|
| 168 |
+
mqa_bytes = 2*bs*n*(d/h) + 2*bs*n*(d/h) + 2*bs*h*(d/h)
|
| 169 |
+
c1, c2 = st.columns([2, 3])
|
| 170 |
+
att2_mqa_time = print_kernel_execution(c1, c2, mqa_flop, mqa_bytes)
|
| 171 |
+
|
| 172 |
+
st.subheader('Output projection')
|
| 173 |
+
out_flop = 2*bs*1*d*d
|
| 174 |
+
out_bytes = 2*bs*1*d + 2*d*d + 2*bs*1*d
|
| 175 |
+
c1, c2 = st.columns([2, 3])
|
| 176 |
+
out_time = print_kernel_execution(c1, c2, out_flop, out_bytes)
|
| 177 |
+
|
| 178 |
+
st.subheader('Element-wise ops')
|
| 179 |
+
st.write("We also need to take into the softmax layer, layer norm, and residual connection. We assume that these operations are memory bound. ")
|
| 180 |
+
|
| 181 |
+
st.caption("Softmax")
|
| 182 |
+
softmax_bytes = 2*bs*h*n + 2*bs*h*n
|
| 183 |
+
c1, c2 = st.columns([2, 3])
|
| 184 |
+
softmax_time = print_kernel_execution(c1, c2, 0, softmax_bytes)
|
| 185 |
+
|
| 186 |
+
st.caption("Layer norm/residual connection")
|
| 187 |
+
ln_bytes = 2*bs*1*d
|
| 188 |
+
ln_flop = 0
|
| 189 |
+
ln_time = print_kernel_execution(c1, c2, 0, ln_bytes)
|
| 190 |
+
|
| 191 |
+
st.header('MLP')
|
| 192 |
+
st.subheader('First Linear')
|
| 193 |
+
mlp1_flop = 2*bs*1*d*4*d
|
| 194 |
+
mlp1_bytes = 2*bs*1*d + 2*d*4*d + 2*bs*1*4*d
|
| 195 |
+
c1, c2 = st.columns([2, 3])
|
| 196 |
+
mlp1_time = print_kernel_execution(c1, c2, mlp1_flop, mlp1_bytes)
|
| 197 |
+
|
| 198 |
+
st.subheader('Second Linear')
|
| 199 |
+
mlp2_flop = 2*bs*1*d*4*d
|
| 200 |
+
mlp2_bytes = 2*bs*1*d + 2*d*4*d + 2*bs*1*4*d
|
| 201 |
+
c1, c2 = st.columns([2, 3])
|
| 202 |
+
mlp2_time = print_kernel_execution(c1, c2, mlp2_flop, mlp2_bytes)
|
| 203 |
+
|
| 204 |
+
st.subheader('Element-wise ops')
|
| 205 |
+
st.write("We also need to take into the GeLU, layer norm, and residual connection. We assume that these operations are memory bound. ")
|
| 206 |
+
ln_bytes = 2*bs*1*d
|
| 207 |
+
ln_flop = 0
|
| 208 |
+
ln_time = print_kernel_execution(c1, c2, 0, ln_bytes)
|
|
|
|
|
|