File size: 9,031 Bytes
6d6abcb c4a84f5 6d6abcb |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
import streamlit as st
import time
from datetime import datetime
import logging
from utils.HFManager import fetch_training_metrics_commits
import pandas as pd
import os
from dotenv import load_dotenv
import plotly.graph_objects as go
import pydeck as pdk
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
# Page config
st.set_page_config(page_title="Alpha9 Miner Dashboard",
page_icon="🧠",
layout="wide",
menu_items={
'Get Help': 'https://github.com/Alpha9-Omega/YoGPT',
'Report a bug': "https://github.com/Alpha9-Omega/YoGPT/issues",
'About': "Dashboard for monitoring Alpha9 Bittensor and Commune miners"
})
# Custom CSS for progress bar and styling
st.markdown("""
<style>
.stProgress > div > div > div > div {
background-image: linear-gradient(to right, #9146FF, #784CBD);
}
.metric-container {
background-color: #262730;
padding: 1rem;
border-radius: 0.5rem;
}
.plot-container {
background-color: #262730;
border-radius: 0.5rem;
padding: 1rem;
}
</style>
""", unsafe_allow_html=True)
class MetricsManager:
def __init__(self, repo_name, token):
if not repo_name:
raise ValueError("Repository name is required")
if not token:
raise ValueError("Hugging Face token is required")
self.repo_name = repo_name
self.token = token
self.last_update = None
self.metrics_cache = []
self.update_interval = 60 # seconds
logging.info(f"MetricsManager initialized for repo: {repo_name}")
def needs_update(self):
if not self.last_update:
return True
return (datetime.now() - self.last_update).total_seconds() > self.update_interval
def fetch_latest_metrics(self):
if self.needs_update():
logging.info("Fetching fresh metrics from HuggingFace...")
try:
self.metrics_cache = fetch_training_metrics_commits(self.repo_name, token=self.token)
self.last_update = datetime.now()
logging.info(f"Fetched {len(self.metrics_cache)} metrics entries")
except Exception as e:
logging.error(f"Error fetching metrics: {str(e)}")
return []
return self.metrics_cache
def get_latest_job_metrics(self):
metrics = self.fetch_latest_metrics()
if not metrics:
return None
# Group metrics by job_id
jobs = {}
for entry in metrics:
job_id = entry['metrics']['job_id']
if job_id not in jobs:
jobs[job_id] = []
jobs[job_id].append(entry)
# Get the latest job
latest_job_id = max(jobs.keys())
return jobs[latest_job_id]
def get_historical_metrics(self):
metrics = self.fetch_latest_metrics()
if not metrics:
return pd.DataFrame()
records = []
for entry in metrics:
record = {
'timestamp': entry['timestamp'],
'miner_uid': entry['miner_uid'],
'job_id': entry['metrics']['job_id'],
'final_loss': entry['metrics'].get('final_loss', None),
'perplexity': entry['metrics'].get('perplexity', None),
'tokens_per_second': entry['metrics'].get('tokens_per_second', None),
'inner_lr': entry['metrics'].get('inner_lr', None),
'location': entry.get('location', 'Unknown'),
'model_repo': entry['model_repo']
}
records.append(record)
df = pd.DataFrame(records)
try:
df['timestamp'] = pd.to_datetime(df['timestamp'], format='%Y%m%d_%H%M%S')
except ValueError:
try:
df['timestamp'] = pd.to_datetime(df['timestamp'], format='mixed')
except:
st.warning("Could not parse some timestamp values")
return df.sort_values('timestamp')
# Get configuration
try:
hf_token = st.secrets["HF_TOKEN"]
except:
hf_token = os.getenv("HF_TOKEN")
try:
central_repo = st.secrets["CENTRAL_REPO"]
except:
central_repo = os.getenv("CENTRAL_REPO", "Tobius/yogpt_test")
if not hf_token:
st.error("No Hugging Face token found. Please set HF_TOKEN in environment variables.")
st.stop()
# Initialize metrics manager
if 'metrics_manager' not in st.session_state:
st.session_state.metrics_manager = MetricsManager(central_repo, hf_token)
# Dashboard UI
st.title("🧠 A9Labs Miners Dashboard")
# Progress Bar Section
latest_metrics = st.session_state.metrics_manager.get_latest_job_metrics()
if latest_metrics:
progress = 0.7158 # This should be calculated from actual data
tokens_progress = "715,899,792,640/1T tokens"
st.markdown("### Training Progress")
st.progress(progress)
col1, col2 = st.columns([1, 2])
with col1:
st.metric("Progress", f"{progress*100:.2f}%")
with col2:
st.metric("Tokens", tokens_progress)
# Metrics Grid
st.markdown("### Training Metrics")
metric_cols = st.columns(2)
with metric_cols[0]:
# Loss Plot
fig_loss = go.Figure()
fig_loss.add_trace(go.Scatter(x=[1, 2, 3], y=[12, 3, 2],
mode='lines',
line=dict(color='#9146FF', width=2),
name='Loss'))
fig_loss.update_layout(
title='Loss',
xaxis_title='Steps',
yaxis_title='Loss',
yaxis_type="log",
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font=dict(color='white')
)
st.plotly_chart(fig_loss, use_container_width=True)
# Tokens per Second Plot
fig_tps = go.Figure()
fig_tps.add_trace(go.Scatter(x=[1, 2, 3], y=[40000, 42000, 41000],
mode='lines',
line=dict(color='#9146FF', width=2),
name='Tokens/s'))
fig_tps.update_layout(
title='Tokens per Second',
xaxis_title='Time',
yaxis_title='Tokens/s',
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font=dict(color='white')
)
st.plotly_chart(fig_tps, use_container_width=True)
with metric_cols[1]:
# Perplexity Plot
fig_perp = go.Figure()
fig_perp.add_trace(go.Scatter(x=[1, 2, 3], y=[200, 50, 20],
mode='lines',
line=dict(color='#9146FF', width=2),
name='Perplexity'))
fig_perp.update_layout(
title='Perplexity',
xaxis_title='Steps',
yaxis_title='Perplexity',
yaxis_type="log",
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font=dict(color='white')
)
st.plotly_chart(fig_perp, use_container_width=True)
# Inner LR Plot
fig_lr = go.Figure()
fig_lr.add_trace(go.Scatter(x=[1, 2, 3], y=[0.0001, 0.0001, 0.0001],
mode='lines',
line=dict(color='#9146FF', width=2),
name='Inner LR'))
fig_lr.update_layout(
title='Inner Learning Rate',
xaxis_title='Steps',
yaxis_title='Learning Rate',
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font=dict(color='white')
)
st.plotly_chart(fig_lr, use_container_width=True)
# Leaderboard and Map
st.markdown("### Network Overview")
col1, col2 = st.columns([3, 2])
with col1:
if latest_metrics:
miner_df = pd.DataFrame([{
'Miner UID': m['miner_uid'],
'MH/s': round(m['metrics'].get('hashrate', 0) / 1e6, 2),
'Location': m.get('location', 'Unknown'),
'Status': 'Active'
} for m in latest_metrics]).sort_values('MH/s', ascending=False)
st.dataframe(miner_df, use_container_width=True)
with col2:
# Sample map data
map_data = pd.DataFrame({
'lat': [32.7767, 40.7128, 51.5074],
'lon': [-96.7970, -74.0060, -0.1278],
'size': [10, 15, 20]
})
st.pydeck_chart(pdk.Deck(
map_style='mapbox://styles/mapbox/dark-v10',
initial_view_state=pdk.ViewState(
latitude=20,
longitude=0,
zoom=1,
pitch=0,
),
layers=[
pdk.Layer(
'ScatterplotLayer',
data=map_data,
get_position='[lon, lat]',
get_color='[145, 70, 255, 160]',
get_radius='size',
pickable=True
),
]
))
# Auto-refresh
time.sleep(5)
st.rerun()
|