emozilla commited on
Commit
7e9f8cd
·
1 Parent(s): 1e5dafb

update leaderboard for multiple competitions

Browse files
Files changed (1) hide show
  1. app.py +51 -32
app.py CHANGED
@@ -31,6 +31,14 @@ NETUID = 6
31
  SUBNET_START_BLOCK = 2225782
32
  SECONDS_PER_BLOCK = 12
33
 
 
 
 
 
 
 
 
 
34
  def get_subtensor_and_metagraph() -> typing.Tuple[bt.subtensor, bt.metagraph]:
35
  for i in range(0, METAGRAPH_RETRIES):
36
  try:
@@ -54,6 +62,7 @@ class ModelData:
54
  block: int
55
  incentive: float
56
  emission: float
 
57
 
58
  @classmethod
59
  def from_compressed_str(cls, uid: int, hotkey: str, cs: str, block: int, incentive: float, emission: float):
@@ -66,6 +75,7 @@ class ModelData:
66
  name=tokens[1],
67
  commit=tokens[2] if tokens[2] != "None" else None,
68
  hash=tokens[3] if tokens[3] != "None" else None,
 
69
  block=block,
70
  incentive=incentive,
71
  emission=emission
@@ -194,8 +204,11 @@ tao_price = get_tao_price()
194
  leaderboard_df = get_subnet_data(subtensor, metagraph)
195
  leaderboard_df.sort(key=lambda x: x.incentive, reverse=True)
196
 
197
- scores = get_scores([x.uid for x in leaderboard_df])
198
-
 
 
 
199
  current_block = metagraph.block.item()
200
  next_update = next_tempo(
201
  SUBNET_START_BLOCK,
@@ -216,7 +229,7 @@ def get_next_update():
216
  delta = next_update_time - now
217
  return f"""<div align="center" style="font-size: larger;">Next reward update: <b>{blocks_to_go}</b> blocks (~{int(delta.total_seconds() // 60)} minutes)</div>"""
218
 
219
- def leaderboard_data(show_stale: bool):
220
  value = [
221
  [
222
  f'[{c.namespace}/{c.name} ({c.commit[0:8]})](https://huggingface.co/{c.namespace}/{c.name}/commit/{c.commit})',
@@ -225,7 +238,7 @@ def leaderboard_data(show_stale: bool):
225
  format_score(c.uid, scores, "weight"),
226
  c.uid,
227
  c.block
228
- ] for c in leaderboard_df if scores[c.uid]["fresh"] or show_stale
229
  ]
230
  return value
231
 
@@ -238,34 +251,40 @@ with demo:
238
 
239
  gr.HTML(value=get_next_update())
240
 
241
- gr.Label(
242
- value={ f"{c.namespace}/{c.name} ({c.commit[0:8]}) · ${round(c.emission * tao_price, 2):,} (τ{round(c.emission, 2):,})": c.incentive for c in leaderboard_df if c.incentive},
243
- num_top_classes=10,
244
- )
245
-
246
- with gr.Accordion("Evaluation Stats"):
247
- gr.HTML(EVALUATION_HEADER)
248
-
249
- with gr.Tabs():
250
- for entry in leaderboard_df:
251
- sample = scores[entry.uid]["sample"]
252
- if sample is not None:
253
- name = f"{entry.namespace}/{entry.name} ({entry.commit[0:8]})"
254
- with gr.Tab(name):
255
- gr.Chatbot([(sample[0], sample[1])])
256
- # gr.Chatbot([(sample[0], f"*{name}*: {sample[1]}"), (None, f"*GPT-4*: {sample[2]}")])
257
-
258
- show_stale = gr.Checkbox(label="Show Stale", interactive=True)
259
- leaderboard_table = gr.components.Dataframe(
260
- value=leaderboard_data(show_stale.value),
261
- headers=["Name", "Win Rate", "Perplexity", "Weight", "UID", "Block"],
262
- datatype=["markdown", "number", "number", "number", "number", "number"],
263
- elem_id="leaderboard-table",
264
- interactive=False,
265
- visible=True,
266
- )
267
- gr.HTML(EVALUATION_DETAILS)
268
- show_stale.change(leaderboard_data, [show_stale], leaderboard_table)
 
 
 
 
 
 
269
 
270
  with gr.Accordion("Validator Stats"):
271
  validator_table = gr.components.Dataframe(
 
31
  SUBNET_START_BLOCK = 2225782
32
  SECONDS_PER_BLOCK = 12
33
 
34
+ @dataclass
35
+ class Competition:
36
+ id: str
37
+ name: str
38
+
39
+ COMPETITIONS = [Competition(id="g1", name="gemma-7b"), Competition(id="m1", name="mistral-7b")]
40
+ DEFAULT_COMPETITION_ID = "m1"
41
+
42
  def get_subtensor_and_metagraph() -> typing.Tuple[bt.subtensor, bt.metagraph]:
43
  for i in range(0, METAGRAPH_RETRIES):
44
  try:
 
62
  block: int
63
  incentive: float
64
  emission: float
65
+ competition: str
66
 
67
  @classmethod
68
  def from_compressed_str(cls, uid: int, hotkey: str, cs: str, block: int, incentive: float, emission: float):
 
75
  name=tokens[1],
76
  commit=tokens[2] if tokens[2] != "None" else None,
77
  hash=tokens[3] if tokens[3] != "None" else None,
78
+ competition=tokens[4] if len(tokens) > 4 and tokens[4] != "None" else DEFAULT_COMPETITION_ID,
79
  block=block,
80
  incentive=incentive,
81
  emission=emission
 
204
  leaderboard_df = get_subnet_data(subtensor, metagraph)
205
  leaderboard_df.sort(key=lambda x: x.incentive, reverse=True)
206
 
207
+ competition_scores = {
208
+ y.id: get_scores([x.uid for x in leaderboard_df if x.competition == y.id])
209
+ for y in COMPETITIONS
210
+ }
211
+
212
  current_block = metagraph.block.item()
213
  next_update = next_tempo(
214
  SUBNET_START_BLOCK,
 
229
  delta = next_update_time - now
230
  return f"""<div align="center" style="font-size: larger;">Next reward update: <b>{blocks_to_go}</b> blocks (~{int(delta.total_seconds() // 60)} minutes)</div>"""
231
 
232
+ def leaderboard_data(show_stale: bool, scores: typing.Dict[int, typing.Dict[str, typing.Optional[float | str]]], competition_id: str):
233
  value = [
234
  [
235
  f'[{c.namespace}/{c.name} ({c.commit[0:8]})](https://huggingface.co/{c.namespace}/{c.name}/commit/{c.commit})',
 
238
  format_score(c.uid, scores, "weight"),
239
  c.uid,
240
  c.block
241
+ ] for c in leaderboard_df if c.competition == competition_id and (scores[c.uid]["fresh"] or show_stale)
242
  ]
243
  return value
244
 
 
251
 
252
  gr.HTML(value=get_next_update())
253
 
254
+ with gr.Tabs():
255
+ for competition in COMPETITIONS:
256
+ with gr.Tab(competition.name):
257
+ scores = competition_scores[competition.id]
258
+
259
+ gr.Label(
260
+ value={ f"{c.namespace}/{c.name} ({c.commit[0:8]}) · ${round(c.emission * tao_price, 2):,} (τ{round(c.emission, 2):,})": c.incentive for c in leaderboard_df if c.incentive and c.competition == competition.id},
261
+ num_top_classes=10,
262
+ )
263
+
264
+ with gr.Accordion("Evaluation Stats"):
265
+ gr.HTML(EVALUATION_HEADER)
266
+
267
+ with gr.Tabs():
268
+ for entry in leaderboard_df:
269
+ if entry.competition == competition.id:
270
+ sample = scores[entry.uid]["sample"]
271
+ if sample is not None:
272
+ name = f"{entry.namespace}/{entry.name} ({entry.commit[0:8]})"
273
+ with gr.Tab(name):
274
+ gr.Chatbot([(sample[0], sample[1])])
275
+ # gr.Chatbot([(sample[0], f"*{name}*: {sample[1]}"), (None, f"*GPT-4*: {sample[2]}")])
276
+
277
+ show_stale = gr.Checkbox(label="Show Stale", interactive=True)
278
+ leaderboard_table = gr.components.Dataframe(
279
+ value=leaderboard_data(show_stale.value, scores, competition.id),
280
+ headers=["Name", "Win Rate", "Perplexity", "Weight", "UID", "Block"],
281
+ datatype=["markdown", "number", "number", "number", "number", "number"],
282
+ elem_id="leaderboard-table",
283
+ interactive=False,
284
+ visible=True,
285
+ )
286
+ gr.HTML(EVALUATION_DETAILS)
287
+ show_stale.change(lambda x: leaderboard_data(x, scores, competition.id), [show_stale], leaderboard_table)
288
 
289
  with gr.Accordion("Validator Stats"):
290
  validator_table = gr.components.Dataframe(