Skip to content

Commit

Permalink
Merge releases 4.0.0 and 4.0.1 back to staging (#1306)
Browse files Browse the repository at this point in the history
* bump version

* Fix permissions for release github script (#1224)

Co-authored-by: Cameron Fairchild <[email protected]>

* should be 4.1.0

* Revert "should be 4.1.0"

This reverts commit 3db08ea.

* Staging into Release branch (#1275)

* (un)Staking multiple avoid tx limit (#1244)

* add tx rate limit

* wait for tx limit if not done multi stake/unstake

* dont "decrypt" hotkey

* additional logging for prometheus (#1246)

* Dataset fix (#1249)

* fix

* added try except

* Grab delegates details from GitHub (#1245)

* add url to init

* add dataclass and util functions

* use in cli

* remove delegates json

---------

Co-authored-by: joeylegere <[email protected]>

* Add raw spec for local test and new bins (#1243)

* add spec and new bins

* fix config netuid

* use dot get

* check if config netuid is list

* add start to mockstatus

* add attr to mock neuron

* add info to mock from neurons

* change ordering of neuron dict to namespace

* remove test for wandb for axon

* use regex for looser match

* fix blacklist metagraph mock

* use real mock netuid

* use mock network and netuid in constructor

* fix patch

* patch delegate check

* use mock network and netuid

* remove check for wallet hotkey

* fix tests for subtensor init

* dont set netuid for overview test

* typo in docstring

* add mock status stop

* add low mock tx limit

* oops typo

* use dot get

* add wait for final and incl args

* use args during setup

* update bins and use 100ms blocktime

* pass block arg

* remove bittensor.logging and a old test

* use random port

* backward fix

* fix block time to 1s

* compile no symb on linux

* compile no symb mac

* remove useless init on var

* use dot get for new flags

* update test durations

* update test durations

* use dot get for config

* output error msg

* mock to_default

* remove to defaults in help

* reduce neruons, remove flaky test

* deactivate test

* mvoe key pair tests out of the subtensor interface

---------

Co-authored-by: Eugene <[email protected]>

* Fix list_delegates on non-archive nodes (#1232)

* Change how pull of archival data is handled

* fix for list_delegates too

* .

* use empty dict

* fix spacing

* specify exception

* log out

* add space in log message

* use warning instead

* Blacklist fixes + depreciation of old signatures (#1240)

* fixes blacklist error message + remove

* remove checks for parse signature

* remove sign v1 tests

* fix for the syanpse checks

* fix tests and remove duplicate sign

* [BIT-636] Change u16 weight normalization to max-upscaling (#1241)

* Change u16 weight normalization to max-upscaling

Use full u16 bitwidth so that max_weight=U16_MAX, then rely on subtensor epoch to properly normalize weights in I32F32. This means that weights submission extrinsic to subtensor does not have to be pre-normalized.

* Skip zero sum in weight conversion

* Round u16 weights

* remove duplicate command #1228 (#1231)

* remove duplicate command #1228

* Extract create_parser for cli testing

* mark as private

* use in tests and test for duplicates

* fix test using mock prompt answers

* test_forward_priority_2nd_request_timeout fix (#1276)

fix

* Remove btcli query and btcli set_weights (#1144)

.

---------

Co-authored-by: Eugene-hu <[email protected]>
Co-authored-by: isabella618033 <[email protected]>
Co-authored-by: joeylegere <[email protected]>
Co-authored-by: Eugene <[email protected]>
Co-authored-by: opentaco <[email protected]>

* Remove codecov (#1282)

* Use alt new preseal (#1269)

* use new preseal for reg

* bump cubit req

* fix arg order issue

* cubit req back

* use alt impl

* fix typehint

* use 512

* modify tests for new format

* refactor functions to use helpers and remove useless

* refactor functions

* add test for CPU solver

* modify tests for privitized module and methods

* private register cuda

* move formatting funcs

* use powsolution

* privitize most methods

* fix test

* fix perms

* remove test script

* remove debug

* fix call

* fix seal

* fix combined hash

* move to method

* fix test using real example

* update mock bins

* use new builder

* fix block update tests

* fix some patching in tests

* mock live display for some tests

* fix chain mock

* update linux bin

* add mock network flag

* set max diff at 0 for mock netuid 1

* set min diff too

* add try catch for setup

* add some logging during tests

* don't submit on cli register

* update test durations

* fix test to use mock keypair

* return mock wallet

* should use subtensor instance during rereg

* update node subtensor bins

* use fixtures and multiple subtensor instances

* changelog update

* skip CLI tests (#1284)

* skip tests

* dont test mock functions

* update test durations

* [Release] v4.0.0 (#1271)

* bump version

* Fix permissions for release github script (#1224)

Co-authored-by: Cameron Fairchild <[email protected]>

* should be 4.1.0

* Revert "should be 4.1.0"

This reverts commit 3db08ea.

* Staging into Release branch (#1275)

* (un)Staking multiple avoid tx limit (#1244)

* add tx rate limit

* wait for tx limit if not done multi stake/unstake

* dont "decrypt" hotkey

* additional logging for prometheus (#1246)

* Dataset fix (#1249)

* fix

* added try except

* Grab delegates details from GitHub (#1245)

* add url to init

* add dataclass and util functions

* use in cli

* remove delegates json

---------

Co-authored-by: joeylegere <[email protected]>

* Add raw spec for local test and new bins (#1243)

* add spec and new bins

* fix config netuid

* use dot get

* check if config netuid is list

* add start to mockstatus

* add attr to mock neuron

* add info to mock from neurons

* change ordering of neuron dict to namespace

* remove test for wandb for axon

* use regex for looser match

* fix blacklist metagraph mock

* use real mock netuid

* use mock network and netuid in constructor

* fix patch

* patch delegate check

* use mock network and netuid

* remove check for wallet hotkey

* fix tests for subtensor init

* dont set netuid for overview test

* typo in docstring

* add mock status stop

* add low mock tx limit

* oops typo

* use dot get

* add wait for final and incl args

* use args during setup

* update bins and use 100ms blocktime

* pass block arg

* remove bittensor.logging and a old test

* use random port

* backward fix

* fix block time to 1s

* compile no symb on linux

* compile no symb mac

* remove useless init on var

* use dot get for new flags

* update test durations

* update test durations

* use dot get for config

* output error msg

* mock to_default

* remove to defaults in help

* reduce neruons, remove flaky test

* deactivate test

* mvoe key pair tests out of the subtensor interface

---------

Co-authored-by: Eugene <[email protected]>

* Fix list_delegates on non-archive nodes (#1232)

* Change how pull of archival data is handled

* fix for list_delegates too

* .

* use empty dict

* fix spacing

* specify exception

* log out

* add space in log message

* use warning instead

* Blacklist fixes + depreciation of old signatures (#1240)

* fixes blacklist error message + remove

* remove checks for parse signature

* remove sign v1 tests

* fix for the syanpse checks

* fix tests and remove duplicate sign

* [BIT-636] Change u16 weight normalization to max-upscaling (#1241)

* Change u16 weight normalization to max-upscaling

Use full u16 bitwidth so that max_weight=U16_MAX, then rely on subtensor epoch to properly normalize weights in I32F32. This means that weights submission extrinsic to subtensor does not have to be pre-normalized.

* Skip zero sum in weight conversion

* Round u16 weights

* remove duplicate command #1228 (#1231)

* remove duplicate command #1228

* Extract create_parser for cli testing

* mark as private

* use in tests and test for duplicates

* fix test using mock prompt answers

* test_forward_priority_2nd_request_timeout fix (#1276)

fix

* Remove btcli query and btcli set_weights (#1144)

.

---------

Co-authored-by: Eugene-hu <[email protected]>
Co-authored-by: isabella618033 <[email protected]>
Co-authored-by: joeylegere <[email protected]>
Co-authored-by: Eugene <[email protected]>
Co-authored-by: opentaco <[email protected]>

* Remove codecov (#1282)

* Use alt new preseal (#1269)

* use new preseal for reg

* bump cubit req

* fix arg order issue

* cubit req back

* use alt impl

* fix typehint

* use 512

* modify tests for new format

* refactor functions to use helpers and remove useless

* refactor functions

* add test for CPU solver

* modify tests for privitized module and methods

* private register cuda

* move formatting funcs

* use powsolution

* privitize most methods

* fix test

* fix perms

* remove test script

* remove debug

* fix call

* fix seal

* fix combined hash

* move to method

* fix test using real example

* update mock bins

* use new builder

* fix block update tests

* fix some patching in tests

* mock live display for some tests

* fix chain mock

* update linux bin

* add mock network flag

* set max diff at 0 for mock netuid 1

* set min diff too

* add try catch for setup

* add some logging during tests

* don't submit on cli register

* update test durations

* fix test to use mock keypair

* return mock wallet

* should use subtensor instance during rereg

* update node subtensor bins

* use fixtures and multiple subtensor instances

* changelog update

* skip CLI tests (#1284)

* skip tests

* dont test mock functions

* update test durations

---------

Co-authored-by: Eduardo García <[email protected]>
Co-authored-by: Eugene-hu <[email protected]>
Co-authored-by: isabella618033 <[email protected]>
Co-authored-by: joeylegere <[email protected]>
Co-authored-by: Eugene <[email protected]>
Co-authored-by: opentaco <[email protected]>

* fix my delegates

* fix perms on changelog script

* update version

* fix changelog script

* Catch bad endpoint protocol (#1296)

* catch protocol not good

* add protocol 4

* catch assertion and return bool

* catch assertion errors

* changelog

---------

Co-authored-by: Eduardo García <[email protected]>
Co-authored-by: Eugene-hu <[email protected]>
Co-authored-by: isabella618033 <[email protected]>
Co-authored-by: joeylegere <[email protected]>
Co-authored-by: Eugene <[email protected]>
Co-authored-by: opentaco <[email protected]>
  • Loading branch information
7 people authored and ifrit98 committed Jun 7, 2023
1 parent 06a6ccd commit 7bfb96c
Show file tree
Hide file tree
Showing 12 changed files with 1,010 additions and 479 deletions.
654 changes: 219 additions & 435 deletions .test_durations

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
5.1.0
151 changes: 151 additions & 0 deletions bittensor/_cli/commands/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import os
import sys
import argparse
import bittensor
from rich.prompt import Prompt, Confirm
from .utils import check_netuid_set, check_for_cuda_reg_config
console = bittensor.__console__

class RunCommand:
def run ( cli ):
cli.config.to_defaults()
subtensor = bittensor.subtensor( config = cli.config )

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

# Check coldkey.
wallet = bittensor.wallet( config = cli.config )
if not wallet.coldkeypub_file.exists_on_device():
if Confirm.ask("Coldkey: [bold]'{}'[/bold] does not exist, do you want to create it".format(cli.config.wallet.get('name', bittensor.defaults.wallet.name))):
wallet.create_new_coldkey()
else:
sys.exit()

# Check hotkey.
if not wallet.hotkey_file.exists_on_device():
if Confirm.ask("Hotkey: [bold]'{}'[/bold] does not exist, do you want to create it".format(cli.config.wallet.hotkey)):
wallet.create_new_hotkey()
else:
sys.exit()

if wallet.hotkey_file.is_encrypted():
bittensor.__console__.print("Decrypting hotkey ... ")
wallet.hotkey

if wallet.coldkeypub_file.is_encrypted():
bittensor.__console__.print("Decrypting coldkeypub ... ")
wallet.coldkeypub

# Check registration
## Will exit if --wallet.reregister is False
if cli.config.wallet.get('reregister', bittensor.defaults.wallet.reregister) and not cli.config.no_prompt and not wallet.is_registered(netuid = cli.config.netuid):
console.print("Wallet not registered.")
check_for_cuda_reg_config(wallet.config)
print(wallet.config)

wallet.reregister( subtensor=subtensor, netuid = cli.config.netuid )

# Run miner.
if cli.config.model == 'core_server':
if cli.config.synapse == 'TextLastHiddenState':
bittensor.neurons.core_server.neuron(lasthidden=True, causallm=False, seq2seq = False, netuid = cli.config.netuid).run()
elif cli.config.synapse == 'TextCausalLM':
bittensor.neurons.core_server.neuron(lasthidden=False, causallm=True, seq2seq = False, netuid = cli.config.netuid).run()
elif cli.config.synapse == 'TextSeq2Seq':
bittensor.neurons.core_server.neuron(lasthidden=False, causallm=False, seq2seq = True, netuid = cli.config.netuid).run()
else:
bittensor.neurons.core_server.neuron(netuid = cli.config.netuid).run()

elif cli.config.model == 'core_validator':
bittensor.neurons.core_validator.neuron(netuid = cli.config.netuid).run()
elif cli.config.model == 'multitron_server':
bittensor.neurons.multitron_server.neuron(netuid = cli.config.netuid).run()

@staticmethod
def check_config( config: 'bittensor.Config' ):
# Check network.
check_netuid_set( config, subtensor = bittensor.subtensor( config = config ) )

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)

# Check hotkey.
if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

# Check Miner
if config.model == 'None' and not config.no_prompt:
model = Prompt.ask('Enter miner name', choices = list(bittensor.neurons.__text_neurons__.keys()), default = 'core_server')
config.model = model

if 'server' in config.model and config.get('synapse', 'None') == 'None' and not config.no_prompt:
synapse = Prompt.ask('Enter synapse', choices = list(bittensor.synapse.__synapses_types__) + ['All'], default = 'All')
config.synapse = synapse


@staticmethod
def add_args( parser: argparse.ArgumentParser ):
run_parser = parser.add_parser(
'run',
add_help=True,
help='''Run the miner.'''
)
run_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
run_parser.add_argument(
'--no_prompt',
dest='no_prompt',
action='store_true',
help='''Set true to avoid prompting the user.''',
default=False,
)
run_parser.add_argument(
'--model',
type=str,
choices= list(bittensor.neurons.__text_neurons__.keys()),
default='None',
help='''Miners available through bittensor.neurons'''
)
run_parser.add_argument(
'--synapse',
type=str,
choices= list(bittensor.synapse.__synapses_types__) + ['All'],
default='None',
help='''Synapses available through bittensor.synapse'''
)
run_parser.add_argument(
'--path',
dest="path",
default=os.path.expanduser('miners/text/core_server.py'),
type=str,
required=False
)
run_parser.add_argument(
'--netuid',
type=int,
help='netuid for subnet to serve this neuron on',
default=argparse.SUPPRESS,
)
bittensor.subtensor.add_args( run_parser )
bittensor.wallet.add_args( run_parser )
194 changes: 194 additions & 0 deletions bittensor/_endpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
""" Create and init endpoint object, with attr hotkey, coldkey, modality and ip
"""
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import json
from typing import Union
import torch
import bittensor

from . import endpoint_impl

MAX_IP_LENGTH = 8*4
MAX_VERSION = 999
SS58_LENGTH = 48
MAXPORT = 65535
MAXUID = 4294967295
ACCEPTABLE_IPTYPES = [4,6,0]
ACCEPTABLE_PROTOCOLS = [0,4] # TODO
ENDPOINT_BUFFER_SIZE = 250

class endpoint:
""" Create and init neuron object, with attr hotkey, coldkey, modality and ip
"""

def __new__(
cls,
version: int,
uid:int,
hotkey:str,
ip:str,
ip_type:int,
port:int,
coldkey:str,
protocol:int = 0, # TODO: activate protocol
modality: int = 0 # TODO: remove modality
) -> 'bittensor.Endpoint':
endpoint.assert_format(
version=version,
uid = uid,
ip = ip,
ip_type = ip_type,
port = port,
coldkey = coldkey,
hotkey = hotkey,
protocol=protocol
)
return endpoint_impl.Endpoint( version, uid, hotkey, ip, ip_type, port, protocol, coldkey, modality )


@staticmethod
def from_neuron( neuron: Union['bittensor.NeuronInfo', 'bittensor.NeuronInfoLite'] ) -> 'bittensor.Endpoint':
"""
endpoint.assert_format(
version = neuron.version,
uid = neuron.uid,
hotkey = neuron.hotkey,
port = neuron.axon_info.port,
ip = neuron.axon_info.ip,
ip_type = neuron.axon_info.ip_type,
protocol = neuron.axon_info.protocol,
coldkey = neuron.coldkey
)
"""
if neuron.is_null:
raise ValueError('Cannot create endpoint from null neuron')

if hasattr(neuron, 'axon_info'): #if config.subtensor.network == 'finney'
return endpoint_impl.Endpoint(
version = neuron.axon_info.version,
uid = neuron.uid,
hotkey = neuron.hotkey,
port = neuron.axon_info.port,
ip = neuron.axon_info.ip,
ip_type = neuron.axon_info.ip_type,
protocol = neuron.axon_info.protocol,
coldkey = neuron.coldkey
)
else:
return endpoint_impl.Endpoint(
version = neuron.version,
uid = neuron.uid,
hotkey = neuron.hotkey,
port = neuron.port,
ip = neuron.ip,
ip_type = neuron.ip_type,
modality = neuron.modality,
coldkey = neuron.coldkey,
protocol = None
)

@staticmethod
def from_dict(endpoint_dict: dict) -> 'bittensor.Endpoint':
""" Return an endpoint with spec from dictionary
"""
if not endpoint.assert_format(
version = endpoint_dict['version'],
uid = endpoint_dict['uid'],
hotkey = endpoint_dict['hotkey'],
port = endpoint_dict['port'],
ip = endpoint_dict['ip'],
ip_type = endpoint_dict['ip_type'],
protocol = endpoint_dict['protocol'],
coldkey = endpoint_dict['coldkey']
):
raise ValueError('Invalid endpoint dict')
return endpoint_impl.Endpoint(
version = endpoint_dict['version'],
uid = endpoint_dict['uid'],
hotkey = endpoint_dict['hotkey'],
port = endpoint_dict['port'],
ip = endpoint_dict['ip'],
ip_type = endpoint_dict['ip_type'],
protocol = endpoint_dict['protocol'],
coldkey = endpoint_dict['coldkey']
)

@staticmethod
def from_tensor( tensor: torch.LongTensor) -> 'bittensor.Endpoint':
""" Return an endpoint with spec from tensor
"""
if len(tensor.shape) == 2:
if tensor.shape[0] != 1:
error_msg = 'Endpoints tensor should have a single first dimension or none got {}'.format( tensor.shape[0] )
raise ValueError(error_msg)
tensor = tensor[0]

if tensor.shape[0] != ENDPOINT_BUFFER_SIZE:
error_msg = 'Endpoints tensor should be length {}, got {}'.format( tensor.shape[0], ENDPOINT_BUFFER_SIZE)
raise ValueError(error_msg)

endpoint_list = tensor.tolist()
if -1 in endpoint_list:
endpoint_list = endpoint_list[ :endpoint_list.index(-1)]

if len(endpoint_list) == 0:
return endpoint.dummy()
else:
endpoint_bytes = bytearray( endpoint_list )
endpoint_string = endpoint_bytes.decode('utf-8')
endpoint_dict = json.loads( endpoint_string )
try:
return endpoint.from_dict(endpoint_dict)
except ValueError:
return endpoint.dummy()

@staticmethod
def dummy():
return endpoint_impl.Endpoint(uid=0, version=0, hotkey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ip_type = 4, ip = '0.0.0.0', port = 0, protocol= 0, coldkey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

@staticmethod
def assert_format(
version: int,
uid:int,
hotkey:str,
ip:str,
ip_type:int,
port:int,
protocol:int,
coldkey:str
) -> bool:
""" Asserts that the endpoint has a valid format
"""
try:
assert version >= 0, 'endpoint version must be positive. - got {}'.format(version)
assert version <= MAX_VERSION, 'endpoint version must be less than 999. - got {}'.format(version)
assert uid >= 0 and uid <= MAXUID, 'endpoint uid must positive and be less than u32 max: 4294967295. - got {}'.format(uid)
assert len(ip) < MAX_IP_LENGTH, 'endpoint ip string must have length less than 8*4. - got {}'.format(ip)
assert ip_type in ACCEPTABLE_IPTYPES, 'endpoint ip_type must be either 4 or 6.- got {}'.format(ip_type)
assert port >= 0 and port < MAXPORT , 'port must be positive and less than 65535 - got {}'.format(port)
assert len(coldkey) == SS58_LENGTH, 'coldkey string must be length 48 - got {}'.format(coldkey)
assert len(hotkey) == SS58_LENGTH, 'hotkey string must be length 48 - got {}'.format(hotkey)
# TODO
assert protocol in ACCEPTABLE_PROTOCOLS, 'protocol must be 0 (for now) - got {}'.format(protocol)

return True
except AssertionError:
return False


Loading

0 comments on commit 7bfb96c

Please sign in to comment.