Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4b94c2
feat: Implement Liquid Alpha Paramters
thealligatorking Jun 12, 2024
3e5701a
Added alpha hyperparams normalization
ibraheem-abe Jun 17, 2024
7ea74fc
Fixed if statement: filter_netuids_by_registered_hotkeys
ibraheem-abe Jun 17, 2024
ea58952
Merge pull request #2035 from opentensor/feat/abe/add-normalized-alpha
thealligatorking Jun 17, 2024
791da5e
Merge branch 'staging' into feature/gus/liquid-alpha-params
thealligatorking Jun 18, 2024
669bb2f
add hyperparam liquid_alpha_enabled
JohnReedV Jun 18, 2024
a2f7126
Add liquid alpha test
Jun 19, 2024
bf2f1c5
Add test to cli parameters to be within bounds.
Jun 20, 2024
e7ed3e2
Reset values for u16, u64.
Jun 20, 2024
0e52d52
Update test comment.
Jun 20, 2024
6411686
Merge branch 'staging' into feature/gus/liquid-alpha-params
Jun 21, 2024
ae45988
modify network.py to allow passing multiple values to subtensor/subst…
Jun 24, 2024
8ee808e
Merge branch 'staging' into feature/gus/liquid-alpha-params
Jun 24, 2024
24284d0
Update bittensor/commands/network.py
Jun 24, 2024
26d35f5
Import types
Jun 24, 2024
7302956
Ruff formatting
Jun 24, 2024
5a7f92e
Merge branch 'staging' into feature/gus/liquid-alpha-params
thealligatorking Jun 25, 2024
8fb6e63
expand test_liquid_alpha cases
JohnReedV Jun 25, 2024
4cee908
Merge branch 'staging' into feature/gus/liquid-alpha-params
Jun 26, 2024
7987366
chore:lint
thealligatorking Jun 26, 2024
0b02f4a
Fix LA test
Jun 26, 2024
383f695
Skip faucet test
Jun 26, 2024
8554c10
Skip faucet test
Jun 26, 2024
a075abe
Merge remote-tracking branch 'origin/feature/gus/liquid-alpha-params'…
Jun 26, 2024
48cfb8c
Merge branch 'staging' into feature/gus/liquid-alpha-params
Jun 26, 2024
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
9 changes: 9 additions & 0 deletions bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@
["difficulty", "Compact<u64>"],
["commit_reveal_weights_interval", "Compact<u64>"],
["commit_reveal_weights_enabled", "bool"],
["alpha_high", "Compact<u16>"],
["alpha_low", "Compact<u16>"],
["liquid_alpha_enabled", "bool"],
],
},
}
Expand Down Expand Up @@ -981,6 +984,9 @@ class SubnetHyperparameters:
difficulty: int
commit_reveal_weights_interval: int
commit_reveal_weights_enabled: bool
alpha_high: int
alpha_low: int
liquid_alpha_enabled: bool

@classmethod
def from_vec_u8(cls, vec_u8: List[int]) -> Optional["SubnetHyperparameters"]:
Expand Down Expand Up @@ -1033,6 +1039,9 @@ def fix_decoded_values(cls, decoded: Dict) -> "SubnetHyperparameters":
difficulty=decoded["difficulty"],
commit_reveal_weights_interval=decoded["commit_reveal_weights_interval"],
commit_reveal_weights_enabled=decoded["commit_reveal_weights_enabled"],
alpha_high=decoded["alpha_high"],
alpha_low=decoded["alpha_low"],
liquid_alpha_enabled=decoded["liquid_alpha_enabled"],
)

def to_parameter_dict(
Expand Down
52 changes: 49 additions & 3 deletions bittensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import argparse
import bittensor
from . import defaults
from . import defaults # type: ignore
from rich.prompt import Prompt
from rich.table import Table
from typing import List, Optional, Dict
from typing import List, Optional, Dict, Union, Tuple
from .utils import (
get_delegates_details,
DelegatesDetails,
Expand Down Expand Up @@ -330,6 +330,8 @@ def add_args(parser: argparse.ArgumentParser):
"bonds_moving_avg": "sudo_set_bonds_moving_average",
"commit_reveal_weights_interval": "sudo_set_commit_reveal_weights_interval",
"commit_reveal_weights_enabled": "sudo_set_commit_reveal_weights_enabled",
"alpha_values": "sudo_set_alpha_values",
"liquid_alpha_enabled": "sudo_set_liquid_alpha_enabled",
}


Expand Down Expand Up @@ -388,18 +390,25 @@ def _run(
cli.config.param == "network_registration_allowed"
or cli.config.param == "network_pow_registration_allowed"
or cli.config.param == "commit_reveal_weights_enabled"
or cli.config.param == "liquid_alpha_enabled"
):
cli.config.value = (
True
if (cli.config.value.lower() == "true" or cli.config.value == "1")
else False
)

is_allowed_value, value = allowed_value(cli.config.param, cli.config.value)
if not is_allowed_value:
raise ValueError(
f"Hyperparameter {cli.config.param} value is not within bounds. Value is {cli.config.value} but must be {value}"
)

subtensor.set_hyperparameter(
wallet,
netuid=cli.config.netuid,
parameter=cli.config.param,
value=cli.config.value,
value=value,
prompt=not cli.config.no_prompt,
)

Expand Down Expand Up @@ -638,3 +647,40 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
)
bittensor.subtensor.add_args(parser)


def allowed_value(
param: str, value: Union[str, bool, float]
) -> Tuple[bool, Union[str, list[float], float]]:
"""
Check the allowed values on hyperparameters. Return False if value is out of bounds.
"""
# Reminder error message ends like: Value is {value} but must be {error_message}. (the second part of return statement)
# Check if value is a boolean, only allow boolean and floats
try:
if not isinstance(value, bool):
if param == "alpha_values":
# Split the string into individual values
alpha_low_str, alpha_high_str = value.split(",")
alpha_high = float(alpha_high_str)
alpha_low = float(alpha_low_str)

# Check alpha_high value
if alpha_high <= 52428 or alpha_high >= 65535:
return (
False,
f"between 52428 and 65535 for alpha_high (but is {alpha_high})",
)

# Check alpha_low value
if alpha_low < 0 or alpha_low > 52428:
return (
False,
f"between 0 and 52428 for alpha_low (but is {alpha_low})",
)

return True, [alpha_low, alpha_high]
except ValueError:
return False, "a number or a boolean"

return True, value
6 changes: 4 additions & 2 deletions bittensor/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def filter_netuids_by_registered_hotkeys(
)
netuids_with_registered_hotkeys.extend(netuids_list)

if cli.config.netuids == None or cli.config.netuids == []:
if not cli.config.netuids:
netuids = netuids_with_registered_hotkeys

elif cli.config.netuids != []:
else:
netuids = [netuid for netuid in netuids if netuid in cli.config.netuids]
netuids.extend(netuids_with_registered_hotkeys)

Expand All @@ -216,6 +216,8 @@ def normalize_hyperparameters(
"bonds_moving_avg": U64_NORMALIZED_FLOAT,
"max_weight_limit": U16_NORMALIZED_FLOAT,
"kappa": U16_NORMALIZED_FLOAT,
"alpha_high": U16_NORMALIZED_FLOAT,
"alpha_low": U16_NORMALIZED_FLOAT,
"min_burn": Balance.from_rao,
"max_burn": Balance.from_rao,
}
Expand Down
30 changes: 26 additions & 4 deletions bittensor/extrinsics/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,38 @@ def set_hyperparameter_extrinsic(
extrinsic_params = substrate.get_metadata_call_function(
"AdminUtils", extrinsic
)
value_argument = extrinsic_params["fields"][
len(extrinsic_params["fields"]) - 1
]
call_params = {"netuid": netuid}

# if input value is a list, iterate through the list and assign values
if isinstance(value, list):
# Create an iterator for the list of values
value_iterator = iter(value)
# Iterate over all value arguments and add them to the call_params dictionary
for value_argument in extrinsic_params["fields"]:
if "netuid" not in str(value_argument["name"]):
# Assign the next value from the iterator
try:
call_params[str(value_argument["name"])] = next(
value_iterator
)
except StopIteration:
raise ValueError(
"Not enough values provided in the list for all parameters"
)

else:
value_argument = extrinsic_params["fields"][
len(extrinsic_params["fields"]) - 1
]
call_params[str(value_argument["name"])] = value

# create extrinsic call
call = substrate.compose_call(
call_module="AdminUtils",
call_function=extrinsic,
call_params={"netuid": netuid, str(value_argument["name"]): value},
call_params=call_params,
)

extrinsic = substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
)
Expand Down
Empty file.
Loading