Spaces:
Running
Running
Commit
·
4ebccb1
1
Parent(s):
872d532
Switch to fiber
Browse files- requirements.txt +2 -2
- src/chain_data.py +79 -46
- src/validator_states.py +3 -3
- src/validator_weights.py +16 -18
- src/wandb_data.py +3 -2
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
|
2 |
-
gradio==5.
|
3 |
wandb==0.18.5
|
4 |
substrate-interface==1.7.10
|
5 |
plotly==5.24.1
|
|
|
1 |
+
fiber @ git+https://github.com/rayonlabs/fiber.git@1.0.0#egg=fiber[chain]
|
2 |
+
gradio==5.5.0
|
3 |
wandb==0.18.5
|
4 |
substrate-interface==1.7.10
|
5 |
plotly==5.24.1
|
src/chain_data.py
CHANGED
@@ -1,69 +1,100 @@
|
|
1 |
from concurrent.futures import ThreadPoolExecutor
|
2 |
from datetime import datetime, timedelta
|
|
|
3 |
from typing import TypeAlias
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
-
from wandb_data import Uid, TIMEZONE
|
8 |
|
9 |
Weight: TypeAlias = float
|
10 |
Incentive: TypeAlias = float
|
11 |
|
12 |
NET_UID = 39
|
13 |
-
WEIGHTS_BY_MINER:
|
14 |
-
|
15 |
-
|
16 |
-
VTRUST: dict[Uid, float] = {}
|
17 |
-
UPDATED: dict[Uid, int] = {}
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
|
|
|
|
22 |
|
23 |
-
def fetch_weights():
|
24 |
-
WEIGHTS_BY_MINER.clear()
|
25 |
-
weights = subtensor.weights(netuid=NET_UID)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
weight = miner_weight[1] / 2 ** 16
|
37 |
-
break
|
38 |
-
WEIGHTS_BY_MINER[miner_uid].append((validator_uid, weight))
|
39 |
|
40 |
|
41 |
-
def
|
42 |
-
|
43 |
-
for i in range(len(metagraph.incentive)):
|
44 |
-
INCENTIVES[i] = metagraph.incentive[i]
|
45 |
|
46 |
|
47 |
-
def
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
def fetch_updated(block: int):
|
54 |
UPDATED.clear()
|
55 |
-
for
|
56 |
-
UPDATED[
|
57 |
|
58 |
|
59 |
-
def fetch_identities():
|
60 |
VALIDATOR_IDENTITIES.clear()
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
|
69 |
last_sync: datetime = datetime.fromtimestamp(0, TIMEZONE)
|
@@ -79,12 +110,14 @@ def sync_metagraph(timeout: int = 10):
|
|
79 |
|
80 |
def sync_task():
|
81 |
print("Syncing metagraph...")
|
82 |
-
block =
|
83 |
-
metagraph.
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
fetch_weights()
|
86 |
-
fetch_incentives()
|
87 |
-
fetch_vtrust()
|
88 |
fetch_updated(block)
|
89 |
|
90 |
global last_identity_sync
|
@@ -92,7 +125,7 @@ def sync_metagraph(timeout: int = 10):
|
|
92 |
return
|
93 |
|
94 |
last_identity_sync = now
|
95 |
-
fetch_identities()
|
96 |
|
97 |
with ThreadPoolExecutor(max_workers=1) as executor:
|
98 |
future = executor.submit(sync_task)
|
|
|
1 |
from concurrent.futures import ThreadPoolExecutor
|
2 |
from datetime import datetime, timedelta
|
3 |
+
from math import ceil
|
4 |
from typing import TypeAlias
|
5 |
|
6 |
+
from fiber.chain.interface import get_substrate
|
7 |
+
from fiber.chain.metagraph import Metagraph
|
8 |
+
from fiber.chain.models import Node
|
9 |
+
from substrateinterface.storage import StorageKey
|
10 |
|
11 |
+
from wandb_data import Hotkey, Uid, TIMEZONE
|
12 |
|
13 |
Weight: TypeAlias = float
|
14 |
Incentive: TypeAlias = float
|
15 |
|
16 |
NET_UID = 39
|
17 |
+
WEIGHTS_BY_MINER: dict[Hotkey, list[tuple[Hotkey, Weight]]] = {}
|
18 |
+
VALIDATOR_IDENTITIES: dict[Hotkey, str] = {}
|
19 |
+
UPDATED: dict[Hotkey, int] = {}
|
|
|
|
|
20 |
|
21 |
+
UIDS_BY_HOTKEY: dict[Hotkey, Uid] = {}
|
22 |
+
HOTKEYS_BY_UID: dict[Uid, Hotkey] = {}
|
23 |
|
24 |
+
substrate = get_substrate()
|
25 |
+
metagraph = Metagraph(substrate, netuid=NET_UID, load_old_nodes=False)
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
+
def query_subtensor(storage_keys: list[StorageKey], block: int) -> list:
|
29 |
+
global substrate
|
30 |
+
try:
|
31 |
+
return substrate.query_multi(
|
32 |
+
storage_keys=storage_keys,
|
33 |
+
block_hash=substrate.get_block_hash(block),
|
34 |
+
)
|
35 |
+
except Exception:
|
36 |
+
substrate = get_substrate()
|
37 |
+
raise
|
38 |
|
39 |
+
|
40 |
+
def is_validator(node: Node) -> bool:
|
41 |
+
return node.vtrust > 0 or node.stake > 10_000
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
+
def get_nodes() -> dict[Hotkey, Node]:
|
45 |
+
return metagraph.nodes
|
|
|
|
|
46 |
|
47 |
|
48 |
+
def fetch_weights(block: int):
|
49 |
+
WEIGHTS_BY_MINER.clear()
|
50 |
+
storage_keys: list[StorageKey] = []
|
51 |
+
for hotkey, node in metagraph.nodes.items():
|
52 |
+
if not is_validator(node): continue
|
53 |
+
storage_keys.append(substrate.create_storage_key(
|
54 |
+
"SubtensorModule",
|
55 |
+
"Weights",
|
56 |
+
[metagraph.netuid, UIDS_BY_HOTKEY[node.hotkey]]
|
57 |
+
))
|
58 |
+
|
59 |
+
weights = query_subtensor(storage_keys, block)
|
60 |
+
|
61 |
+
for hotkey, node in metagraph.nodes.items():
|
62 |
+
for storage, validator_weights in weights:
|
63 |
+
validator_hotkey = HOTKEYS_BY_UID[storage.params[1]]
|
64 |
+
if hotkey not in WEIGHTS_BY_MINER:
|
65 |
+
WEIGHTS_BY_MINER[hotkey] = []
|
66 |
+
weight = 0.0
|
67 |
+
for miner_weight in validator_weights:
|
68 |
+
if miner_weight[0].value == UIDS_BY_HOTKEY[hotkey]:
|
69 |
+
weight = miner_weight[1].value / 2 ** 16
|
70 |
+
break
|
71 |
+
WEIGHTS_BY_MINER[hotkey].append((validator_hotkey, weight))
|
72 |
|
73 |
|
74 |
def fetch_updated(block: int):
|
75 |
UPDATED.clear()
|
76 |
+
for hotkey, node in metagraph.nodes.items():
|
77 |
+
UPDATED[hotkey] = ceil(block - node.last_updated)
|
78 |
|
79 |
|
80 |
+
def fetch_identities(block: int):
|
81 |
VALIDATOR_IDENTITIES.clear()
|
82 |
+
storage_keys: list[StorageKey] = []
|
83 |
+
for hotkey, node in metagraph.nodes.items():
|
84 |
+
if not is_validator(node): continue
|
85 |
+
storage_keys.append(substrate.create_storage_key(
|
86 |
+
"SubtensorModule",
|
87 |
+
"Identities",
|
88 |
+
[node.coldkey]
|
89 |
+
))
|
90 |
+
|
91 |
+
identities = query_subtensor(storage_keys, block)
|
92 |
+
for hotkey, node in metagraph.nodes.items():
|
93 |
+
for storage, info in identities:
|
94 |
+
if node.coldkey != storage.params[0]: continue
|
95 |
+
if info != None: # noqa
|
96 |
+
VALIDATOR_IDENTITIES[hotkey] = info.value["name"]
|
97 |
+
break
|
98 |
|
99 |
|
100 |
last_sync: datetime = datetime.fromtimestamp(0, TIMEZONE)
|
|
|
110 |
|
111 |
def sync_task():
|
112 |
print("Syncing metagraph...")
|
113 |
+
block = substrate.get_block_number(None) # type: ignore
|
114 |
+
metagraph.sync_nodes()
|
115 |
+
|
116 |
+
for uid, node in enumerate(metagraph.nodes.values()):
|
117 |
+
UIDS_BY_HOTKEY[node.hotkey] = uid
|
118 |
+
HOTKEYS_BY_UID[uid] = node.hotkey
|
119 |
|
120 |
+
fetch_weights(block)
|
|
|
|
|
121 |
fetch_updated(block)
|
122 |
|
123 |
global last_identity_sync
|
|
|
125 |
return
|
126 |
|
127 |
last_identity_sync = now
|
128 |
+
fetch_identities(block)
|
129 |
|
130 |
with ThreadPoolExecutor(max_workers=1) as executor:
|
131 |
future = executor.submit(sync_task)
|
src/validator_states.py
CHANGED
@@ -6,7 +6,7 @@ import pandas as pd
|
|
6 |
from packaging import version
|
7 |
|
8 |
from wandb_data import get_current_runs, Run
|
9 |
-
from chain_data import
|
10 |
|
11 |
AVERAGE_BENCHMARK_TIME_WARNING_THRESHOLD = 180 # 3 minutes
|
12 |
ETA_WARNING_THRESHOLD = 43200 # 12 hours
|
@@ -34,8 +34,8 @@ def create_validator_states() -> gr.Dataframe:
|
|
34 |
winner_uid_mode = statistics.mode(winners) if winners else None
|
35 |
latest_version = get_latest_version(runs)
|
36 |
for run in runs:
|
37 |
-
vtrust =
|
38 |
-
updated = UPDATED.get(run.
|
39 |
data.append([
|
40 |
run.uid,
|
41 |
run.name,
|
|
|
6 |
from packaging import version
|
7 |
|
8 |
from wandb_data import get_current_runs, Run
|
9 |
+
from chain_data import get_nodes, UPDATED
|
10 |
|
11 |
AVERAGE_BENCHMARK_TIME_WARNING_THRESHOLD = 180 # 3 minutes
|
12 |
ETA_WARNING_THRESHOLD = 43200 # 12 hours
|
|
|
34 |
winner_uid_mode = statistics.mode(winners) if winners else None
|
35 |
latest_version = get_latest_version(runs)
|
36 |
for run in runs:
|
37 |
+
vtrust = get_nodes().get(run.hotkey, 0).vtrust
|
38 |
+
updated = UPDATED.get(run.hotkey, 0)
|
39 |
data.append([
|
40 |
run.uid,
|
41 |
run.name,
|
src/validator_weights.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
-
from chain_data import WEIGHTS_BY_MINER,
|
5 |
-
from wandb_data import
|
6 |
|
7 |
|
8 |
def get_color_by_weight(weight: float) -> str:
|
@@ -22,16 +22,16 @@ def get_color_by_weight(weight: float) -> str:
|
|
22 |
g = int(255 - ((1 - progress) * 50))
|
23 |
return f"rgb(0, {g}, 0)"
|
24 |
|
25 |
-
def get_active_weights() ->
|
26 |
runs = get_current_runs()
|
27 |
-
weights:
|
28 |
|
29 |
-
for
|
30 |
-
new_weights: list[tuple[
|
31 |
-
for
|
32 |
-
if
|
33 |
-
new_weights.append((
|
34 |
-
weights
|
35 |
|
36 |
return weights
|
37 |
|
@@ -45,19 +45,17 @@ def create_weights(include_inactive: bool) -> gr.Dataframe:
|
|
45 |
weights = WEIGHTS_BY_MINER if include_inactive else get_active_weights()
|
46 |
|
47 |
validator_uids = set()
|
48 |
-
for validator_weights in weights:
|
49 |
-
for
|
50 |
-
validator_uids.add(
|
51 |
|
52 |
for validator_uid in sorted(validator_uids):
|
53 |
headers.append(str(validator_uid))
|
54 |
datatype.append("markdown")
|
55 |
|
56 |
-
for
|
57 |
-
|
58 |
-
|
59 |
-
incentive = INCENTIVES[miner_uid]
|
60 |
-
row = [miner_uid, f"<span style='color: {get_color_by_weight(incentive)}'>{incentive:.{3}f}</span>"]
|
61 |
for _, weight in validator_weights:
|
62 |
row.append(f"<span style='color: {get_color_by_weight(weight)}'>{weight:.{3}f}</span>")
|
63 |
data.append(row)
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
+
from chain_data import WEIGHTS_BY_MINER, UIDS_BY_HOTKEY, get_nodes, sync_metagraph, Weight
|
5 |
+
from wandb_data import Hotkey, get_current_runs
|
6 |
|
7 |
|
8 |
def get_color_by_weight(weight: float) -> str:
|
|
|
22 |
g = int(255 - ((1 - progress) * 50))
|
23 |
return f"rgb(0, {g}, 0)"
|
24 |
|
25 |
+
def get_active_weights() -> dict[Hotkey, list[tuple[Hotkey, Weight]]]:
|
26 |
runs = get_current_runs()
|
27 |
+
weights: dict[Hotkey, list[tuple[Hotkey, Weight]]] = {}
|
28 |
|
29 |
+
for hotkey, validator_weights in WEIGHTS_BY_MINER.items():
|
30 |
+
new_weights: list[tuple[Hotkey, Weight]] = []
|
31 |
+
for validator_hotkey, weight in validator_weights:
|
32 |
+
if validator_hotkey in [run.hotkey for run in runs]:
|
33 |
+
new_weights.append((validator_hotkey, weight))
|
34 |
+
weights[hotkey] = new_weights
|
35 |
|
36 |
return weights
|
37 |
|
|
|
45 |
weights = WEIGHTS_BY_MINER if include_inactive else get_active_weights()
|
46 |
|
47 |
validator_uids = set()
|
48 |
+
for _, validator_weights in weights.items():
|
49 |
+
for validator_hotkey, _ in validator_weights:
|
50 |
+
validator_uids.add(UIDS_BY_HOTKEY[validator_hotkey])
|
51 |
|
52 |
for validator_uid in sorted(validator_uids):
|
53 |
headers.append(str(validator_uid))
|
54 |
datatype.append("markdown")
|
55 |
|
56 |
+
for hotkey, validator_weights in weights.items():
|
57 |
+
incentive = get_nodes().get(hotkey, 0).incentive / 2 ** 16
|
58 |
+
row = [UIDS_BY_HOTKEY[hotkey], f"<span style='color: {get_color_by_weight(incentive)}'>{incentive:.{3}f}</span>"]
|
|
|
|
|
59 |
for _, weight in validator_weights:
|
60 |
row.append(f"<span style='color: {get_color_by_weight(weight)}'>{weight:.{3}f}</span>")
|
61 |
data.append(row)
|
src/wandb_data.py
CHANGED
@@ -16,6 +16,7 @@ TIMEZONE = ZoneInfo("America/Los_Angeles")
|
|
16 |
START_DATE = datetime(2024, 11, 9)
|
17 |
|
18 |
Uid: TypeAlias = int
|
|
|
19 |
|
20 |
|
21 |
class BenchmarkStatus(Enum):
|
@@ -50,7 +51,7 @@ class MetricData:
|
|
50 |
@dataclass
|
51 |
class SubmissionInfo:
|
52 |
uid: int
|
53 |
-
hotkey:
|
54 |
repository: str
|
55 |
revision: str
|
56 |
block: int
|
@@ -207,7 +208,7 @@ def _add_runs(wandb_runs: list[wapi.Run]):
|
|
207 |
start_date=date,
|
208 |
version=wandb_run.tags[1][8:],
|
209 |
uid=uid,
|
210 |
-
name=VALIDATOR_IDENTITIES.get(
|
211 |
hotkey=hotkey,
|
212 |
status=status,
|
213 |
average_benchmark_time=average_benchmark_time,
|
|
|
16 |
START_DATE = datetime(2024, 11, 9)
|
17 |
|
18 |
Uid: TypeAlias = int
|
19 |
+
Hotkey: TypeAlias = str
|
20 |
|
21 |
|
22 |
class BenchmarkStatus(Enum):
|
|
|
51 |
@dataclass
|
52 |
class SubmissionInfo:
|
53 |
uid: int
|
54 |
+
hotkey: Hotkey
|
55 |
repository: str
|
56 |
revision: str
|
57 |
block: int
|
|
|
208 |
start_date=date,
|
209 |
version=wandb_run.tags[1][8:],
|
210 |
uid=uid,
|
211 |
+
name=VALIDATOR_IDENTITIES.get(hotkey, f"{hotkey[:6]}..."),
|
212 |
hotkey=hotkey,
|
213 |
status=status,
|
214 |
average_benchmark_time=average_benchmark_time,
|