Spaces:
Runtime error
Runtime error
File size: 1,441 Bytes
44ac4da b75a0d1 1550361 b75a0d1 1550361 b75a0d1 f98bc09 b75a0d1 f98bc09 f86ffab f98bc09 f86ffab 23b5435 2e71f02 4719f35 f86ffab 23b5435 b75a0d1 f86ffab 23b5435 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import streamlit as st
def number_field(label, columns=None, **input_params):
c1, c2 = st.columns(columns or [1, 4])
# Display field name with some alignment
c1.markdown("##")
c1.markdown(label)
# Sets a default key parameter to avoid duplicate key errors
input_params.setdefault("key", label)
# Forward text input parameters
return c2.number_input("", **input_params)
def key_value(key, value, columns=None):
c1, c2 = st.columns(columns or [2, 3])
# Display field name with some alignment
c1.markdown("##")
c1.markdown(key)
c2.markdown("##")
c2.markdown(value)
st.header("Transformer parameters")
bs = number_field('Batch size: ', value=10)
h = number_field('Num heads: ', value=16)
d = number_field('Dimension: ', value=768)
n = number_field('Seq length: ', value=1024)
st.header('Query, Key, Value projection')
mha_flop = 2*bs*n*d*3*d
mha_bytes = 2*bs*n*d + 2*3*d*d + 2*bs*n*3*d
st.subheader("Multi-query Attention")
c1, c2 = st.columns([2, 3])
c1.write("FLOP:")
c2.write(str(mha_flop))
c1.write("Bytes: ")
c2.write(str(mha_bytes))
c1.write("Arithm. intensity:")
c2.write(str(mha_flop/mha_bytes))
mqa_flop = 2*bs*n*d*(1+2/h)*d
mqa_bytes = 2*bs*n*d + 2*(2/h)*d*d + 2*bs*n*(2/h)*d
st.subheader("Multi-query Attention")
key_value("FLOP: ", str(mqa_flop))
key_value("bytes: ", str(mqa_bytes))
key_value("Arithm. intensity:", str(mqa_flop/mqa_bytes))
st.header('Attention')
|