Skip to content

Commit

Permalink
Aio merge master (#1507)
Browse files Browse the repository at this point in the history
* add automated submodule sync to setup

* add aliases

* add aliases

* Remove set_adjustment_interval from sudo set command

* subtensor config changes

* fix wallet create

* Fix set hyperparameter

* fix transfer command

* Revolution security fix jsons (#1506)

* replace pickle with jsons to avoid pickle security issues

* fix test_syapse.py

* use our internal msgpack-numpy that disables pickle

* skip git+ reqs in check_compat

* graceful error for submodules

* remove jsons in favor of json, no benefit as async client (httpx) attempts to internally json deserialize anyway. jsons would be of no benefit

* fix tests

* remove jsons req

* run black

* fix readme, remove recurse-submod as it's in setup.py now

* remove pep517 note, causes issues

---------

Co-authored-by: unconst <[email protected]>
Co-authored-by: Ayden Brewer <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2023
1 parent dcd1a1d commit b21f0d2
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 145 deletions.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ pip3 install bittensor
```
3. From source:
```bash
$ git clone --recurse-submodules https://github.com/opentensor/bittensor.git
$ git clone https://github.com/opentensor/bittensor.git
$ python3 -m pip install -e bittensor/
```
4. Using Conda (recommended for **Apple M1**):
Expand All @@ -41,16 +41,6 @@ $ conda env create -f ~/.bittensor/bittensor/scripts/environments/apple_m1_envir
$ conda activate bittensor
```

To sync the submodules bittensor-wallet and bittensor-config:
```bash
cd bittensor/

git submodule sync && git submodule update --init

# Reinstall with updated submodules
python3 -m pip install -e .
```

To test your installation, type:
```bash
$ btcli --help
Expand Down
39 changes: 37 additions & 2 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,29 @@
# Create a console instance for CLI display.
console = bittensor.__console__

ALIAS_TO_COMMAND = {
"subnets": "subnets",
"root": "root",
"wallet": "wallet",
"stake": "stake",
"sudo": "sudo",
"legacy": "legacy",
"s": "subnets",
"r": "root",
"w": "wallet",
"st": "stake",
"su": "sudo",
"l": "legacy",
"subnet": "subnets",
"roots": "root",
"wallets": "wallet",
"stakes": "stake",
"sudos": "sudo",
}
COMMANDS = {
"subnets": {
"name": "subnets",
"aliases": ["s", "subnet"],
"help": "Commands for managing and viewing subnetworks.",
"commands": {
"list": SubnetListCommand,
Expand All @@ -40,6 +60,7 @@
},
"root": {
"name": "root",
"aliases": ["r", "roots"],
"help": "Commands for managing and viewing the root network.",
"commands": {
"list": RootList,
Expand All @@ -53,6 +74,7 @@
},
"wallet": {
"name": "wallet",
"aliases": ["w", "wallets"],
"help": "Commands for managing and viewing wallets.",
"commands": {
"list": ListCommand,
Expand All @@ -72,6 +94,7 @@
},
"stake": {
"name": "stake",
"aliases": ["st", "stakes"],
"help": "Commands for staking and removing stake from hotkey accounts.",
"commands": {
"show": StakeShow,
Expand All @@ -81,14 +104,17 @@
},
"sudo": {
"name": "sudo",
"aliases": ["su", "sudos"],
"help": "Commands for subnet management",
"commands": {
# "dissolve": None,
"set": SubnetSudoCommand
"set": SubnetSudoCommand,
"get": SubnetGetHyperparamsCommand,
},
},
"legacy": {
"name": "misc",
"aliases": ["l"],
"help": "Miscellaneous commands.",
"commands": {
"update": UpdateCommand,
Expand Down Expand Up @@ -124,6 +150,13 @@ def __init__(
config = cli.create_config(args)

self.config = config
if self.config.command in ALIAS_TO_COMMAND:
self.config.command = ALIAS_TO_COMMAND[self.config.command]
else:
console.print(
f":cross_mark:[red]Unknown command: {self.config.command}[/red]"
)
sys.exit()

# Check if the config is valid.
cli.check_config(self.config)
Expand Down Expand Up @@ -158,7 +191,9 @@ def __create_parser__() -> "argparse.ArgumentParser":
for command in COMMANDS.values():
if isinstance(command, dict):
subcmd_parser = cmd_parsers.add_parser(
name=command["name"], help=command["help"]
name=command["name"],
aliases=command["aliases"],
help=command["help"],
)
subparser = subcmd_parser.add_subparsers(
help=command["help"], dest="subcommand"
Expand Down
1 change: 1 addition & 0 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@
SubnetListCommand,
SubnetSudoCommand,
SubnetHyperparamsCommand,
SubnetGetHyperparamsCommand,
)
from .root import RootRegisterCommand, RootList, RootSetWeightsCommand
68 changes: 54 additions & 14 deletions bittensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def add_args(parser: argparse.ArgumentParser):
"max_difficulty": "sudo_set_max_difficulty",
"weights_version": "sudo_set_weights_version_key",
"weights_rate_Limit": "sudo_set_weights_set_rate_limit",
"adjustment_interval": "sudo_set_adjustment_interval",
"max_weight_limit": "sudo_set_max_weight_limit",
"immunity_period": "sudo_set_immunity_period",
"min_allowed_weights": "sudo_set_min_allowed_weights",
Expand All @@ -188,12 +187,20 @@ def run(cli):
config = cli.config.copy()
wallet = bittensor.wallet(config=cli.config)
subtensor: bittensor.subtensor = bittensor.subtensor(config=config)
print("\n")
SubnetHyperparamsCommand.run(cli)
if not config.is_set("param") and not config.no_prompt:
param = Prompt.ask("Enter hyperparameter", choices=HYPERPARAMS)
config.param = str(param)
if not config.is_set("value") and not config.no_prompt:
value = Prompt.ask("Enter new value")
config.value = value

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

Expand All @@ -206,14 +213,6 @@ def check_config(config: "bittensor.config"):
if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, bittensor.subtensor(config=config))

if not config.is_set("param") and not config.no_prompt:
param = Prompt.ask("Enter hyperparameter", choices=HYPERPARAMS)
config.param = str(param)

if not config.is_set("value") and not config.no_prompt:
value = Prompt.ask("Enter new value")
config.value = value

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser("set", help="""Set hyperparameters for a subnet""")
Expand Down Expand Up @@ -246,11 +245,11 @@ def run(cli):
table.title = "[white]Subnet Hyperparameters - NETUID: {} - {}".format(
cli.config.netuid, subtensor.network
)
table.add_column("[overline white]HYPERPARAMETER", style="white")
table.add_column("[overline white]VALUE", style="white")
table.add_column("[overline white]HYPERPARAMETER", style="bold white")
table.add_column("[overline white]VALUE", style="green")

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

bittensor.__console__.print(table)

Expand All @@ -268,3 +267,44 @@ def add_args(parser: argparse.ArgumentParser):
"--netuid", dest="netuid", type=int, required=False, default=False
)
bittensor.subtensor.add_args(parser)


class SubnetGetHyperparamsCommand:
@staticmethod
def run(cli):
r"""View hyperparameters of a subnetwork."""
subtensor = bittensor.subtensor(config=cli.config)
subnet: bittensor.SubnetInfo = subtensor.get_subnet_hyperparameters(
cli.config.netuid
)

table = Table(
show_footer=True,
width=cli.config.get("width", None),
pad_edge=True,
box=None,
show_edge=True,
)
table.title = "[white]Subnet Hyperparameters - NETUID: {} - {}".format(
cli.config.netuid, subtensor.network
)
table.add_column("[overline white]HYPERPARAMETER", style="white")
table.add_column("[overline white]VALUE", style="green")

for param in subnet.__dict__:
table.add_row(param, str(subnet.__dict__[param]))

bittensor.__console__.print(table)

@staticmethod
def check_config(config: "bittensor.config"):
if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, bittensor.subtensor(config=config))

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser("get", help="""View subnet hyperparameters""")
parser.add_argument(
"--netuid", dest="netuid", type=int, required=False, default=False
)
bittensor.subtensor.add_args(parser)
34 changes: 2 additions & 32 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys
import re
import torch
import typing
import argparse
import bittensor
from typing import List
Expand Down Expand Up @@ -48,17 +49,6 @@ def add_args(parser: argparse.ArgumentParser):

@staticmethod
def check_config(config: "bittensor.config"):
if (
not config.is_set("subtensor.network")
and not config.is_set("subtensor.chain_endpoint")
and not config.no_prompt
):
config.subtensor.network = Prompt.ask(
"Enter subtensor network",
choices=bittensor.__networks__,
default=defaults.subtensor.network,
)

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)
Expand All @@ -85,16 +75,7 @@ def add_args(parser: argparse.ArgumentParser):

@staticmethod
def check_config(config: "bittensor.config"):
if (
not config.is_set("subtensor.network")
and not config.is_set("subtensor.chain_endpoint")
and not config.no_prompt
):
config.subtensor.network = Prompt.ask(
"Enter subtensor network",
choices=bittensor.__networks__,
default=defaults.subtensor.network,
)
pass


class RootSetWeightsCommand:
Expand Down Expand Up @@ -158,17 +139,6 @@ def add_args(parser: argparse.ArgumentParser):

@staticmethod
def check_config(config: "bittensor.config"):
if (
not config.is_set("subtensor.network")
and not config.is_set("subtensor.chain_endpoint")
and not config.no_prompt
):
config.subtensor.network = Prompt.ask(
"Enter subtensor network",
choices=bittensor.__networks__,
default=defaults.subtensor.network,
)

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)
Expand Down
4 changes: 2 additions & 2 deletions bittensor/commands/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def check_config(config: "bittensor.config"):

# Get current balance and print to user.
if not config.no_prompt:
wallet = bittensor.wallet(config)
subtensor = bittensor.subtensor(config)
wallet = bittensor.wallet(config=config)
subtensor = bittensor.subtensor(config=config)
with bittensor.__console__.status(":satellite: Checking Balance..."):
account_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
bittensor.__console__.print(
Expand Down
2 changes: 1 addition & 1 deletion bittensor/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def run(cli):
)
wallet.create_new_hotkey(
n_words=cli.config.n_words,
use_password=cli.config.use_password,
use_password=False,
overwrite=cli.config.overwrite_hotkey,
)

Expand Down
3 changes: 3 additions & 0 deletions bittensor/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def preprocess_synapse_for_request(
Returns:
bt.Synapse: The preprocessed synapse.
"""
bt.logging.trace("Pre-process synapse for request")

# Set the timeout for the synapse
synapse.timeout = str(timeout)
Expand Down Expand Up @@ -359,6 +360,8 @@ def process_server_response(
Raises:
None, but errors in attribute setting are silently ignored.
"""
bt.logging.trace("Postprocess server response")

# Check if the server responded with a successful status code
if server_response.status == 200:
# If the response is successful, overwrite local synapse state with
Expand Down
2 changes: 1 addition & 1 deletion bittensor/extrinsics/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def set_hyperparameter_extrinsic(
return False

with bittensor.__console__.status(
f":satellite: Setting hyperparameter {parameter} to {value}..."
f":satellite: Setting hyperparameter {parameter} to {value} on subnet: {netuid} ..."
):
with subtensor.substrate as substrate:
extrinsic_params = substrate.get_metadata_call_function(
Expand Down
Loading

0 comments on commit b21f0d2

Please sign in to comment.