Spaces:
Runtime error
Runtime error
guard and retry metagraph sync, filter out models without loss
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import wandb
|
|
8 |
import math
|
9 |
import os
|
10 |
import statistics
|
|
|
11 |
from dotenv import load_dotenv
|
12 |
from huggingface_hub import HfApi
|
13 |
from apscheduler.schedulers.background import BackgroundScheduler
|
@@ -23,9 +24,20 @@ H4_TOKEN = os.environ.get("H4_TOKEN", None)
|
|
23 |
API = HfApi(token=H4_TOKEN)
|
24 |
REPO_ID = "NousResearch/finetuning_subnet_leaderboard"
|
25 |
MAX_AVG_LOSS_POINTS = 5
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
@dataclass
|
31 |
class ModelData:
|
@@ -69,7 +81,7 @@ def print_validator_weights(metagraph: bt.metagraph):
|
|
69 |
if weight > 0:
|
70 |
print(f" {ouid} = {weight}")
|
71 |
|
72 |
-
def get_subnet_data(metagraph: bt.metagraph) -> typing.List[ModelData]:
|
73 |
result = []
|
74 |
for uid in metagraph.uids.tolist():
|
75 |
hotkey = metagraph.hotkeys[uid]
|
@@ -113,10 +125,11 @@ def get_avg_loss(uids: typing.List[int]) -> typing.Dict[int, float]:
|
|
113 |
break
|
114 |
return result
|
115 |
|
|
|
116 |
|
117 |
tao_price = get_tao_price()
|
118 |
|
119 |
-
leaderboard_df = get_subnet_data(metagraph)
|
120 |
leaderboard_df.sort(key=lambda x: x.incentive, reverse=True)
|
121 |
|
122 |
losses = get_avg_loss([x.uid for x in leaderboard_df])
|
@@ -137,6 +150,7 @@ with demo:
|
|
137 |
c.block
|
138 |
] for c in leaderboard_df
|
139 |
]
|
|
|
140 |
leaderboard_table = gr.components.Dataframe(
|
141 |
value=value,
|
142 |
headers=["Name", "Rewards / Day", "Last Average Loss", "UID", "Block"],
|
|
|
8 |
import math
|
9 |
import os
|
10 |
import statistics
|
11 |
+
import time
|
12 |
from dotenv import load_dotenv
|
13 |
from huggingface_hub import HfApi
|
14 |
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
24 |
API = HfApi(token=H4_TOKEN)
|
25 |
REPO_ID = "NousResearch/finetuning_subnet_leaderboard"
|
26 |
MAX_AVG_LOSS_POINTS = 5
|
27 |
+
METAGRAPH_RETRIES = 5
|
28 |
+
METAGRAPH_DELAY_SECS = 3
|
29 |
|
30 |
+
def get_subtensor_and_metagraph() -> typing.Tuple[bt.subtensor, bt.metagraph]:
|
31 |
+
subtensor: bt.subtensor = bt.subtensor("finney")
|
32 |
+
for i in range(0, METAGRAPH_RETRIES):
|
33 |
+
try:
|
34 |
+
metagraph: bt.metagraph = subtensor.metagraph(6, lite=False)
|
35 |
+
return subtensor, metagraph
|
36 |
+
except:
|
37 |
+
if i == METAGRAPH_RETRIES - 1:
|
38 |
+
raise
|
39 |
+
time.sleep(METAGRAPH_DELAY_SECS)
|
40 |
+
raise RuntimeError()
|
41 |
|
42 |
@dataclass
|
43 |
class ModelData:
|
|
|
81 |
if weight > 0:
|
82 |
print(f" {ouid} = {weight}")
|
83 |
|
84 |
+
def get_subnet_data(subtensor: bt.subtensor, metagraph: bt.metagraph) -> typing.List[ModelData]:
|
85 |
result = []
|
86 |
for uid in metagraph.uids.tolist():
|
87 |
hotkey = metagraph.hotkeys[uid]
|
|
|
125 |
break
|
126 |
return result
|
127 |
|
128 |
+
subtensor, metagraph = get_subtensor_and_metagraph()
|
129 |
|
130 |
tao_price = get_tao_price()
|
131 |
|
132 |
+
leaderboard_df = get_subnet_data(subtensor, metagraph)
|
133 |
leaderboard_df.sort(key=lambda x: x.incentive, reverse=True)
|
134 |
|
135 |
losses = get_avg_loss([x.uid for x in leaderboard_df])
|
|
|
150 |
c.block
|
151 |
] for c in leaderboard_df
|
152 |
]
|
153 |
+
value = [x for x in value if x[2] != ""] # filter out anything without a loss
|
154 |
leaderboard_table = gr.components.Dataframe(
|
155 |
value=value,
|
156 |
headers=["Name", "Rewards / Day", "Last Average Loss", "UID", "Block"],
|