Skip to content

Commit

Permalink
Release 3.7 subtensor integration (#1105)
Browse files Browse the repository at this point in the history
* adds back old subtensor, metagraph, and wallet

* naka wallet add netuid param

* naka subtensor add netuid param

* validator adapt to netuid param

* btcli list fix

* btcli naka query fix

* btcli finney query fix

* help & update fix

* weights fix

* cli finney weight fix

* btcli wallets fix

* cli fix list_subnet

* fixed btcli new hotkey

* revert unecessary finney check

* btcli stake and unstake fix

* btcli naka stake/unstake fix

* btcli naka metagraph fix

* btcli naka query fix

* btcli naka weights fix

* removed uncessary finney check

* version key for subtensor set_weights

* remove duplicated deepcopy

* validator version 1 -> version_as_int

* get_n -> get_neuron_num

* reverted validator version_key to 1

* removed deepcopy

* removed uncessary copy import

Co-authored-by: Eduardo García <[email protected]>

---------

Co-authored-by: Eugene <[email protected]>
Co-authored-by: Eduardo García <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2023
1 parent ff4af76 commit 70c93e6
Show file tree
Hide file tree
Showing 18 changed files with 5,107 additions and 110 deletions.
10 changes: 9 additions & 1 deletion bittensor/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from . import cli_impl
from .commands import *
from typing import List, Optional
from .naka_cli_impl import CLI as naka_CLI
console = bittensor.__console__

# Turn off rich console locals trace.
Expand All @@ -50,7 +51,13 @@ def __new__(
if config == None:
config = cli.config(args)
cli.check_config( config )
return cli_impl.CLI( config = config)
if config.subtensor:
network = config.subtensor.get('network', bittensor.defaults.subtensor.network)

if network == 'finney':
return cli_impl.CLI( config = config)
elif network == 'nakamoto':
return naka_CLI(config=config)

@staticmethod
def config(args: List[str]) -> 'bittensor.config':
Expand Down Expand Up @@ -80,6 +87,7 @@ def config(args: List[str]) -> 'bittensor.config':
MetagraphCommand.add_args( cmd_parsers )
SetWeightsCommand.add_args( cmd_parsers )
NewColdkeyCommand.add_args( cmd_parsers )
NewHotkeyCommand.add_args( cmd_parsers )
ListSubnetsCommand.add_args( cmd_parsers )
RegenHotkeyCommand.add_args( cmd_parsers )
RegenColdkeyCommand.add_args( cmd_parsers )
Expand Down
3 changes: 2 additions & 1 deletion bittensor/_cli/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ def add_args( parser: argparse.ArgumentParser ):
default=False,
)
list_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
bittensor.wallet.add_args( list_parser )
bittensor.wallet.add_args( list_parser )
bittensor.subtensor.add_args( list_parser )
6 changes: 4 additions & 2 deletions bittensor/_cli/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def add_args( parser: argparse.ArgumentParser ):
default='None',
)
help_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
bittensor.subtensor.add_args( help_parser )

class UpdateCommand:
@staticmethod
Expand Down Expand Up @@ -86,6 +87,7 @@ def add_args( parser: argparse.ArgumentParser ):
default=False,
)
update_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
bittensor.subtensor.add_args( update_parser )

class ListSubnetsCommand:
@staticmethod
Expand All @@ -96,7 +98,7 @@ def run (cli):

rows = []
total_neurons = 0

for subnet in subnets:
total_neurons += subnet.max_n
rows.append((
Expand All @@ -109,7 +111,7 @@ def run (cli):
str(subnet.validator_sequence_length),
str(subnet.tempo),
str(subnet.modality),
str(list(subnet.connection_requirements.keys())),
str([cr[1] for cr in subnet.connection_requirements]),
str(subnet.emission_value),
))

Expand Down
29 changes: 25 additions & 4 deletions bittensor/_cli/commands/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,38 @@ def run (cli):
subtensor = bittensor.subtensor( config = cli.config )

# Verify subnet exists
if not hasattr(cli.config, 'netuid'):
bittensor.__console__.print(f"[red]Please specify subnet with --netuid.[/red]")
sys.exit(1)

if not subtensor.subnet_exists( netuid = cli.config.netuid ):
bittensor.__console__.print(f"[red]Subnet {cli.config.netuid} does not exist[/red]")
bittensor.__console__.print(f"[red]Subnet {cli.config.netuid} does not exist.[/red]")
sys.exit(1)

dendrite = bittensor.dendrite( wallet = wallet )
stats = {}
for uid in cli.config.uids:
neuron = subtensor.neuron_for_uid( uid = uid, netuid = cli.config.netuid )
endpoint = bittensor.endpoint.from_neuron( neuron )
_, c, t = dendrite.forward_text( endpoints = endpoint, inputs = 'hello world')
latency = "{}".format(t.tolist()[0]) if c.tolist()[0] == 1 else 'N/A'
bittensor.__console__.print("\tUid: [bold white]{}[/bold white]\n\tLatency: [bold white]{}[/bold white]\n\tCode: [bold {}]{}[/bold {}]\n\n".format(uid, latency, bittensor.utils.codes.code_to_loguru_color( c.item() ), bittensor.utils.codes.code_to_string( c.item() ), bittensor.utils.codes.code_to_loguru_color( c.item() )), highlight=True)
_, c, t = dendrite.text( endpoints = endpoint, inputs = 'hello world', synapses = [bittensor.synapse.TextCausalLMNext()])
latency = "{}".format(t[0].tolist()[0]) if c[0].tolist()[0] == 1 else 'N/A'
bittensor.__console__.print("\tUid: [bold white]{}[/bold white]\n\tLatency: [bold white]{}[/bold white]\n\tCode: [bold {}]{}[/bold {}]\n\n".format(
uid,
latency,
bittensor.utils.codes.code_to_loguru_color( c[0].item() ),
bittensor.utils.codes.code_to_string( c[0].item() ),
bittensor.utils.codes.code_to_loguru_color( c[0].item() )
), highlight=True)
stats[uid] = latency
print (stats)
dendrite.__del__()

@staticmethod
def check_config( config: 'bittensor.Config' ):

if config.subtensor.get('network') == bittensor.defaults.subtensor.network and not config.no_prompt:
config.subtensor.network = Prompt.ask("Enter subtensor network", choices=bittensor.__networks__, default = bittensor.defaults.subtensor.network)

if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)
Expand Down Expand Up @@ -85,6 +100,12 @@ def add_args( parser: argparse.ArgumentParser ):
help='''Set true to avoid prompting the user.''',
default=False,
)
query_parser.add_argument(
'--netuid',
type=int,
help='netuid for subnet to serve this neuron on',
default=argparse.SUPPRESS,
)
query_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
bittensor.wallet.add_args( query_parser )
bittensor.subtensor.add_args( query_parser )
Expand Down
42 changes: 21 additions & 21 deletions bittensor/_cli/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ def check_choice( self, value: str ) -> bool:


def check_netuid_set( config: 'bittensor.Config', subtensor: 'bittensor.Subtensor', allow_none: bool = False ):

all_netuids = [str(netuid) for netuid in subtensor.get_subnets()]
if len(all_netuids) == 0:
console.print(":cross_mark:[red]There are no open networks.[/red]")
sys.exit()

# Make sure netuid is set.
if config.get('netuid', 'notset') == 'notset':
if not config.no_prompt:
netuid = IntListPrompt.ask("Enter netuid", choices=all_netuids, default=str(all_netuids[0]))
if subtensor.network =='finney':
all_netuids = [str(netuid) for netuid in subtensor.get_subnets()]
if len(all_netuids) == 0:
console.print(":cross_mark:[red]There are no open networks.[/red]")
sys.exit()

# Make sure netuid is set.
if config.get('netuid', 'notset') == 'notset':
if not config.no_prompt:
netuid = IntListPrompt.ask("Enter netuid", choices=all_netuids, default=str(all_netuids[0]))
else:
netuid = str(bittensor.defaults.netuid) if not allow_none else 'None'
else:
netuid = str(bittensor.defaults.netuid) if not allow_none else 'None'
else:
netuid = config.netuid

if isinstance(netuid, str) and netuid.lower() in ['none'] and allow_none:
config.netuid = None
else:
try:
config.netuid = int(netuid)
except ValueError:
raise ValueError('netuid must be an integer or "None" (if applicable)')
netuid = config.netuid

if isinstance(netuid, str) and netuid.lower() in ['none'] and allow_none:
config.netuid = None
else:
try:
config.netuid = int(netuid)
except ValueError:
raise ValueError('netuid must be an integer or "None" (if applicable)')


def check_for_cuda_reg_config( config: 'bittensor.Config' ) -> None:
Expand Down
7 changes: 6 additions & 1 deletion bittensor/_cli/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def add_args( parser: argparse.ArgumentParser ):
help='''Overwrite the old coldkey with the newly generated coldkey'''
)
bittensor.wallet.add_args( regen_coldkey_parser )
bittensor.subtensor.add_args( regen_coldkey_parser )


class RegenColdkeypubCommand:
Expand Down Expand Up @@ -180,6 +181,7 @@ def add_args( parser: argparse.ArgumentParser ):
help='''Overwrite the old coldkeypub file with the newly generated coldkeypub'''
)
bittensor.wallet.add_args( regen_coldkeypub_parser )
bittensor.subtensor.add_args( regen_coldkeypub_parser )

class RegenHotkeyCommand:

Expand Down Expand Up @@ -282,6 +284,7 @@ def add_args( parser: argparse.ArgumentParser ):
help='''Overwrite the old hotkey with the newly generated hotkey'''
)
bittensor.wallet.add_args( regen_hotkey_parser )
bittensor.subtensor.add_args( regen_hotkey_parser )



Expand Down Expand Up @@ -339,6 +342,7 @@ def add_args( parser: argparse.ArgumentParser ):
help='''Overwrite the old hotkey with the newly generated hotkey'''
)
bittensor.wallet.add_args( new_hotkey_parser )
bittensor.subtensor.add_args( new_hotkey_parser )


class NewColdkeyCommand:
Expand Down Expand Up @@ -393,4 +397,5 @@ def add_args( parser: argparse.ArgumentParser ):
default=False,
help='''Overwrite the old coldkey with the newly generated coldkey'''
)
bittensor.wallet.add_args( new_coldkey_parser )
bittensor.wallet.add_args( new_coldkey_parser )
bittensor.subtensor.add_args( new_coldkey_parser )
Loading

0 comments on commit 70c93e6

Please sign in to comment.