Exemplo n.º 1
0
 def add_args(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
     parser.add_argument(
         '--neuron.hotkeyfile',
         required=False,
         default='~/.bittensor/wallets/default/hotkeys/default',
         help='''The path to your bittensor hot key file,
                                     Hotkeys should not hold tokens and are only used
                                     for suscribing and setting weights from running code.
                                     Hotkeys are linked to coldkeys through the metagraph'''
     )
     parser.add_argument(
         '--neuron.coldkeyfile',
         required=False,
         default='~/.bittensor/wallets/default/coldkeypub.txt',
         help='''The path to your bittensor cold publickey text file.
                                     Coldkeys can hold tokens and should be encrypted on your device.
                                     The coldkey must be used to stake and unstake funds from a running node.
                                     On subscribe this coldkey account is linked to the associated hotkey on the subtensor chain.
                                     Only this key is capable of making staking and unstaking requests for this neuron.'''
     )
     Axon.add_args(parser)
     Dendrite.add_args(parser)
     Metagraph.add_args(parser)
     Nucleus.add_args(parser)
     return parser
Exemplo n.º 2
0
def test_not_implemented():
    nucleus = Nucleus(config, metagraph)
    synapse = Synapse(None)
    x = torch.tensor([])
    mode = bittensor_pb2.Modality.TEXT
    outputs, _, code = nucleus.forward(synapse=synapse,
                                       inputs=x,
                                       mode=mode,
                                       priority=1)
    assert outputs == None
    assert code == bittensor_pb2.ReturnCode.NotImplemented
Exemplo n.º 3
0
def test_backward_success():
    nucleus = Nucleus(config, metagraph)
    synapse = Synapse(None)
    x = torch.rand(3, 3)
    synapse.call_backward = MagicMock(return_value=x)
    mode = bittensor_pb2.Modality.TEXT
    nucleus.backward(synapse=synapse,
                     inputs_x=x,
                     grads_dy=x,
                     mode=mode,
                     priority=1)
Exemplo n.º 4
0
def test_forward_success():
    nucleus = Nucleus(config, metagraph)
    synapse = Synapse(None)
    x = torch.rand(3, 3)
    synapse.call_forward = MagicMock(return_value=x)
    mode = bittensor_pb2.Modality.TEXT
    outputs, _, code = nucleus.forward(synapse=synapse,
                                       inputs=x,
                                       mode=mode,
                                       priority=1)
    assert list(outputs.shape) == [3, 3]
    assert code == bittensor_pb2.ReturnCode.Success
Exemplo n.º 5
0
def test_stress_test():
    n_to_call = 100
    config.nucleus.queue_maxsize = 10000
    config.nucleus.queue_timeout = n_to_call
    nucleus = Nucleus(config, metagraph)
    synapse = SlowSynapse(None)
    x = torch.rand(3, 3, bittensor.__network_dim__)
    mode = bittensor_pb2.Modality.TEXT

    def _call_nucleus_forward():
        _, _, code = nucleus.forward(synapse=synapse,
                                     inputs=x,
                                     mode=mode,
                                     priority=random.random())
        return code

    # Create many futures.
    futures = []
    with concurrent.futures.ThreadPoolExecutor() as executor:
        for _ in range(n_to_call):
            futures.append(executor.submit(_call_nucleus_forward))

    # All should return success fully.
    for f in futures:
        code = f.result()
        print(code)
        if code != bittensor_pb2.ReturnCode.Success:
            assert False

    assert True
Exemplo n.º 6
0
def test_queue_full():
    config.nucleus.queue_maxsize = 10
    nucleus = Nucleus(config, metagraph)
    synapse = SlowSynapse(None)
    x = torch.rand(3, 3, bittensor.__network_dim__)
    mode = bittensor_pb2.Modality.TEXT

    def _call_nucleus_forward():
        _, _, code = nucleus.forward(synapse=synapse,
                                     inputs=x,
                                     mode=mode,
                                     priority=random.random())
        return code

    # Create many futures.
    futures = []
    with concurrent.futures.ThreadPoolExecutor() as executor:
        for _ in range(100):
            futures.append(executor.submit(_call_nucleus_forward))

    # Check future codes, should get at least one queue full.
    for f in futures:
        code = f.result()
        if code == bittensor_pb2.ReturnCode.NucleusFull:
            return

    # One should be a timeout.
    assert False
Exemplo n.º 7
0
 def check_config(config: Munch):
     Dendrite.check_config(config)
     Metagraph.check_config(config)
     Axon.check_config(config)
     Nucleus.check_config(config)
     Neuron.__check_hot_key_path(config.neuron.hotkeyfile)
     Neuron.__check_cold_key_path(config.neuron.coldkeyfile)
     try:
         Neuron.load_hotkeypair(config)
         Neuron.load_cold_key(config)
     except (KeyError):
         logger.error("Invalid password")
         quit()
     except KeyFileError:
         logger.error("Keyfile corrupt")
         quit()
Exemplo n.º 8
0
def test_multiple_forward_success():
    nucleus = Nucleus(config, metagraph)
    synapse = Synapse(None)
    x = torch.rand(3, 3, bittensor.__network_dim__)
    synapse.call_forward = MagicMock(return_value=x)
    mode = bittensor_pb2.Modality.TEXT
    outputs1, _, code1 = nucleus.forward(synapse=synapse,
                                         inputs=x,
                                         mode=mode,
                                         priority=1)
    outputs2, _, code2 = nucleus.forward(synapse=synapse,
                                         inputs=x,
                                         mode=mode,
                                         priority=1)
    outputs3, _, code3 = nucleus.forward(synapse=synapse,
                                         inputs=x,
                                         mode=mode,
                                         priority=1)
    outputs4, _, code4 = nucleus.forward(synapse=synapse,
                                         inputs=x,
                                         mode=mode,
                                         priority=1)
    outputs5, _, code5 = nucleus.forward(synapse=synapse,
                                         inputs=x,
                                         mode=mode,
                                         priority=1)

    assert list(outputs1.shape) == [3, 3, bittensor.__network_dim__]
    assert list(outputs2.shape) == [3, 3, bittensor.__network_dim__]
    assert list(outputs3.shape) == [3, 3, bittensor.__network_dim__]
    assert list(outputs4.shape) == [3, 3, bittensor.__network_dim__]
    assert list(outputs5.shape) == [3, 3, bittensor.__network_dim__]

    assert code1 == bittensor_pb2.ReturnCode.Success
    assert code2 == bittensor_pb2.ReturnCode.Success
    assert code3 == bittensor_pb2.ReturnCode.Success
    assert code4 == bittensor_pb2.ReturnCode.Success
    assert code5 == bittensor_pb2.ReturnCode.Success
Exemplo n.º 9
0
def test_stop():
    nucleus = Nucleus(config, metagraph)
    nucleus.stop()
Exemplo n.º 10
0
def test_init():
    nucleus = Nucleus(config, metagraph)
Exemplo n.º 11
0
 def __init__(self, config):
     self.config = config
     self.metagraph = Metagraph(self.config)
     self.nucleus = Nucleus(self.config, self.metagraph)
     self.axon = Axon(self.config, self.nucleus, self.metagraph)
     self.dendrite = Dendrite(self.config, self.metagraph)
Exemplo n.º 12
0
    'meta_logger': {
        'log_dir': 'data/'
    },
    'neuron': {
        'keyfile': None,
        'keypair': None
    }
}

config = Munch.fromDict(config)
mnemonic = Keypair.generate_mnemonic()
keypair = Keypair.create_from_mnemonic(mnemonic)
config.neuron.keypair = keypair

metagraph = Metagraph(config)
nucleus = Nucleus(config, metagraph)
axon = bittensor.axon.Axon(config, nucleus, metagraph)
synapse = Synapse(config)


def test_serve():
    assert axon.synapse == None
    for _ in range(0, 10):
        axon.serve(synapse)
    assert axon.synapse != None


def test_forward_not_implemented():
    axon.serve(synapse)
    nucleus.forward = MagicMock(return_value=[
        None, 'not implemented', bittensor_pb2.ReturnCode.NotImplemented