Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.7 subtensor integration #1105

Merged
merged 31 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9f7ad73
adds back old subtensor, metagraph, and wallet
Eugene-hu Feb 23, 2023
ac02041
naka wallet add netuid param
isabella618033 Feb 27, 2023
5d2fdee
naka subtensor add netuid param
isabella618033 Feb 27, 2023
4c3e2ad
validator adapt to netuid param
isabella618033 Feb 27, 2023
c3d5ad7
btcli list fix
isabella618033 Feb 28, 2023
7b5a40c
btcli naka query fix
isabella618033 Feb 28, 2023
ae83463
btcli finney query fix
isabella618033 Feb 28, 2023
379235d
help & update fix
isabella618033 Feb 28, 2023
4388cbf
weights fix
isabella618033 Feb 28, 2023
53c34ce
cli finney weight fix
isabella618033 Feb 28, 2023
0e1b851
btcli wallets fix
isabella618033 Feb 28, 2023
399a0c8
cli fix list_subnet
isabella618033 Feb 28, 2023
e94fdd4
fixed btcli new hotkey
isabella618033 Feb 28, 2023
1b9c63d
revert unecessary finney check
isabella618033 Feb 28, 2023
6fc82fb
btcli stake and unstake fix
isabella618033 Feb 28, 2023
cf565af
btcli naka stake/unstake fix
isabella618033 Mar 1, 2023
55faf92
btcli naka metagraph fix
isabella618033 Mar 1, 2023
d5c3751
btcli naka query fix
isabella618033 Mar 1, 2023
d93315a
btcli naka weights fix
isabella618033 Mar 1, 2023
c26d4f0
Merge remote-tracking branch 'origin/release/3.7.0' into release-3.7-…
isabella618033 Mar 1, 2023
a573ed3
Merge remote-tracking branch 'origin/release/3.7.0' into release-3.7-…
Eugene-hu Mar 1, 2023
85c93f7
Merge branch 'release-3.7-subtensor-integration' of https://github.co…
Eugene-hu Mar 1, 2023
ecd5fc4
removed uncessary finney check
isabella618033 Mar 1, 2023
2e586fc
version key for subtensor set_weights
Eugene-hu Mar 2, 2023
6dd69dc
Merge branch 'release-3.7-subtensor-integration' of https://github.co…
Eugene-hu Mar 2, 2023
47f6b88
remove duplicated deepcopy
isabella618033 Mar 3, 2023
00c6625
validator version 1 -> version_as_int
isabella618033 Mar 3, 2023
7a8b7f6
get_n -> get_neuron_num
isabella618033 Mar 3, 2023
135f811
reverted validator version_key to 1
isabella618033 Mar 3, 2023
a1deda4
removed deepcopy
isabella618033 Mar 5, 2023
f8c6f50
removed uncessary copy import
isabella618033 Mar 7, 2023
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
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