Spaces:
Sleeping
Sleeping
Fix bugs
Browse files- app.py +71 -66
- requirements.txt +2 -1
- utils.py +250 -21
app.py
CHANGED
|
@@ -6,93 +6,99 @@ import plotly.express as px
|
|
| 6 |
import utils
|
| 7 |
|
| 8 |
_ = """
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"""
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
st.title('Folding Subnet Dashboard')
|
| 20 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 21 |
|
| 22 |
# reload data periodically
|
| 23 |
-
|
| 24 |
-
st.toast(f'Loaded {len(df)} runs')
|
| 25 |
-
|
| 26 |
-
# TODO: fix the factor for 24 hours ago
|
| 27 |
-
runs_alive_24h_ago = (df.last_event_at > pd.Timestamp.now() - pd.Timedelta('1d'))
|
| 28 |
-
df_24h = df.loc[runs_alive_24h_ago]
|
| 29 |
-
# correction factor to account for the fact that the data straddles the 24h boundary
|
| 30 |
-
# correction factor is based on the fraction of the run which occurred in the last 24h
|
| 31 |
-
# factor = (df_24h.last_event_at - pd.Timestamp.now() + pd.Timedelta('1d')) / pd.Timedelta('1d')
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
#### ------ PRODUCTIVITY ------
|
| 35 |
|
| 36 |
# Overview of productivity
|
| 37 |
st.subheader('Productivity overview')
|
| 38 |
-
st.info('Productivity metrics show how
|
| 39 |
|
| 40 |
-
productivity = utils.get_productivity(
|
| 41 |
-
productivity_24h = utils.get_productivity(
|
| 42 |
|
| 43 |
|
| 44 |
-
m1, m2, m3 = st.columns(
|
| 45 |
-
m1.metric('
|
| 46 |
-
m2.metric('Total
|
| 47 |
-
m3.metric('Total
|
|
|
|
| 48 |
|
| 49 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 50 |
|
| 51 |
-
time_binned_data = df.set_index('last_event_at').groupby(pd.Grouper(freq='12h'))
|
| 52 |
-
|
| 53 |
-
PROD_CHOICES = {
|
| 54 |
-
'Unique proteins folded': 'unique_pdbs',
|
| 55 |
-
'Total simulations': 'total_pdbs',
|
| 56 |
-
'Total simulation steps': 'total_md_steps',
|
| 57 |
-
}
|
| 58 |
-
prod_choice_label = st.radio('Select productivity metric', list(PROD_CHOICES.keys()), index=0, horizontal=True)
|
| 59 |
-
prod_choice = PROD_CHOICES[prod_choice_label]
|
| 60 |
-
steps_running_total = time_binned_data[prod_choice].sum().cumsum()
|
| 61 |
st.plotly_chart(
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
).update_traces(fill='tozeroy'),
|
| 66 |
use_container_width=True,
|
| 67 |
)
|
| 68 |
|
| 69 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
st.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
data_transferred_24h = utils.get_data_transferred(df_24h, unit=MEM_UNIT)
|
| 81 |
|
| 82 |
-
|
| 83 |
-
m1.metric(f'Total sent data ({MEM_UNIT})', f'{data_transferred.get("sent"):,.0f}', delta=f'{data_transferred_24h.get("sent"):,.0f} (24h)')
|
| 84 |
-
m2.metric(f'Total received data ({MEM_UNIT})', f'{data_transferred.get("received"):,.0f}', delta=f'{data_transferred_24h.get("received"):,.0f} (24h)')
|
| 85 |
-
m3.metric(f'Total transferred data ({MEM_UNIT})', f'{data_transferred.get("total"):,.0f}', delta=f'{data_transferred_24h.get("total"):,.0f} (24h)')
|
| 86 |
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
io_running_total['value'] = io_running_total['value'].apply(utils.convert_unit, args=(utils.BASE_UNITS, MEM_UNIT))
|
| 91 |
|
| 92 |
st.plotly_chart(
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
),
|
| 96 |
use_container_width=True,
|
| 97 |
)
|
| 98 |
|
|
@@ -107,7 +113,6 @@ m1, m2 = st.columns(2)
|
|
| 107 |
ntop = m1.slider('Number of top miners to display', value=10, min_value=3, max_value=50, step=1)
|
| 108 |
entity_choice = m2.radio('Select entity', utils.ENTITY_CHOICES, index=0, horizontal=True)
|
| 109 |
|
| 110 |
-
df_m = utils.get_metagraph(time.time()//UPDATE_INTERVAL)
|
| 111 |
df_miners = utils.get_leaderboard(df_m, ntop=ntop, entity_choice=entity_choice)
|
| 112 |
|
| 113 |
# hide colorbar and don't show y axis
|
|
@@ -128,13 +133,13 @@ st.markdown('<br>', unsafe_allow_html=True)
|
|
| 128 |
#### ------ LOGGED RUNS ------
|
| 129 |
|
| 130 |
st.subheader('Logged runs')
|
| 131 |
-
st.info('The timeline shows the creation and last event time of each run.')
|
| 132 |
-
st.plotly_chart(
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
)
|
| 138 |
|
| 139 |
with st.expander('Show raw run data'):
|
| 140 |
-
st.dataframe(
|
|
|
|
| 6 |
import utils
|
| 7 |
|
| 8 |
_ = """
|
| 9 |
+
[x] Define KPIs: Number of steps, number of completions and total generated tokens
|
| 10 |
+
[x] Data pipeline I: pull run summary data from wandb
|
| 11 |
+
[x] Data pipeline II: pull run event data from wandb (max 500 steps per run)
|
| 12 |
+
[x] Task trends: Number of tasks over time
|
| 13 |
+
[x] Reward trends I: average reward over time, by task
|
| 14 |
+
[x] Reward trends II: average nonzero reward over time, by task
|
| 15 |
+
[x] Reward trends III: average nonzero normalized reward over time, by task
|
| 16 |
+
[x] Explain trends: show release dates to indicate sudden changes
|
| 17 |
+
[ ] Miner trends: associate uids with miner rankings and plot top miner rewards vs network avg
|
| 18 |
+
[ ] Baseline rewards I: compare the network trends with baseline model gpt-3.5-turbo
|
| 19 |
+
[ ] Baseline rewards II: compare the network trends with baseline model gpt-4o
|
| 20 |
+
[ ] Baseline rewards III: compare the network trends with baseline model zephyr
|
| 21 |
+
[ ] Baseline rewards IV: compare the network trends with baseline model solar
|
| 22 |
+
[ ] Baseline rewards V: compare the network trends with baseline model llama3 8B
|
| 23 |
+
[ ] Baseline rewards VI: compare the network trends with baseline model llama3 70B
|
| 24 |
+
|
| 25 |
+
---------
|
| 26 |
"""
|
| 27 |
|
| 28 |
+
st.title('Prompting Subnet Dashboard')
|
|
|
|
|
|
|
|
|
|
| 29 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 30 |
|
| 31 |
# reload data periodically
|
| 32 |
+
state_vars = utils.load_state_vars()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
df_runs = state_vars['df_runs']
|
| 35 |
+
df_runs_24h = state_vars['df_runs_24h']
|
| 36 |
+
df_vali = state_vars['df_vali']
|
| 37 |
+
df_events = state_vars['df_events']
|
| 38 |
+
df_task_counts = state_vars['df_task_counts']
|
| 39 |
+
df_m = state_vars['metagraph']
|
| 40 |
+
st.toast(f'Loaded {len(df_runs)} runs')
|
| 41 |
|
| 42 |
#### ------ PRODUCTIVITY ------
|
| 43 |
|
| 44 |
# Overview of productivity
|
| 45 |
st.subheader('Productivity overview')
|
| 46 |
+
st.info('Productivity metrics show how much data has been created by subnet 1')
|
| 47 |
|
| 48 |
+
productivity = utils.get_productivity(df_runs)
|
| 49 |
+
productivity_24h = utils.get_productivity(df_runs_24h)
|
| 50 |
|
| 51 |
|
| 52 |
+
m1, m2, m3, m4 = st.columns(4)
|
| 53 |
+
m1.metric('Competition duration', f'{productivity.get("duration").days} days')
|
| 54 |
+
m2.metric('Total events', f'{productivity.get("total_events")/1e6:,.2f}M', delta=f'{productivity_24h.get("total_events")/1e6:,.2f}M (24h)')
|
| 55 |
+
m3.metric('Total completions', f'{productivity.get("total_completions")/1e9:,.2f}B', delta=f'{productivity_24h.get("total_completions")/1e9:,.2f}B (24h)')
|
| 56 |
+
m4.metric('Total dataset tokens', f'{productivity.get("total_tokens")/1e9:,.2f}B', delta=f'{productivity_24h.get("total_tokens")/1e9:,.2f}B (24h)')
|
| 57 |
|
| 58 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
st.plotly_chart(
|
| 61 |
+
px.area(df_task_counts, y=df_task_counts.columns, title='Data Created by Task',
|
| 62 |
+
labels={'created_at':'','value':'Total data created'},
|
| 63 |
+
),
|
|
|
|
| 64 |
use_container_width=True,
|
| 65 |
)
|
| 66 |
|
| 67 |
st.markdown('<br>', unsafe_allow_html=True)
|
| 68 |
|
| 69 |
+
# Overview of productivity
|
| 70 |
+
st.subheader('Improvement overview')
|
| 71 |
+
st.info('Subnet 1 is an endlessly improving system, where miners compete to produce high quality responses to a range of challenging tasks')
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
TASK_CHOICES = {
|
| 75 |
+
'Question answering': 'qa',
|
| 76 |
+
'Summarization': 'summarization',
|
| 77 |
+
'Date-based question answering': 'date_qa',
|
| 78 |
+
'Math': 'math',
|
| 79 |
+
'Generic instruction': 'generic',
|
| 80 |
+
'Sentiment analysis': 'sentiment',
|
| 81 |
+
'Translation': 'translation',
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
with st.expander('Advanced settings'):
|
| 85 |
+
c1, c2 = st.columns(2)
|
| 86 |
+
remove_zero_rewards = c1.checkbox('Exclude zero rewards', value=True, help='Remove completions which scored zero rewards (failed responses, timeouts etc.)')
|
| 87 |
+
normalize_rewards = c1.checkbox('Normalize rewards', value=True, help='Scale rewards for each task to a maximium value of 1 (approx)')
|
| 88 |
+
show_releases = c1.checkbox('Show releases', value=False, help='Add annotations which indicate when major releases may have impacted network performance')
|
| 89 |
+
moving_avg_window = c2.slider('Moving avg. window', min_value=1, max_value=30, value=14, help='Window size to smooth data and make long term trends clearer')
|
| 90 |
|
| 91 |
+
reward_col = 'normalized_rewards' if normalize_rewards else 'rewards'
|
|
|
|
| 92 |
|
| 93 |
+
df_stats = utils.get_reward_stats(df_events, exclude_multiturn=True, freq='1D', remove_zero_rewards=remove_zero_rewards)
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
+
task_choice_label = st.radio('Select task', list(TASK_CHOICES.keys()), index=0, horizontal=True)
|
| 97 |
+
task_choice = TASK_CHOICES[task_choice_label]
|
|
|
|
| 98 |
|
| 99 |
st.plotly_chart(
|
| 100 |
+
# add fillgradient to make it easier to see the trend
|
| 101 |
+
utils.plot_reward_trends(df_stats, task=task_choice, window=moving_avg_window, col=reward_col, annotate=show_releases, task_label=task_choice_label),
|
|
|
|
| 102 |
use_container_width=True,
|
| 103 |
)
|
| 104 |
|
|
|
|
| 113 |
ntop = m1.slider('Number of top miners to display', value=10, min_value=3, max_value=50, step=1)
|
| 114 |
entity_choice = m2.radio('Select entity', utils.ENTITY_CHOICES, index=0, horizontal=True)
|
| 115 |
|
|
|
|
| 116 |
df_miners = utils.get_leaderboard(df_m, ntop=ntop, entity_choice=entity_choice)
|
| 117 |
|
| 118 |
# hide colorbar and don't show y axis
|
|
|
|
| 133 |
#### ------ LOGGED RUNS ------
|
| 134 |
|
| 135 |
st.subheader('Logged runs')
|
| 136 |
+
# st.info('The timeline shows the creation and last event time of each run.')
|
| 137 |
+
# st.plotly_chart(
|
| 138 |
+
# px.timeline(df_runs, x_start='created_at', x_end='last_event_at', y='user', color='state',
|
| 139 |
+
# labels={'created_at':'Created at', 'last_event_at':'Last event at', 'username':''},
|
| 140 |
+
# ),
|
| 141 |
+
# use_container_width=True
|
| 142 |
+
# )
|
| 143 |
|
| 144 |
with st.expander('Show raw run data'):
|
| 145 |
+
st.dataframe(df_runs)
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ git+https://github.com/macrocosm-os/prompting.git
|
|
| 2 |
aiohttp
|
| 3 |
deprecated
|
| 4 |
aiohttp_apispec>=2.2.3
|
| 5 |
-
aiofiles
|
|
|
|
|
|
| 2 |
aiohttp
|
| 3 |
deprecated
|
| 4 |
aiohttp_apispec>=2.2.3
|
| 5 |
+
aiofiles
|
| 6 |
+
streamlit
|
utils.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
import os
|
| 2 |
import tqdm
|
| 3 |
import time
|
|
|
|
| 4 |
import wandb
|
|
|
|
| 5 |
import streamlit as st
|
| 6 |
import pandas as pd
|
| 7 |
import bittensor as bt
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# TODO: Store the runs dataframe (as in sn1 dashboard) and top up with the ones created since the last snapshot
|
|
@@ -12,14 +15,14 @@ import bittensor as bt
|
|
| 12 |
|
| 13 |
|
| 14 |
MIN_STEPS = 10 # minimum number of steps in wandb run in order to be worth analyzing
|
| 15 |
-
MAX_RUNS = 100#0000
|
| 16 |
NETUID = 1
|
| 17 |
BASE_PATH = 'macrocosmos/prompting-validators'
|
| 18 |
NETWORK = 'finney'
|
| 19 |
-
KEYS =
|
| 20 |
ABBREV_CHARS = 8
|
| 21 |
ENTITY_CHOICES = ('identity', 'hotkey', 'coldkey')
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
api = wandb.Api(timeout=600)
|
| 25 |
|
|
@@ -102,17 +105,44 @@ def get_metagraph(time):
|
|
| 102 |
return df_m
|
| 103 |
|
| 104 |
|
| 105 |
-
@st.cache_data()
|
| 106 |
-
def
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
@st.cache_data(show_spinner=False)
|
| 118 |
def build_data(timestamp=None, path=BASE_PATH, min_steps=MIN_STEPS, use_cache=True):
|
|
@@ -140,7 +170,7 @@ def build_data(timestamp=None, path=BASE_PATH, min_steps=MIN_STEPS, use_cache=Tr
|
|
| 140 |
if num_steps<min_steps:
|
| 141 |
continue
|
| 142 |
n_events += num_steps
|
| 143 |
-
prog_msg = f'Loading data {i/len(runs)*100:.0f}%, {n_events:,.0f} events)'
|
| 144 |
progress.progress(i/len(runs),text=f'{prog_msg}... **downloading** `{os.path.join(*run.path)}`')
|
| 145 |
|
| 146 |
run_data.append(run)
|
|
@@ -153,23 +183,222 @@ def build_data(timestamp=None, path=BASE_PATH, min_steps=MIN_STEPS, use_cache=Tr
|
|
| 153 |
df['identity'] = df['vali_hotkey'].map(IDENTITIES).fillna('unknown')
|
| 154 |
df['vali_hotkey'] = df['vali_hotkey'].str[:ABBREV_CHARS]
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
df.to_csv(save_path, index=False)
|
|
|
|
| 157 |
return df
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
def load_state_vars():
|
| 161 |
UPDATE_INTERVAL = 600
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
df_m = get_metagraph(time.time()//UPDATE_INTERVAL)
|
| 168 |
|
| 169 |
return {
|
| 170 |
-
'
|
| 171 |
-
'
|
|
|
|
|
|
|
| 172 |
'metagraph': df_m,
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
|
|
|
|
| 1 |
import os
|
| 2 |
import tqdm
|
| 3 |
import time
|
| 4 |
+
import glob
|
| 5 |
import wandb
|
| 6 |
+
from traceback import print_exc
|
| 7 |
import streamlit as st
|
| 8 |
import pandas as pd
|
| 9 |
import bittensor as bt
|
| 10 |
+
import plotly.express as px
|
| 11 |
|
| 12 |
|
| 13 |
# TODO: Store the runs dataframe (as in sn1 dashboard) and top up with the ones created since the last snapshot
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
MIN_STEPS = 10 # minimum number of steps in wandb run in order to be worth analyzing
|
|
|
|
| 18 |
NETUID = 1
|
| 19 |
BASE_PATH = 'macrocosmos/prompting-validators'
|
| 20 |
NETWORK = 'finney'
|
| 21 |
+
KEYS = ['_step','_timestamp','task','query','reference','challenge','topic','subtopic']
|
| 22 |
ABBREV_CHARS = 8
|
| 23 |
ENTITY_CHOICES = ('identity', 'hotkey', 'coldkey')
|
| 24 |
+
LOCAL_WANDB_PATH = './data/wandb'
|
| 25 |
+
USERNAME = 'opentensor'
|
| 26 |
|
| 27 |
api = wandb.Api(timeout=600)
|
| 28 |
|
|
|
|
| 105 |
return df_m
|
| 106 |
|
| 107 |
|
| 108 |
+
@st.cache_data(show_spinner=False)
|
| 109 |
+
def load_downloaded_runs(time, cols=KEYS):
|
| 110 |
+
|
| 111 |
+
list_cols = ['rewards','uids']
|
| 112 |
+
extra_cols = ['turn']
|
| 113 |
+
df_all = pd.DataFrame()
|
| 114 |
+
|
| 115 |
+
progress = st.progress(0, text='Loading downloaded data')
|
| 116 |
+
paths = glob.glob(os.path.join(LOCAL_WANDB_PATH,'*.parquet'))
|
| 117 |
+
for i, path in enumerate(paths):
|
| 118 |
+
run_id = path.split('/')[-1].split('.')[0]
|
| 119 |
+
frame = pd.read_parquet(path).dropna(subset=cols)
|
| 120 |
+
frame._timestamp = frame._timestamp.apply(pd.to_datetime, unit='s')
|
| 121 |
+
# handle missing extra cols such as turn which depend on the version of the codebase
|
| 122 |
+
found_extra_cols = [c for c in frame.columns if c in extra_cols]
|
| 123 |
+
df_long = frame[cols+list_cols+found_extra_cols].explode(list_cols)
|
| 124 |
+
|
| 125 |
+
prog_msg = f'Downloading data {i/len(paths)*100:.0f}%'
|
| 126 |
+
progress.progress(i/len(paths), text=f'{prog_msg}... **downloading** `{run_id}`')
|
| 127 |
+
|
| 128 |
+
df_all = pd.concat([df_all, df_long.assign(run_id=run_id)], ignore_index=True)
|
| 129 |
+
|
| 130 |
+
progress.empty()
|
| 131 |
+
|
| 132 |
+
# Ensure we have consistent naming schema for tasks
|
| 133 |
+
task_mapping = {
|
| 134 |
+
'date-based question answering': 'date_qa',
|
| 135 |
+
'question-answering': 'qa',
|
| 136 |
+
}
|
| 137 |
+
df_all.task = df_all.task.apply(lambda x: task_mapping.get(x, x))
|
| 138 |
+
|
| 139 |
+
# Runs which do not have a turn field are imputed to be turn zero (single turn)
|
| 140 |
+
df_all.turn.fillna(0, inplace=True)
|
| 141 |
+
|
| 142 |
+
df_all.sort_values(by=['_timestamp'], inplace=True)
|
| 143 |
+
|
| 144 |
+
return df_all
|
| 145 |
+
|
| 146 |
|
| 147 |
@st.cache_data(show_spinner=False)
|
| 148 |
def build_data(timestamp=None, path=BASE_PATH, min_steps=MIN_STEPS, use_cache=True):
|
|
|
|
| 170 |
if num_steps<min_steps:
|
| 171 |
continue
|
| 172 |
n_events += num_steps
|
| 173 |
+
prog_msg = f'Loading data {i/len(runs)*100:.0f}%, (total {n_events:,.0f} events)'
|
| 174 |
progress.progress(i/len(runs),text=f'{prog_msg}... **downloading** `{os.path.join(*run.path)}`')
|
| 175 |
|
| 176 |
run_data.append(run)
|
|
|
|
| 183 |
df['identity'] = df['vali_hotkey'].map(IDENTITIES).fillna('unknown')
|
| 184 |
df['vali_hotkey'] = df['vali_hotkey'].str[:ABBREV_CHARS]
|
| 185 |
|
| 186 |
+
# Drop events that are not related to validator queries
|
| 187 |
+
df.dropna(subset='query', inplace=True)
|
| 188 |
+
|
| 189 |
+
print(df.completions.apply(type).value_counts())
|
| 190 |
+
# Assumes completions is in the frame
|
| 191 |
+
df['completions'] = df['completions'].apply(lambda x: x if isinstance(x, list) else eval(x))
|
| 192 |
+
|
| 193 |
+
df['completion_words'] = df.completions.apply(lambda x: sum([len(xx.split()) for xx in x]) if isinstance(x, list) else 0)
|
| 194 |
+
df['validator_words'] = df.apply(lambda x: len(str(x.query).split()) + len(str(x.challenge).split()) + len(str(x.reference).split()), axis=1 )
|
| 195 |
+
|
| 196 |
df.to_csv(save_path, index=False)
|
| 197 |
+
|
| 198 |
return df
|
| 199 |
|
| 200 |
+
@st.cache_data()
|
| 201 |
+
def normalize_rewards(df, turn=0, percentile=0.98):
|
| 202 |
+
top_reward_stats = df.loc[df.turn==turn].astype({'rewards':float}).groupby('task').rewards.quantile(percentile)
|
| 203 |
+
|
| 204 |
+
df['best_reward'] = df.task.map(top_reward_stats)
|
| 205 |
+
df['normalized_rewards'] = df['rewards'].astype(float) / df['best_reward']
|
| 206 |
+
return df
|
| 207 |
+
|
| 208 |
+
@st.cache_data(show_spinner=False)
|
| 209 |
+
def download_runs(time, df_vali):
|
| 210 |
+
|
| 211 |
+
pbar = tqdm.tqdm(df_vali.index, total=len(df_vali))
|
| 212 |
+
|
| 213 |
+
progress = st.progress(0, text='Loading data')
|
| 214 |
+
|
| 215 |
+
for i, idx in enumerate(pbar):
|
| 216 |
+
row = df_vali.loc[idx]
|
| 217 |
+
|
| 218 |
+
prog_msg = f'Downloading data {i/len(df_vali)*100:.0f}%'
|
| 219 |
+
progress.progress(i/len(df_vali), text=f'{prog_msg}... **downloading** `{os.path.join(*row.run_id)}`')
|
| 220 |
+
|
| 221 |
+
save_path = f'data/wandb/{row.run_id}.parquet'
|
| 222 |
+
if os.path.exists(save_path):
|
| 223 |
+
pbar.set_description(f'>> Skipping {row.run_id!r} because file {save_path!r} already exists')
|
| 224 |
+
continue
|
| 225 |
+
|
| 226 |
+
try:
|
| 227 |
+
pbar.set_description(f'* Downloading run {row.run_id!r}', flush=True)
|
| 228 |
+
run = api.run(row.run_path)
|
| 229 |
+
|
| 230 |
+
# By default we just download a subset of events (500 most recent)
|
| 231 |
+
df = run.history()
|
| 232 |
+
df.to_parquet(save_path)
|
| 233 |
+
except KeyboardInterrupt:
|
| 234 |
+
break
|
| 235 |
+
except Exception as e:
|
| 236 |
+
pbar.set_description(f'- Something went wrong with {row.run_id!r}: {print_exc()}\n')
|
| 237 |
+
|
| 238 |
+
progress.empty()
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def get_productivity(df_runs):
|
| 242 |
+
|
| 243 |
+
total_duration = df_runs.last_event_at.max() - df_runs.created_at.min()
|
| 244 |
+
total_steps = df_runs.num_steps.sum()
|
| 245 |
+
total_completions = (df_runs.num_steps*df_runs.sample_size).sum()
|
| 246 |
+
total_completion_words = (df_runs.num_steps*df_runs.completion_words).sum()
|
| 247 |
+
total_completion_tokens = round(total_completion_words/0.75)
|
| 248 |
+
total_validator_words = (df_runs.num_steps*df_runs.apply(lambda x: len(str(x.query).split()) + len(str(x.challenge).split()) + len(str(x.reference).split()), axis=1 )).sum()
|
| 249 |
+
total_validator_tokens = round(total_validator_words/0.75)
|
| 250 |
+
total_dataset_tokens = total_completion_tokens + total_validator_tokens
|
| 251 |
+
|
| 252 |
+
return {
|
| 253 |
+
'duration':total_duration,
|
| 254 |
+
'total_events':total_steps,
|
| 255 |
+
'total_completions':total_completions,
|
| 256 |
+
'total_completion_tokens':total_completion_tokens,
|
| 257 |
+
'total_validator_tokens':total_validator_tokens,
|
| 258 |
+
'total_tokens':total_dataset_tokens,
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
@st.cache_data(show_spinner=False)
|
| 262 |
+
def get_reward_stats(df, exclude_multiturn=True, freq='1D', remove_zero_rewards=True, agg='mean', date_min='2024-01-22', date_max='2024-06-25'):
|
| 263 |
+
|
| 264 |
+
df = df.loc[df._timestamp.between(pd.Timestamp(date_min), pd.Timestamp(date_max))]
|
| 265 |
+
if exclude_multiturn:
|
| 266 |
+
df = df.loc[df.turn == 0]
|
| 267 |
+
if remove_zero_rewards:
|
| 268 |
+
df = df.loc[df.rewards > 0]
|
| 269 |
+
|
| 270 |
+
groups = ['run_id',pd.Grouper(key='_timestamp',freq=freq),'task']
|
| 271 |
+
return df.groupby(groups).agg({'rewards':agg, 'normalized_rewards':agg})
|
| 272 |
+
|
| 273 |
+
def get_release_dates():
|
| 274 |
+
release_dates = pd.DataFrame([
|
| 275 |
+
{'version': '1.0.0', 'release_date': pd.Timestamp(month=1, day=22, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':['qa','summarization']},
|
| 276 |
+
{'version': '1.0.1', 'release_date': pd.Timestamp(month=1, day=22, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':[]},
|
| 277 |
+
{'version': '1.0.2', 'release_date': pd.Timestamp(month=1, day=24, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':['qa','summarization']},
|
| 278 |
+
{'version': '1.0.3', 'release_date': pd.Timestamp(month=2, day=14, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':[]},
|
| 279 |
+
{'version': '1.0.4', 'release_date': pd.Timestamp(month=2, day=15, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':[]},
|
| 280 |
+
{'version': '1.1.0', 'release_date': pd.Timestamp(month=2, day=21, year=2024), 'note': 'decay scores', 'model': 'zephyr', 'tasks_affected':['date_qa','math']},
|
| 281 |
+
{'version': '1.1.1', 'release_date': pd.Timestamp(month=2, day=28, year=2024), 'note': 'reduce penalty weight', 'model': 'zephyr', 'tasks_affected':['date_qa','qa','summarization']},
|
| 282 |
+
{'version': '1.1.2', 'release_date': pd.Timestamp(month=2, day=29, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':[]},
|
| 283 |
+
{'version': '1.1.3', 'release_date': pd.Timestamp(month=3, day=11, year=2024), 'note': '', 'model': 'zephyr', 'tasks_affected':[]},
|
| 284 |
+
{'version': '1.2.0', 'release_date': pd.Timestamp(month=3, day=19, year=2024), 'note': 'vllm', 'model': 'zephyr', 'tasks_affected':[]},
|
| 285 |
+
{'version': '1.3.0', 'release_date': pd.Timestamp(month=3, day=27, year=2024), 'note': '', 'model': 'solar', 'tasks_affected':['all','math']},
|
| 286 |
+
{'version': '2.0.0', 'release_date': pd.Timestamp(month=4, day=4, year=2024), 'note': 'streaming', 'model': 'solar', 'tasks_affected':['math','qa','summarization']},
|
| 287 |
+
{'version': '2.1.0', 'release_date': pd.Timestamp(month=4, day=18, year=2024), 'note': 'chattensor prompt', 'model': 'solar', 'tasks_affected':['generic']},
|
| 288 |
+
{'version': '2.2.0', 'release_date': pd.Timestamp(month=5, day=1, year=2024), 'note': 'multiturn + paraphrase', 'model': 'solar', 'tasks_affected':['sentiment','translation','math']},
|
| 289 |
+
{'version': '2.3.0', 'release_date': pd.Timestamp(month=5, day=20, year=2024), 'note': 'llama + freeform date', 'model': 'llama', 'tasks_affected':['all','date_qa']},
|
| 290 |
+
{'version': '2.3.1', 'release_date': pd.Timestamp(month=5, day=21, year=2024), 'note': '', 'model': 'llama', 'tasks_affected':['date_qa']},
|
| 291 |
+
{'version': '2.4.0', 'release_date': pd.Timestamp(month=6, day=5, year=2024), 'note': 'streaming penalty', 'model': 'llama', 'tasks_affected':[]},
|
| 292 |
+
{'version': '2.4.1', 'release_date': pd.Timestamp(month=6, day=6, year=2024), 'note': '', 'model': 'llama', 'tasks_affected':[]},
|
| 293 |
+
{'version': '2.4.2', 'release_date': pd.Timestamp(month=6, day=7, year=2024), 'note': '', 'model': 'llama', 'tasks_affected':[]},
|
| 294 |
+
{'version': '2.4.2', 'release_date': pd.Timestamp(month=6, day=7, year=2024), 'note': '', 'model': 'llama', 'tasks_affected':[]},
|
| 295 |
+
{'version': '2.5.0', 'release_date': pd.Timestamp(month=6, day=18, year=2024), 'note': 'reduce multiturn', 'model': 'llama', 'tasks_affected':['translation','sentiment']},
|
| 296 |
+
{'version': '2.5.1', 'release_date': pd.Timestamp(month=6, day=25, year=2024), 'note': 'reduce timeout', 'model': 'llama', 'tasks_affected':[]},
|
| 297 |
+
])
|
| 298 |
+
return release_dates
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def plot_reward_trends(df_stats, task='qa', window=14, col='normalized_reward', annotate=False, task_label='Question answering'):
|
| 302 |
+
|
| 303 |
+
stats = df_stats.reset_index()
|
| 304 |
+
release_dates = get_release_dates()
|
| 305 |
+
stats_task = stats.loc[(stats.task == task)].sort_values(by='_timestamp')
|
| 306 |
+
stats_task['rewards_ma'] = stats_task[col].rolling(window, min_periods=0).mean()
|
| 307 |
+
fig = px.area(stats_task,
|
| 308 |
+
x='_timestamp', y='rewards_ma',
|
| 309 |
+
title=f'Reward Trend for {task_label} Task',
|
| 310 |
+
labels={'rewards_ma': f'Rewards [{window} day avg.]','_timestamp':''},
|
| 311 |
+
width=800,height=600,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
if not annotate:
|
| 315 |
+
return fig
|
| 316 |
+
|
| 317 |
+
# Add annotations based on relevant releases
|
| 318 |
+
for idx, row in release_dates.iterrows():
|
| 319 |
+
if all(col not in row['tasks_affected'] for col in ['all',task]):
|
| 320 |
+
continue
|
| 321 |
+
# TODO add annotation or something
|
| 322 |
+
fig.add_vline(row['release_date'], line_color='red', opacity=0.6, line_dash='dot', line_width=1)#, annotation_text=str(v))
|
| 323 |
+
|
| 324 |
+
return fig
|
| 325 |
+
|
| 326 |
+
@st.cache_data()
|
| 327 |
+
def get_task_counts(df_runs, df_events):
|
| 328 |
+
# Get mapping from run id to prompting repo version
|
| 329 |
+
run_to_version = df_runs.set_index('run_id').version.to_dict()
|
| 330 |
+
|
| 331 |
+
df_events['version'] = df_events.run_id.map(run_to_version)
|
| 332 |
+
|
| 333 |
+
def version_to_spec(version):
|
| 334 |
+
major, minor, patch = version.split('.')
|
| 335 |
+
return 10_000 * major + 100 * minor + patch
|
| 336 |
+
|
| 337 |
+
def get_closest_prev_version(version, my_versions):
|
| 338 |
+
|
| 339 |
+
ref_spec = version_to_spec(version)
|
| 340 |
+
my_specs = list(map(version_to_spec, my_versions))
|
| 341 |
+
|
| 342 |
+
match = my_specs[0]
|
| 343 |
+
for spec in my_specs[1:]:
|
| 344 |
+
if spec>ref_spec:
|
| 345 |
+
break
|
| 346 |
+
|
| 347 |
+
match = spec
|
| 348 |
+
|
| 349 |
+
return my_versions[my_specs.index(match)]
|
| 350 |
+
|
| 351 |
+
# Now estimate the distribution of tasks for each version using the event data
|
| 352 |
+
task_rate = df_events.groupby('version').task.value_counts(normalize=True).unstack().fillna(0)
|
| 353 |
+
# Impute missing versions
|
| 354 |
+
for v in sorted(df_runs.version.unique()):
|
| 355 |
+
if v not in task_rate.index:
|
| 356 |
+
prev_version = get_closest_prev_version(v, list(task_rate.index))
|
| 357 |
+
print(f'Imputing version {v} with task rate from closes previous version {prev_version!r}')
|
| 358 |
+
task_rate.loc[v] = task_rate.loc[prev_version]
|
| 359 |
+
|
| 360 |
+
# get esimated number of each task generated in every run using summary dataframe
|
| 361 |
+
task_counts = df_runs.set_index('created_at').sort_index().apply(lambda x: round(task_rate.loc[x.version]*x.num_steps), axis=1).cumsum()
|
| 362 |
+
return task_counts
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def load_state_vars(username=USERNAME, percentile=0.95):
|
| 366 |
|
|
|
|
| 367 |
UPDATE_INTERVAL = 600
|
| 368 |
|
| 369 |
+
df_runs = build_data(time.time()//UPDATE_INTERVAL, use_cache=True)
|
| 370 |
+
|
| 371 |
+
df_runs = df_runs.loc[df_runs.netuid.isin([1,61,102])]
|
| 372 |
+
st.toast(f'Loaded {len(df_runs)} runs')
|
| 373 |
+
|
| 374 |
+
df_vali = df_runs.loc[df_runs.username == username]
|
| 375 |
+
|
| 376 |
+
download_runs(time.time()//UPDATE_INTERVAL, df_vali)
|
| 377 |
+
|
| 378 |
+
df_events = load_downloaded_runs(time.time()//UPDATE_INTERVAL)
|
| 379 |
+
df_events = normalize_rewards(df_events, percentile=percentile)
|
| 380 |
+
|
| 381 |
+
yesterday = pd.Timestamp.now() - pd.Timedelta('1d')
|
| 382 |
+
runs_alive_24h_ago = (df_runs.last_event_at > yesterday)
|
| 383 |
+
|
| 384 |
+
df_runs_24h = df_runs.loc[runs_alive_24h_ago]
|
| 385 |
+
|
| 386 |
+
# weight factor indicates the fraction of events that happened within the last 24 hour.
|
| 387 |
+
fraction = 1 - (yesterday - df_runs_24h.created_at) / (pd.Timestamp.now()- df_runs_24h.created_at)
|
| 388 |
+
df_runs_24h['fraction'] = fraction.clip(0,1)
|
| 389 |
+
df_runs_24h['num_steps'] *= fraction.clip(0,1)
|
| 390 |
+
|
| 391 |
+
df_task_counts = get_task_counts(df_runs, df_events)
|
| 392 |
|
| 393 |
df_m = get_metagraph(time.time()//UPDATE_INTERVAL)
|
| 394 |
|
| 395 |
return {
|
| 396 |
+
'df_runs': df_runs,
|
| 397 |
+
'df_runs_24h': df_runs_24h,
|
| 398 |
+
'df_vali': df_vali,
|
| 399 |
+
'df_events': df_events,
|
| 400 |
'metagraph': df_m,
|
| 401 |
+
'df_task_counts': df_task_counts
|
| 402 |
}
|
| 403 |
|
| 404 |
|