Skip to content
Merged

Boost #1594

Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"list": RootList,
"weights": RootSetWeightsCommand,
"get_weights": RootGetWeightsCommand,
"boost": RootSetBoostCommand,
"slash": RootSetSlashCommand,
"senate_vote": VoteCommand,
"senate": SenateCommand,
"register": RootRegisterCommand,
Expand Down
2 changes: 2 additions & 0 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,7 @@
RootList,
RootSetWeightsCommand,
RootGetWeightsCommand,
RootSetBoostCommand,
RootSetSlashCommand,
)
from .identity import GetIdentityCommand, SetIdentityCommand
213 changes: 213 additions & 0 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,219 @@ def check_config(config: "bittensor.config"):
pass


class RootSetBoostCommand:
"""
Executes the 'boost' command to boost the weights for a specific subnet within the root network on the Bittensor network.

Usage:
The command allows boosting the weights for different subnets within the root network.

Optional arguments:
- --netuid (int): A single netuid for which weights are to be boosted.
- --increase (float): The cooresponding increase in the weight for this subnet.

Example usage:
>>> btcli root boost --netuid 1 --increase 0.01

Enter netuid (e.g. 1): 1
Enter amount (e.g. 0.01): 0.1
Boosting weight for subnet: 1 by amount: 0.1

Normalized weights:
tensor([
0.0000, 0.5455, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.4545, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]) -> tensor([0.0000, 0.5455, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.4545, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]
)

Do you want to set the following root weights?:
weights: tensor([
0.0000, 0.5455, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.4545, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000])
uids: tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40])? [y/n]: y
True None
✅ Finalized
⠙ 📡 Setting root weights on test ...2023-11-28 22:09:14.001 | SUCCESS | Set weights Finalized: True

"""

@staticmethod
def run(cli):
r"""Set weights for root network."""
wallet = bittensor.wallet(config=cli.config)
subtensor = bittensor.subtensor(config=cli.config)
subnets: List[bittensor.SubnetInfo] = subtensor.get_all_subnets_info()

bittensor.__console__.print(
"Boosting weight for subnet: {} by amount: {}".format(
cli.config.netuid, cli.config.amount
)
)
root = subtensor.metagraph(0, lite=False)
try:
my_uid = root.hotkeys.index(wallet.hotkey.ss58_address)
except ValueError:
bittensor.__console__.print(
"Wallet hotkey: {} not found in root metagraph".format(wallet.hotkey)
)
exit()
my_weights = root.weights[my_uid]
my_weights[cli.config.netuid] += cli.config.amount
my_weights /= my_weights.sum()
all_netuids = torch.tensor(list(range(len(my_weights))))

subtensor.root_set_weights(
wallet=wallet,
netuids=all_netuids,
weights=my_weights,
version_key=0,
prompt=not cli.config.no_prompt,
wait_for_finalization=True,
wait_for_inclusion=True,
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser(
"boost", help="""Boost weight for a specific subnet by increase amount."""
)
parser.add_argument("--netuid", dest="netuid", type=int, required=False)
parser.add_argument("--increase", dest="amount", type=float, required=False)

bittensor.wallet.add_args(parser)
bittensor.subtensor.add_args(parser)

@staticmethod
def check_config(config: "bittensor.config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
if not config.is_set("wallet.hotkey") and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)
if not config.is_set("netuid") and not config.no_prompt:
config.netuid = int(Prompt.ask(f"Enter netuid (e.g. 1)"))
if not config.is_set("amount") and not config.no_prompt:
config.amount = float(Prompt.ask(f"Enter amount (e.g. 0.01)"))


class RootSetSlashCommand:
"""
Executes the 'slash' command to decrease the weights for a specific subnet within the root network on the Bittensor network.

Usage:
The command allows slashing (decreasing) the weights for different subnets within the root network.

Optional arguments:
- --netuid (int): A single netuid for which weights are to be slashed.
- --decrease (float): The corresponding decrease in the weight for this subnet.

Example usage:
>>> btcli root slash --netuid 1 --decrease 0.01

Enter netuid (e.g. 1): 1
Enter decrease amount (e.g. 0.01): 0.2
Slashing weight for subnet: 1 by amount: 0.2

Normalized weights:
tensor([
0.0000, 0.4318, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.5682, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]) -> tensor([
0.0000, 0.4318, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.5682, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]
)

Do you want to set the following root weights?:
weights: tensor([
0.0000, 0.4318, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.5682, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000])
uids: tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40])? [y/n]: y
⠙ 📡 Setting root weights on test ...2023-11-28 22:09:14.001 | SUCCESS | Set weights Finalized: True
"""

@staticmethod
def run(cli):
"""Set weights for root network with decreased values."""
wallet = bittensor.wallet(config=cli.config)
subtensor = bittensor.subtensor(config=cli.config)
subnets: List[bittensor.SubnetInfo] = subtensor.get_all_subnets_info()

bittensor.__console__.print(
"Slashing weight for subnet: {} by amount: {}".format(
cli.config.netuid, cli.config.amount
)
)
root = subtensor.metagraph(0, lite=False)
try:
my_uid = root.hotkeys.index(wallet.hotkey.ss58_address)
except ValueError:
bittensor.__console__.print(
"Wallet hotkey: {} not found in root metagraph".format(wallet.hotkey)
)
exit()
my_weights = root.weights[my_uid]
my_weights[cli.config.netuid] -= cli.config.amount
my_weights[my_weights < 0] = 0 # Ensure weights don't go negative
my_weights /= my_weights.sum()
all_netuids = torch.tensor(list(range(len(my_weights))))

subtensor.root_set_weights(
wallet=wallet,
netuids=all_netuids,
weights=my_weights,
version_key=0,
prompt=not cli.config.no_prompt,
wait_for_finalization=True,
wait_for_inclusion=True,
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser(
"slash", help="""Slash weight for a specific subnet by decrease amount."""
)
parser.add_argument("--netuid", dest="netuid", type=int, required=False)
parser.add_argument("--decrease", dest="amount", type=float, required=False)

bittensor.wallet.add_args(parser)
bittensor.subtensor.add_args(parser)

@staticmethod
def check_config(config: "bittensor.config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
if not config.is_set("wallet.hotkey") and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)
if not config.is_set("netuid") and not config.no_prompt:
config.netuid = int(Prompt.ask(f"Enter netuid (e.g. 1)"))
if not config.is_set("amount") and not config.no_prompt:
config.amount = float(Prompt.ask(f"Enter decrease amount (e.g. 0.01)"))


class RootSetWeightsCommand:
"""
Executes the 'weights' command to set the weights for the root network on the Bittensor network.
Expand Down