Skip to content

Commit

Permalink
Allow set subnet specific hyper parameters. (#1745)
Browse files Browse the repository at this point in the history
* Allowed for display and setting of AdjustmentAlpha

* Added adjustment_alpha value settings

* Added difficulty

* Fixed setting difficulty errors

* wallet typing

* Removed subnet info changes

* black and test fixes

* Fixed subnet_info

* version update

* changelog and black

---------

Co-authored-by: Ala Shaabana <ala@bittensor.com>
Co-authored-by: Eugene <etesting007@gmail.com>
  • Loading branch information
3 people committed Mar 12, 2024
1 parent 9e7e872 commit 0759f6a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.9.3 / 2024-03-12

## What's Changed
* Release/6.9.2 by @ifrit98 in https://github.com/opentensor/bittensor/pull/1743


**Full Changelog**: https://github.com/opentensor/bittensor/compare/v6.9.2...v6.9.3


## 6.9.2 / 2024-03-08

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.9.2
6.9.3
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
nest_asyncio.apply()

# Bittensor code and protocol version.
__version__ = "6.9.2"
__version__ = "6.9.3"

version_split = __version__.split(".")
__version_as_int__: int = (
Expand Down
11 changes: 10 additions & 1 deletion bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
["max_regs_per_block", "Compact<u16>"],
["serving_rate_limit", "Compact<u64>"],
["max_validators", "Compact<u16>"],
["adjustment_alpha", "Compact<u64>"],
["difficulty", "Compact<u64>"],
],
},
}
Expand Down Expand Up @@ -882,6 +884,7 @@ class SubnetInfo:
emission_value: float
burn: Balance
owner_ss58: str
# adjustment_alpha: int

@classmethod
def from_vec_u8(cls, vec_u8: List[int]) -> Optional["SubnetInfo"]:
Expand Down Expand Up @@ -922,6 +925,8 @@ def fix_decoded_values(cls, decoded: Dict) -> "SubnetInfo":
max_allowed_validators=decoded["max_allowed_validators"],
min_allowed_weights=decoded["min_allowed_weights"],
max_weight_limit=decoded["max_weights_limit"],
# adjustment_alpha=decoded["adjustment_alpha"],
# bonds_moving_avg=decoded["bonds_moving_average"],
scaling_law_power=decoded["scaling_law_power"],
subnetwork_n=decoded["subnetwork_n"],
max_n=decoded["max_allowed_uids"],
Expand Down Expand Up @@ -975,6 +980,8 @@ class SubnetHyperparameters:
max_regs_per_block: int
serving_rate_limit: int
max_validators: int
adjustment_alpha: int
difficulty: int

@classmethod
def from_vec_u8(cls, vec_u8: List[int]) -> Optional["SubnetHyperparameters"]:
Expand Down Expand Up @@ -1023,10 +1030,12 @@ def fix_decoded_values(cls, decoded: Dict) -> "SubnetHyperparameters":
target_regs_per_interval=decoded["target_regs_per_interval"],
min_burn=decoded["min_burn"],
max_burn=decoded["max_burn"],
bonds_moving_avg=decoded["bonds_moving_avg"],
max_regs_per_block=decoded["max_regs_per_block"],
max_validators=decoded["max_validators"],
serving_rate_limit=decoded["serving_rate_limit"],
bonds_moving_avg=decoded["bonds_moving_avg"],
adjustment_alpha=decoded["adjustment_alpha"],
difficulty=decoded["difficulty"],
)

def to_parameter_dict(self) -> "torch.nn.ParameterDict":
Expand Down
5 changes: 5 additions & 0 deletions bittensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ def add_args(parser: argparse.ArgumentParser):
"network_pow_registration_allowed": "sudo_set_network_pow_registration_allowed",
"min_burn": "sudo_set_min_burn",
"max_burn": "sudo_set_max_burn",
"adjustment_alpha": "sudo_set_adjustment_alpha",
"rho": "sudo_set_rho",
"kappa": "sudo_set_kappa",
"difficulty": "sudo_set_difficulty",
"bonds_moving_avg": "sudo_set_bonds_moving_average",
}


Expand Down
4 changes: 2 additions & 2 deletions bittensor/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import sys
from rich.prompt import Prompt, Confirm
from rich.table import Table
from typing import Optional, List
from typing import Optional, List, Tuple
from . import defaults
import requests
from ..utils import RAOPERTAO
Expand Down Expand Up @@ -692,7 +692,7 @@ def check_config(config: "bittensor.Config"):
config.wallet.name = str(wallet_name)


def _get_coldkey_ss58_addresses_for_path(path: str) -> tuple[list[str], list[str]]:
def _get_coldkey_ss58_addresses_for_path(path: str) -> Tuple[List[str], List[str]]:
"""Get all coldkey ss58 addresses from path."""

def list_coldkeypub_files(dir_path):
Expand Down
8 changes: 8 additions & 0 deletions bittensor/mock/subtensor_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def setup(self) -> None:
"Prometheus": {},
"SubnetOwner": {},
"Commits": {},
"AdjustmentAlpha": {},
"BondsMovingAverage": {},
},
}

Expand Down Expand Up @@ -328,6 +330,7 @@ def create_subnet(self, netuid: int) -> None:
subtensor_state["BlocksSinceLastStep"][netuid][0] = 0
subtensor_state["Tempo"][netuid] = {}
subtensor_state["Tempo"][netuid][0] = 99

# subtensor_state['NetworkConnect'][netuid] = {}
# subtensor_state['NetworkConnect'][netuid][0] = {}
subtensor_state["EmissionValues"][netuid] = {}
Expand Down Expand Up @@ -364,6 +367,11 @@ def create_subnet(self, netuid: int) -> None:
subtensor_state["NetworksAdded"][netuid] = {}
subtensor_state["NetworksAdded"][netuid][0] = True

subtensor_state["AdjustmentAlpha"][netuid] = {}
subtensor_state["AdjustmentAlpha"][netuid][0] = 1000

subtensor_state["BondsMovingAverage"][netuid] = {}
subtensor_state["BondsMovingAverage"][netuid][0] = 1000
else:
raise Exception("Subnet already exists")

Expand Down
24 changes: 23 additions & 1 deletion bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
)
from .extrinsics.root import root_register_extrinsic, set_root_weights_extrinsic
from .types import AxonServeCallParams, PrometheusServeCallParams
from .utils import U16_NORMALIZED_FLOAT, ss58_to_vec_u8
from .utils import U16_NORMALIZED_FLOAT, ss58_to_vec_u8, U64_NORMALIZED_FLOAT
from .utils.balance import Balance
from .utils.registration import POWSolution

Expand Down Expand Up @@ -2858,6 +2858,28 @@ def max_weight_limit(
return None
return U16_NORMALIZED_FLOAT(_result.value)

def adjustment_alpha(
self, netuid: int, block: Optional[int] = None
) -> Optional[float]:
"""Returns network AdjustmentAlpha hyper parameter"""
if not self.subnet_exists(netuid, block):
return None
_result = self.query_subtensor("AdjustmentAlpha", block, [netuid])
if not hasattr(_result, "value") or _result is None:
return None
return U64_NORMALIZED_FLOAT(_result.value)

def bonds_moving_avg(
self, netuid: int, block: Optional[int] = None
) -> Optional[float]:
"""Returns network BondsMovingAverage hyper parameter"""
if not self.subnet_exists(netuid, block):
return None
_result = self.query_subtensor("BondsMovingAverage", block, [netuid])
if not hasattr(_result, "value") or _result is None:
return None
return U64_NORMALIZED_FLOAT(_result.value)

def scaling_law_power(
self, netuid: int, block: Optional[int] = None
) -> Optional[float]:
Expand Down

0 comments on commit 0759f6a

Please sign in to comment.