Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize weights in r get weights table #1556

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import torch
import typing
import argparse
import numpy as np
import bittensor
from typing import List, Optional, Dict
from rich.prompt import Prompt, Confirm
Expand Down Expand Up @@ -222,35 +223,52 @@ def run(cli):
table = Table(show_footer=False)
table.title = "[white]Root Network Weights"
table.add_column(
"[overline white]UID",
"[white]UID",
header_style="overline white",
footer_style="overline white",
style="rgb(50,163,219)",
no_wrap=True,
)
table.add_column(
"[overline white]NETUID",
footer_style="overline white",
justify="right",
style="green",
no_wrap=True,
)
table.add_column(
"[overline white]WEIGHT",
footer_style="overline white",
justify="right",
style="green",
no_wrap=True,
)
table.show_footer = True

uid_to_weights = {}
netuids = set()
for matrix in weights:
uid = matrix[0]
for weight_data in matrix[1]:
table.add_row(
str(uid),
str(weight_data[0]),
"{:0.2f}%".format((weight_data[1] / 65535) * 100),
)
[uid, weights_data] = matrix

normalized_weights = np.array(weights_data)[:, 1] / max(
np.sum(weights_data, axis=0)[1], 1
)
for weight_data, normalized_weight in zip(weights_data, normalized_weights):
[netuid, _] = weight_data
netuids.add(netuid)
if uid not in uid_to_weights:
uid_to_weights[uid] = {}

uid_to_weights[uid][netuid] = normalized_weight

for netuid in netuids:
table.add_column(
f"[white]{netuid}",
header_style="overline white",
footer_style="overline white",
justify="right",
style="green",
no_wrap=True,
)

for uid in uid_to_weights:
row = [str(uid)]

uid_weights = uid_to_weights[uid]
for netuid in netuids:
if netuid in uid_weights:
normalized_weight = uid_weights[netuid]
row.append("{:0.2f}%".format(normalized_weight * 100))
else:
row.append("-")
table.add_row(*row)

table.show_footer = True

table.box = None
table.pad_edge = False
Expand Down