AlexNijjar commited on
Commit
4d944cb
·
unverified ·
1 Parent(s): 5fb35aa

Add duplicate submission graph

Browse files
Files changed (2) hide show
  1. src/app.py +4 -1
  2. src/submissions.py +80 -6
src/app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from chain_data import sync_chain
4
  from leaderboard import create_leaderboard, create_dropdown, create_baseline
5
  from model_demo import create_demo
6
- from submissions import create_submissions, DROPDOWN_OPTIONS
7
  from validator_states import create_validator_states
8
  from validator_weights import create_weights
9
  from wandb_data import sync
@@ -49,6 +49,9 @@ def main():
49
 
50
  filter_dropdown.change(lambda submission_filter: create_submissions(submission_filter), [filter_dropdown], [submissions_dataframe])
51
 
 
 
 
52
  with gr.Tab("Model Demo"):
53
  create_demo()
54
  app.launch()
 
3
  from chain_data import sync_chain
4
  from leaderboard import create_leaderboard, create_dropdown, create_baseline
5
  from model_demo import create_demo
6
+ from submissions import create_submissions, create_duplicate_submissions_plot, DROPDOWN_OPTIONS
7
  from validator_states import create_validator_states
8
  from validator_weights import create_weights
9
  from wandb_data import sync
 
49
 
50
  filter_dropdown.change(lambda submission_filter: create_submissions(submission_filter), [filter_dropdown], [submissions_dataframe])
51
 
52
+ duplicate_submissions_plot = gr.Plot()
53
+ duplicate_submissions_plot.attach_load_event(lambda: create_duplicate_submissions_plot(), None)
54
+
55
  with gr.Tab("Model Demo"):
56
  create_demo()
57
  app.launch()
src/submissions.py CHANGED
@@ -1,7 +1,9 @@
 
1
  from enum import Enum
2
 
3
  import gradio as gr
4
  import pandas as pd
 
5
 
6
  from chain_data import sync_chain, fetch_commitments
7
  from src import Key
@@ -18,14 +20,10 @@ class SubmissionStatus(Enum):
18
 
19
  @staticmethod
20
  def get_status(run: Run, hotkey: Key, coldkey: Key, block: int, revision: str) -> "SubmissionStatus":
21
- blacklisted_keys = get_blacklisted_keys()
22
- if hotkey in blacklisted_keys.hotkeys or coldkey in blacklisted_keys.coldkeys:
23
  return SubmissionStatus.BLACKLISTED
24
 
25
- if not any(
26
- submission.hotkey == hotkey and submission.revision == revision
27
- for submission in blacklisted_keys.duplicate_selection.safe_submissions
28
- ):
29
  return SubmissionStatus.DUPLICATE
30
 
31
  if hotkey in run.submissions and block > run.submissions[hotkey].info.block and hotkey not in run.invalid_submissions:
@@ -40,9 +38,85 @@ class SubmissionStatus(Enum):
40
  return SubmissionStatus.PENDING
41
 
42
 
 
 
 
 
 
 
 
 
 
 
 
43
  DROPDOWN_OPTIONS = [status.value[0] for status in SubmissionStatus]
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def create_submissions(submission_filters: list[str]) -> gr.Dataframe:
47
  data: list[list] = []
48
  sync_chain()
 
1
+ from collections import defaultdict
2
  from enum import Enum
3
 
4
  import gradio as gr
5
  import pandas as pd
6
+ import plotly.graph_objects as go
7
 
8
  from chain_data import sync_chain, fetch_commitments
9
  from src import Key
 
20
 
21
  @staticmethod
22
  def get_status(run: Run, hotkey: Key, coldkey: Key, block: int, revision: str) -> "SubmissionStatus":
23
+ if is_blacklisted(hotkey, coldkey):
 
24
  return SubmissionStatus.BLACKLISTED
25
 
26
+ if is_duplicate_submission(hotkey, revision):
 
 
 
27
  return SubmissionStatus.DUPLICATE
28
 
29
  if hotkey in run.submissions and block > run.submissions[hotkey].info.block and hotkey not in run.invalid_submissions:
 
38
  return SubmissionStatus.PENDING
39
 
40
 
41
+ def is_blacklisted(hotkey: Key, coldkey: Key) -> bool:
42
+ return hotkey in get_blacklisted_keys().hotkeys or coldkey in get_blacklisted_keys().coldkeys
43
+
44
+
45
+ def is_duplicate_submission(hotkey: Key, revision: str) -> bool:
46
+ return not any(
47
+ submission.hotkey == hotkey and submission.revision == revision
48
+ for submission in get_blacklisted_keys().duplicate_selection.safe_submissions
49
+ )
50
+
51
+
52
  DROPDOWN_OPTIONS = [status.value[0] for status in SubmissionStatus]
53
 
54
 
55
+ def create_duplicate_submissions_plot() -> gr.Plot:
56
+ sync_chain()
57
+
58
+ submissions_by_coldkey = defaultdict(lambda: ([], []))
59
+
60
+ for hotkey, commitment in fetch_commitments().items():
61
+ neuron = get_neurons().get(hotkey)
62
+ if not neuron:
63
+ continue
64
+
65
+ coldkey = neuron.coldkey
66
+
67
+ if is_blacklisted(hotkey, coldkey):
68
+ continue
69
+
70
+ if is_duplicate_submission(hotkey, commitment.revision):
71
+ submissions_by_coldkey[coldkey][0].append(commitment)
72
+ else:
73
+ submissions_by_coldkey[coldkey][1].append(commitment)
74
+
75
+ submissions_by_coldkey = dict(sorted(
76
+ submissions_by_coldkey.items(),
77
+ key=lambda x: len(x[1][0]) + len(x[1][1]),
78
+ reverse=True
79
+ ))
80
+
81
+ figure = go.Figure()
82
+
83
+ for coldkey, (duplicate_commitments, safe_commitments) in submissions_by_coldkey.items():
84
+ urls_safe = [c.url for c in safe_commitments]
85
+ figure.add_trace(go.Bar(
86
+ x=[f"{coldkey[:6]}..."],
87
+ y=[len(safe_commitments)],
88
+ name="Safe",
89
+ marker_color="green", # type: ignore
90
+ hovertemplate="<br>".join([
91
+ "Submissions (%{y}):<br>" + "<br>".join(urls_safe)
92
+ ]) + "<extra></extra>"
93
+ ))
94
+
95
+ urls_duplicate = [c.url for c in duplicate_commitments]
96
+ figure.add_trace(go.Bar(
97
+ x=[f"{coldkey[:6]}..."],
98
+ y=[len(duplicate_commitments)],
99
+ name="Duplicate",
100
+ marker_color="red", # type: ignore
101
+ hovertemplate="<br>".join([
102
+ "Submissions (%{y}):<br>" + "<br>".join(urls_duplicate)
103
+ ]) + "<extra></extra>"
104
+ ))
105
+
106
+ figure.update_layout(
107
+ title="Duplicate Submissions",
108
+ xaxis_title="Coldkey",
109
+ yaxis_title="# of Submissions",
110
+ barmode="stack",
111
+ showlegend=False,
112
+ autosize=True,
113
+ margin=dict(l=50, r=50, t=50, b=50),
114
+ template="plotly_dark"
115
+ )
116
+
117
+ return gr.Plot(figure)
118
+
119
+
120
  def create_submissions(submission_filters: list[str]) -> gr.Dataframe:
121
  data: list[list] = []
122
  sync_chain()