Skip to content

Commit

Permalink
Feat: Added normalized hyperparams
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor committed May 16, 2024
1 parent 44d1c24 commit fee2f1e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
14 changes: 11 additions & 3 deletions bittensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from rich.prompt import Prompt
from rich.table import Table
from typing import List, Optional, Dict
from .utils import get_delegates_details, DelegatesDetails, check_netuid_set
from .utils import (
get_delegates_details,
DelegatesDetails,
check_netuid_set,
normalize_hyperparameters,
)
from .identity import SetIdentityCommand

console = bittensor.__console__
Expand Down Expand Up @@ -489,9 +494,12 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
)
table.add_column("[overline white]HYPERPARAMETER", style="bold white")
table.add_column("[overline white]VALUE", style="green")
table.add_column("[overline white]NORMALIZED", style="cyan")

for param in subnet.__dict__:
table.add_row(" " + param, str(subnet.__dict__[param]))
normalized_values = normalize_hyperparameters(subnet)

for param, value, norm_value in normalized_values:
table.add_row(" " + param, value, norm_value)

bittensor.__console__.print(table)

Expand Down
48 changes: 47 additions & 1 deletion bittensor/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import os
import bittensor
import requests
from bittensor.utils import U64_NORMALIZED_FLOAT, U16_NORMALIZED_FLOAT
from bittensor.utils.balance import Balance
from bittensor.utils.registration import maybe_get_torch
from typing import List, Dict, Any, Optional
from typing import List, Dict, Any, Optional, Tuple
from rich.prompt import Confirm, PromptBase
from dataclasses import dataclass
from . import defaults
Expand Down Expand Up @@ -196,6 +198,50 @@ def filter_netuids_by_registered_hotkeys(
return list(set(netuids))


def normalize_hyperparameters(
subnet: bittensor.SubnetHyperparameters,
) -> List[Tuple[str, str, str]]:
"""
Normalizes the hyperparameters of a subnet.
Args:
subnet: The subnet hyperparameters object.
Returns:
A list of tuples containing the parameter name, value, and normalized value.
"""
param_mappings = {
"adjustment_alpha": U64_NORMALIZED_FLOAT,
"min_difficulty": U64_NORMALIZED_FLOAT,
"max_difficulty": U64_NORMALIZED_FLOAT,
"difficulty": U64_NORMALIZED_FLOAT,
"bonds_moving_avg": U64_NORMALIZED_FLOAT,
"max_weight_limit": U16_NORMALIZED_FLOAT,
"kappa": U16_NORMALIZED_FLOAT,
"min_burn": Balance.from_rao,
"max_burn": Balance.from_rao,
}

normalized_values: List[Tuple[str, str, str]] = []
subnet_dict = subnet.__dict__

for param, value in subnet_dict.items():
try:
if param in param_mappings:
norm_value = param_mappings[param](value)
if isinstance(norm_value, float):
norm_value = f"{norm_value:.{10}g}"
else:
norm_value = value
except Exception as e:
bittensor.logging.error(f"Error normalizing parameter '{param}': {e}")
norm_value = "-"

normalized_values.append((param, str(value), str(norm_value)))

return normalized_values


@dataclass
class DelegatesDetails:
name: str
Expand Down

0 comments on commit fee2f1e

Please sign in to comment.