Spaces:
Runtime error
Runtime error
validator stats
Browse files
app.py
CHANGED
@@ -30,7 +30,6 @@ METAGRAPH_RETRIES = 5
|
|
30 |
METAGRAPH_DELAY_SECS = 3
|
31 |
NETUID = 6
|
32 |
SUBNET_START_BLOCK = 2225782
|
33 |
-
MIN_INCENTIVE_THRESHOLD = 0.01
|
34 |
SECONDS_PER_BLOCK = 12
|
35 |
|
36 |
def get_subtensor_and_metagraph() -> typing.Tuple[bt.subtensor, bt.metagraph]:
|
@@ -83,16 +82,19 @@ def get_tao_price() -> float:
|
|
83 |
time.sleep(METAGRAPH_DELAY_SECS)
|
84 |
raise RuntimeError()
|
85 |
|
86 |
-
def
|
|
|
87 |
for uid in metagraph.uids.tolist():
|
88 |
-
|
89 |
-
|
|
|
90 |
for ouid in metagraph.uids.tolist():
|
91 |
if ouid == uid:
|
92 |
continue
|
93 |
weight = round(metagraph.weights[uid][ouid].item(), 4)
|
94 |
if weight > 0:
|
95 |
-
|
|
|
96 |
|
97 |
def get_subnet_data(subtensor: bt.subtensor, metagraph: bt.metagraph) -> typing.List[ModelData]:
|
98 |
result = []
|
@@ -136,7 +138,6 @@ def get_float_score(key: str, history) -> typing.Tuple[typing.Optional[float], b
|
|
136 |
def get_scores(uids: typing.List[int]) -> typing.Dict[int, typing.Dict[str, typing.Optional[float]]]:
|
137 |
api = wandb.Api()
|
138 |
runs = list(api.runs(VALIDATOR_WANDB_PROJECT))
|
139 |
-
print(f"Top validator run: {runs[0].name}")
|
140 |
|
141 |
result = {}
|
142 |
for run in runs:
|
@@ -174,7 +175,6 @@ def next_tempo(start_block, tempo, block):
|
|
174 |
return nearest_num
|
175 |
|
176 |
subtensor, metagraph = get_subtensor_and_metagraph()
|
177 |
-
print_validator_weights(metagraph)
|
178 |
|
179 |
tao_price = get_tao_price()
|
180 |
|
@@ -193,6 +193,11 @@ blocks_to_go = next_update - current_block
|
|
193 |
current_time = datetime.datetime.now()
|
194 |
next_update_time = current_time + datetime.timedelta(seconds=blocks_to_go * SECONDS_PER_BLOCK)
|
195 |
|
|
|
|
|
|
|
|
|
|
|
196 |
def get_next_update():
|
197 |
now = datetime.datetime.now()
|
198 |
delta = next_update_time - now
|
@@ -201,7 +206,7 @@ def get_next_update():
|
|
201 |
def leaderboard_data(show_stale: bool):
|
202 |
value = [
|
203 |
[
|
204 |
-
f'[{c.namespace}/{c.name} ({c.commit[
|
205 |
format_score(c.uid, scores, "win_rate"),
|
206 |
format_score(c.uid, scores, "avg_loss"),
|
207 |
format_score(c.uid, scores, "weight"),
|
@@ -221,7 +226,7 @@ with demo:
|
|
221 |
gr.HTML(value=get_next_update())
|
222 |
|
223 |
gr.Label(
|
224 |
-
value={ f"{c.namespace}/{c.name} ({c.commit[
|
225 |
num_top_classes=10,
|
226 |
)
|
227 |
|
@@ -239,6 +244,22 @@ with demo:
|
|
239 |
gr.HTML(EVALUATION_DETAILS)
|
240 |
show_stale.change(leaderboard_data, [show_stale], leaderboard_table)
|
241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
def restart_space():
|
243 |
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
|
244 |
|
|
|
30 |
METAGRAPH_DELAY_SECS = 3
|
31 |
NETUID = 6
|
32 |
SUBNET_START_BLOCK = 2225782
|
|
|
33 |
SECONDS_PER_BLOCK = 12
|
34 |
|
35 |
def get_subtensor_and_metagraph() -> typing.Tuple[bt.subtensor, bt.metagraph]:
|
|
|
82 |
time.sleep(METAGRAPH_DELAY_SECS)
|
83 |
raise RuntimeError()
|
84 |
|
85 |
+
def get_validator_weights(metagraph: bt.metagraph) -> typing.Dict[int, typing.Tuple[float, int, typing.Dict[int, float]]]:
|
86 |
+
ret = {}
|
87 |
for uid in metagraph.uids.tolist():
|
88 |
+
vtrust = metagraph.validator_trust[uid].item()
|
89 |
+
if vtrust > 0:
|
90 |
+
ret[uid] = (vtrust, metagraph.S[uid].item(), {})
|
91 |
for ouid in metagraph.uids.tolist():
|
92 |
if ouid == uid:
|
93 |
continue
|
94 |
weight = round(metagraph.weights[uid][ouid].item(), 4)
|
95 |
if weight > 0:
|
96 |
+
ret[uid][-1][ouid] = weight
|
97 |
+
return ret
|
98 |
|
99 |
def get_subnet_data(subtensor: bt.subtensor, metagraph: bt.metagraph) -> typing.List[ModelData]:
|
100 |
result = []
|
|
|
138 |
def get_scores(uids: typing.List[int]) -> typing.Dict[int, typing.Dict[str, typing.Optional[float]]]:
|
139 |
api = wandb.Api()
|
140 |
runs = list(api.runs(VALIDATOR_WANDB_PROJECT))
|
|
|
141 |
|
142 |
result = {}
|
143 |
for run in runs:
|
|
|
175 |
return nearest_num
|
176 |
|
177 |
subtensor, metagraph = get_subtensor_and_metagraph()
|
|
|
178 |
|
179 |
tao_price = get_tao_price()
|
180 |
|
|
|
193 |
current_time = datetime.datetime.now()
|
194 |
next_update_time = current_time + datetime.timedelta(seconds=blocks_to_go * SECONDS_PER_BLOCK)
|
195 |
|
196 |
+
validator_df = get_validator_weights(metagraph)
|
197 |
+
weight_keys = set()
|
198 |
+
for uid, stats in validator_df.items():
|
199 |
+
weight_keys.update(stats[-1].keys())
|
200 |
+
|
201 |
def get_next_update():
|
202 |
now = datetime.datetime.now()
|
203 |
delta = next_update_time - now
|
|
|
206 |
def leaderboard_data(show_stale: bool):
|
207 |
value = [
|
208 |
[
|
209 |
+
f'[{c.namespace}/{c.name} ({c.commit[0:8]})](https://huggingface.co/{c.namespace}/{c.name}/commit/{c.commit})',
|
210 |
format_score(c.uid, scores, "win_rate"),
|
211 |
format_score(c.uid, scores, "avg_loss"),
|
212 |
format_score(c.uid, scores, "weight"),
|
|
|
226 |
gr.HTML(value=get_next_update())
|
227 |
|
228 |
gr.Label(
|
229 |
+
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},
|
230 |
num_top_classes=10,
|
231 |
)
|
232 |
|
|
|
244 |
gr.HTML(EVALUATION_DETAILS)
|
245 |
show_stale.change(leaderboard_data, [show_stale], leaderboard_table)
|
246 |
|
247 |
+
with gr.Accordion("Validator Stats"):
|
248 |
+
validator_table = gr.components.Dataframe(
|
249 |
+
value=[
|
250 |
+
[uid, int(validator_df[uid][1]), round(validator_df[uid][0], 4)] + [validator_df[uid][-1].get(c.uid) for c in leaderboard_df if c.incentive]
|
251 |
+
for uid, _ in sorted(
|
252 |
+
zip(validator_df.keys(), [validator_df[x][1] for x in validator_df.keys()]),
|
253 |
+
key=lambda x: x[1],
|
254 |
+
reverse=True
|
255 |
+
)
|
256 |
+
],
|
257 |
+
headers=["UID", "Stake (τ)", "V-Trust"] + [f"{c.namespace}/{c.name} ({c.commit[0:8]})" for c in leaderboard_df if c.incentive],
|
258 |
+
datatype=["number", "number", "number"] + ["number" for c in leaderboard_df if c.incentive],
|
259 |
+
interactive=False,
|
260 |
+
visible=True,
|
261 |
+
)
|
262 |
+
|
263 |
def restart_space():
|
264 |
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
|
265 |
|