diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-05 08:39:55 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-05 08:39:55 +0000 |
commit | fe8ffd0eb02b2a1d96540928162aaf1b2d60636a (patch) | |
tree | b42a4aab5d8c9be153966ae277a0d18ac384fcf6 | |
parent | ff7f72002407d8428d55af1a58a5281d03e95699 (diff) |
automatic import of python-bittensoropeneuler20.03
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-bittensor.spec | 918 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 920 insertions, 0 deletions
@@ -0,0 +1 @@ +/bittensor-4.0.1.tar.gz diff --git a/python-bittensor.spec b/python-bittensor.spec new file mode 100644 index 0000000..bd3a845 --- /dev/null +++ b/python-bittensor.spec @@ -0,0 +1,918 @@ +%global _empty_manifest_terminate_build 0 +Name: python-bittensor +Version: 4.0.1 +Release: 1 +Summary: bittensor +License: MIT +URL: https://github.com/opentensor/bittensor +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/b2/b7/edd639c895875c16cc864ebc383a7c660fc849cb7bb0551c89b252ac1398/bittensor-4.0.1.tar.gz +BuildArch: noarch + +Requires: python3-ansible-vault +Requires: python3-argparse +Requires: python3-backoff +Requires: python3-base58 +Requires: python3-certifi +Requires: python3-cryptography +Requires: python3-fuzzywuzzy +Requires: python3-google-api-python-client +Requires: python3-grpcio-tools +Requires: python3-grpcio +Requires: python3-hypothesis +Requires: python3-idna +Requires: python3-jinja2 +Requires: python3-jsonschema[format-nongpl] +Requires: python3-loguru +Requires: python3-markupsafe +Requires: python3-miniupnpc +Requires: python3-msgpack-numpy +Requires: python3-msgpack +Requires: python3-munch +Requires: python3-nest-asyncio +Requires: python3-netaddr +Requires: python3-numpy +Requires: python3-pandas +Requires: python3-password-strength +Requires: python3-prometheus-client +Requires: python3-protobuf +Requires: python3-psutil +Requires: python3-py-bip39-bindings +Requires: python3-py-ed25519-bindings +Requires: python3-py-sr25519-bindings +Requires: python3-pycryptodome +Requires: python3-levenshtein +Requires: python3-pyyaml +Requires: python3-qqdm +Requires: python3-requests +Requires: python3-retry +Requires: python3-rich +Requires: python3-scalecodec +Requires: python3-sentencepiece +Requires: python3-substrate-interface +Requires: python3-termcolor +Requires: python3-torch +Requires: python3-tqdm +Requires: python3-transformers +Requires: python3-wandb +Requires: python3-wheel +Requires: python3-coveralls +Requires: python3-ddt +Requires: python3-pytest-cov +Requires: python3-pytest-rerunfailures +Requires: python3-pytest-split +Requires: python3-pytest-xdist +Requires: python3-pytest + +%description +### Internet-scale Neural Networks <!-- omit in toc --> +[Discord](https://discord.gg/bittensor) • [Docs](https://docs.bittensor.com/) • [Network](https://www.bittensor.com/network) • [Research](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU) • [Code](https://github.com/opentensor/BitTensor) +</div> +This repository contains Bittensor's Python API, which can be used for the following purposes: +1. Querying the Bittensor network as a [client](https://github.com/opentensor/bittensor#31-client). +2. Running and building Bittensor miners and validators for [mining TAO](https://github.com/opentensor/bittensor#43-running-a-template-miner). +3. Pulling network [state information](https://github.com/opentensor/bittensor#3-using-bittensor). +4. Managing [TAO wallets](https://github.com/opentensor/bittensor#41-cli), balances, transfers, etc. +Bittensor is a mining network, similar to Bitcoin, that includes built-in incentives designed to encourage miners to provide value by hosting trained or training machine learning models. These models can be queried by clients seeking inference over inputs, such as token-based text generations or numerical embeddings from a large foundation model like GPT-NeoX-20B. +Token-based incentives are designed to drive the network's growth and distribute the value generated by the network directly to the individuals producing that value, without intermediaries. The network is open to all participants, and no individual or group has full control over what is learned, who can profit from it, or who can access it. +To learn more about Bittensor, please read our [paper](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU/view). +- [1. Documentation](#1-documentation) +- [2. Install](#2-install) +- [3. Using Bittensor](#3-using-bittensor) + - [3.1. Client](#31-client) + - [3.2. Server](#32-server) + - [3.3. Validator](#33-validator) +- [4. Features](#4-features) + - [4.1. Using the CLI](#41-cli) + - [4.2. Selecting the network to join](#42-selecting-the-network-to-join) + - [4.3. Running a template miner](#43-running-a-template-miner) + - [4.4. Running a template server](#44-running-a-template-server) + - [4.5. Syncing with the chain/ Finding the ranks/stake/uids of other nodes](#46-syncing-with-the-chain-finding-the-ranksstakeuids-of-other-nodes) + - [4.6. Finding and creating the endpoints for other nodes in the network](#47-finding-and-creating-the-endpoints-for-other-nodes-in-the-network) + - [4.7. Querying others in the network](#48-querying-others-in-the-network) +- [5. Release](#5-release) +- [6. License](#6-license) +- [7. Acknowledgments](#7-acknowledgments) +## 1. Documentation +https://docs.bittensor.com/ +## 2. Install +Three ways to install Bittensor +1. Through the installer: +``` +$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/opentensor/bittensor/master/scripts/install.sh)" +``` +2. With pip: +```bash +$ pip3 install bittensor +``` +3. From source: +``` +$ git clone https://github.com/opentensor/bittensor.git +$ python3 -m pip install -e bittensor/ +``` +## 3. Using Bittensor +The following examples showcase how to use the Bittensor API for 3 separate purposes. +### 3.1. Client +Querying the network for generations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).generate + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + prompt = "The quick brown fox jumped over the lazy dog", + num_to_generate = 20 + ) +) +``` +Querying the network for representations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).text_last_hidden_state + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + inputs = "The quick brown fox jumped over the lazy dog" + ) +) +// Apply model. +loss.backward() // Accumulate gradients on endpoints. +``` +### 3.2. Server +Serving a custom model. +```python +import bittensor +import torch +from transformers import GPT2Model, GPT2Config +model = GPT2Model( GPT2Config(vocab_size = bittensor.__vocab_size__, n_embd = bittensor.__network_dim__ , n_head = 8)) +optimizer = torch.optim.SGD( [ {"params": model.parameters()} ], lr = 0.01 ) +def forward_text( pubkey, inputs_x ): + return model( inputs_x ) +def backward_text( pubkey, inputs_x, grads_dy ): + with torch.enable_grad(): + outputs_y = model( inputs_x.to(device) ).last_hidden_state + torch.autograd.backward ( + tensors = [ outputs_y.to(device) ], + grad_tensors = [ grads_dy.to(device) ] + ) + optimizer.step() + optimizer.zero_grad() +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 3.3. Validator +Validating models by setting weights. +```python +import bittensor +import torch +graph = bittensor.metagraph().sync() +dataset = bittensor.dataset() +chain_weights = torch.ones( [graph.n.item()], dtype = torch.float32 ) +for batch in dataset.dataloader( 10 ): + // Train chain_weights. +bittensor.subtensor().set_weights ( + weights = chain_weights, + uids = graph.uids, + wait_for_inclusion = True, + wallet = bittensor.wallet(), +) +``` +## 4. Features +### 4.1. CLI +Creating a new wallet. +```bash +$ btcli new_coldkey +$ btcli new_hotkey +``` +Listing your wallets +```bash +$ btcli list +``` +Registering a wallet +```bash +$ btcli register +``` +Running a miner +```bash +$ btcli run +``` +Checking balances +```bash +$ btcli overview +``` +Checking the incentive mechanism. +```bash +$ btcli metagraph +``` +Transfering funds +```bash +$ btcli transfer +``` +Staking/Unstaking from a hotkey +```bash +$ btcli stake +$ btcli unstake +``` +### 4.2. Selecting the network to join +There are two open Bittensor networks: staging (Nobunaga) and main (Nakamoto, Local). +- Nobunaga (staging) +- Nakamoto (main) +- Local (localhost, mirrors nakamoto) +```bash +$ export NETWORK=local +$ python (..) --subtensor.network $NETWORK +or +>> btcli run --subtensor.network $NETWORK +``` +### 4.3. Running a template miner +The following command will run Bittensor's template miner +```bash +$ cd bittensor +$ python ./bittensor/_neuron/text/template_miner/main.py +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.template_miner.neuron().run() +``` +OR with customized settings +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/template_miner/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +For the full list of settings, please run +```bash +$ python3 ~/.bittensor/bittensor/bittensor/_neuron/neurons/text/template_miner/main.py --help +``` +### 4.4. Running a template server +The template server follows a similar structure as the template miner. +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.core_server.neuron().run() +``` +For the full list of settings, please run +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --help +``` +### 4.5. Serving an endpoint on the network +Endpoints are served to the bittensor network through the axon. The axon is instantiated via a wallet which holds an account on the Bittensor network. +```python +import bittensor +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 4.6. Syncing with the chain/ Finding the ranks/stake/uids of other nodes +Information from the chain is collected/formated by the metagraph. +```bash +btcli metagraph +``` +and +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +# --- uid --- +print(meta.uids) +# --- hotkeys --- +print(meta.hotkeys) +# --- ranks --- +print(meta.R) +# --- stake --- +print(meta.S) +``` +### 4.7. Finding and creating the endpoints for other nodes in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_as_tensor = meta.endpoints[0] +endpoint_as_object = meta.endpoint_objs[0] +``` +### 4.8. Querying others in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_0 = meta.endpoints[0] +### Creating the wallet, and dendrite +wallet = bittensor.wallet().create().register() +den = bittensor.dendrite(wallet = wallet) +representations, _, _ = den.forward_text ( + endpoints = endpoint_0, + inputs = "Hello World" +) +``` +## 5. Release +The release manager should follow the instructions of the [RELEASE_GUIDELINES.md](./RELEASE_GUIDELINES.md) document. +## 6. License +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. +## 7. Acknowledgments +**learning-at-home/hivemind** + +%package -n python3-bittensor +Summary: bittensor +Provides: python-bittensor +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-bittensor +### Internet-scale Neural Networks <!-- omit in toc --> +[Discord](https://discord.gg/bittensor) • [Docs](https://docs.bittensor.com/) • [Network](https://www.bittensor.com/network) • [Research](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU) • [Code](https://github.com/opentensor/BitTensor) +</div> +This repository contains Bittensor's Python API, which can be used for the following purposes: +1. Querying the Bittensor network as a [client](https://github.com/opentensor/bittensor#31-client). +2. Running and building Bittensor miners and validators for [mining TAO](https://github.com/opentensor/bittensor#43-running-a-template-miner). +3. Pulling network [state information](https://github.com/opentensor/bittensor#3-using-bittensor). +4. Managing [TAO wallets](https://github.com/opentensor/bittensor#41-cli), balances, transfers, etc. +Bittensor is a mining network, similar to Bitcoin, that includes built-in incentives designed to encourage miners to provide value by hosting trained or training machine learning models. These models can be queried by clients seeking inference over inputs, such as token-based text generations or numerical embeddings from a large foundation model like GPT-NeoX-20B. +Token-based incentives are designed to drive the network's growth and distribute the value generated by the network directly to the individuals producing that value, without intermediaries. The network is open to all participants, and no individual or group has full control over what is learned, who can profit from it, or who can access it. +To learn more about Bittensor, please read our [paper](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU/view). +- [1. Documentation](#1-documentation) +- [2. Install](#2-install) +- [3. Using Bittensor](#3-using-bittensor) + - [3.1. Client](#31-client) + - [3.2. Server](#32-server) + - [3.3. Validator](#33-validator) +- [4. Features](#4-features) + - [4.1. Using the CLI](#41-cli) + - [4.2. Selecting the network to join](#42-selecting-the-network-to-join) + - [4.3. Running a template miner](#43-running-a-template-miner) + - [4.4. Running a template server](#44-running-a-template-server) + - [4.5. Syncing with the chain/ Finding the ranks/stake/uids of other nodes](#46-syncing-with-the-chain-finding-the-ranksstakeuids-of-other-nodes) + - [4.6. Finding and creating the endpoints for other nodes in the network](#47-finding-and-creating-the-endpoints-for-other-nodes-in-the-network) + - [4.7. Querying others in the network](#48-querying-others-in-the-network) +- [5. Release](#5-release) +- [6. License](#6-license) +- [7. Acknowledgments](#7-acknowledgments) +## 1. Documentation +https://docs.bittensor.com/ +## 2. Install +Three ways to install Bittensor +1. Through the installer: +``` +$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/opentensor/bittensor/master/scripts/install.sh)" +``` +2. With pip: +```bash +$ pip3 install bittensor +``` +3. From source: +``` +$ git clone https://github.com/opentensor/bittensor.git +$ python3 -m pip install -e bittensor/ +``` +## 3. Using Bittensor +The following examples showcase how to use the Bittensor API for 3 separate purposes. +### 3.1. Client +Querying the network for generations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).generate + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + prompt = "The quick brown fox jumped over the lazy dog", + num_to_generate = 20 + ) +) +``` +Querying the network for representations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).text_last_hidden_state + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + inputs = "The quick brown fox jumped over the lazy dog" + ) +) +// Apply model. +loss.backward() // Accumulate gradients on endpoints. +``` +### 3.2. Server +Serving a custom model. +```python +import bittensor +import torch +from transformers import GPT2Model, GPT2Config +model = GPT2Model( GPT2Config(vocab_size = bittensor.__vocab_size__, n_embd = bittensor.__network_dim__ , n_head = 8)) +optimizer = torch.optim.SGD( [ {"params": model.parameters()} ], lr = 0.01 ) +def forward_text( pubkey, inputs_x ): + return model( inputs_x ) +def backward_text( pubkey, inputs_x, grads_dy ): + with torch.enable_grad(): + outputs_y = model( inputs_x.to(device) ).last_hidden_state + torch.autograd.backward ( + tensors = [ outputs_y.to(device) ], + grad_tensors = [ grads_dy.to(device) ] + ) + optimizer.step() + optimizer.zero_grad() +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 3.3. Validator +Validating models by setting weights. +```python +import bittensor +import torch +graph = bittensor.metagraph().sync() +dataset = bittensor.dataset() +chain_weights = torch.ones( [graph.n.item()], dtype = torch.float32 ) +for batch in dataset.dataloader( 10 ): + // Train chain_weights. +bittensor.subtensor().set_weights ( + weights = chain_weights, + uids = graph.uids, + wait_for_inclusion = True, + wallet = bittensor.wallet(), +) +``` +## 4. Features +### 4.1. CLI +Creating a new wallet. +```bash +$ btcli new_coldkey +$ btcli new_hotkey +``` +Listing your wallets +```bash +$ btcli list +``` +Registering a wallet +```bash +$ btcli register +``` +Running a miner +```bash +$ btcli run +``` +Checking balances +```bash +$ btcli overview +``` +Checking the incentive mechanism. +```bash +$ btcli metagraph +``` +Transfering funds +```bash +$ btcli transfer +``` +Staking/Unstaking from a hotkey +```bash +$ btcli stake +$ btcli unstake +``` +### 4.2. Selecting the network to join +There are two open Bittensor networks: staging (Nobunaga) and main (Nakamoto, Local). +- Nobunaga (staging) +- Nakamoto (main) +- Local (localhost, mirrors nakamoto) +```bash +$ export NETWORK=local +$ python (..) --subtensor.network $NETWORK +or +>> btcli run --subtensor.network $NETWORK +``` +### 4.3. Running a template miner +The following command will run Bittensor's template miner +```bash +$ cd bittensor +$ python ./bittensor/_neuron/text/template_miner/main.py +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.template_miner.neuron().run() +``` +OR with customized settings +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/template_miner/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +For the full list of settings, please run +```bash +$ python3 ~/.bittensor/bittensor/bittensor/_neuron/neurons/text/template_miner/main.py --help +``` +### 4.4. Running a template server +The template server follows a similar structure as the template miner. +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.core_server.neuron().run() +``` +For the full list of settings, please run +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --help +``` +### 4.5. Serving an endpoint on the network +Endpoints are served to the bittensor network through the axon. The axon is instantiated via a wallet which holds an account on the Bittensor network. +```python +import bittensor +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 4.6. Syncing with the chain/ Finding the ranks/stake/uids of other nodes +Information from the chain is collected/formated by the metagraph. +```bash +btcli metagraph +``` +and +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +# --- uid --- +print(meta.uids) +# --- hotkeys --- +print(meta.hotkeys) +# --- ranks --- +print(meta.R) +# --- stake --- +print(meta.S) +``` +### 4.7. Finding and creating the endpoints for other nodes in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_as_tensor = meta.endpoints[0] +endpoint_as_object = meta.endpoint_objs[0] +``` +### 4.8. Querying others in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_0 = meta.endpoints[0] +### Creating the wallet, and dendrite +wallet = bittensor.wallet().create().register() +den = bittensor.dendrite(wallet = wallet) +representations, _, _ = den.forward_text ( + endpoints = endpoint_0, + inputs = "Hello World" +) +``` +## 5. Release +The release manager should follow the instructions of the [RELEASE_GUIDELINES.md](./RELEASE_GUIDELINES.md) document. +## 6. License +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. +## 7. Acknowledgments +**learning-at-home/hivemind** + +%package help +Summary: Development documents and examples for bittensor +Provides: python3-bittensor-doc +%description help +### Internet-scale Neural Networks <!-- omit in toc --> +[Discord](https://discord.gg/bittensor) • [Docs](https://docs.bittensor.com/) • [Network](https://www.bittensor.com/network) • [Research](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU) • [Code](https://github.com/opentensor/BitTensor) +</div> +This repository contains Bittensor's Python API, which can be used for the following purposes: +1. Querying the Bittensor network as a [client](https://github.com/opentensor/bittensor#31-client). +2. Running and building Bittensor miners and validators for [mining TAO](https://github.com/opentensor/bittensor#43-running-a-template-miner). +3. Pulling network [state information](https://github.com/opentensor/bittensor#3-using-bittensor). +4. Managing [TAO wallets](https://github.com/opentensor/bittensor#41-cli), balances, transfers, etc. +Bittensor is a mining network, similar to Bitcoin, that includes built-in incentives designed to encourage miners to provide value by hosting trained or training machine learning models. These models can be queried by clients seeking inference over inputs, such as token-based text generations or numerical embeddings from a large foundation model like GPT-NeoX-20B. +Token-based incentives are designed to drive the network's growth and distribute the value generated by the network directly to the individuals producing that value, without intermediaries. The network is open to all participants, and no individual or group has full control over what is learned, who can profit from it, or who can access it. +To learn more about Bittensor, please read our [paper](https://drive.google.com/file/d/1VnsobL6lIAAqcA1_Tbm8AYIQscfJV4KU/view). +- [1. Documentation](#1-documentation) +- [2. Install](#2-install) +- [3. Using Bittensor](#3-using-bittensor) + - [3.1. Client](#31-client) + - [3.2. Server](#32-server) + - [3.3. Validator](#33-validator) +- [4. Features](#4-features) + - [4.1. Using the CLI](#41-cli) + - [4.2. Selecting the network to join](#42-selecting-the-network-to-join) + - [4.3. Running a template miner](#43-running-a-template-miner) + - [4.4. Running a template server](#44-running-a-template-server) + - [4.5. Syncing with the chain/ Finding the ranks/stake/uids of other nodes](#46-syncing-with-the-chain-finding-the-ranksstakeuids-of-other-nodes) + - [4.6. Finding and creating the endpoints for other nodes in the network](#47-finding-and-creating-the-endpoints-for-other-nodes-in-the-network) + - [4.7. Querying others in the network](#48-querying-others-in-the-network) +- [5. Release](#5-release) +- [6. License](#6-license) +- [7. Acknowledgments](#7-acknowledgments) +## 1. Documentation +https://docs.bittensor.com/ +## 2. Install +Three ways to install Bittensor +1. Through the installer: +``` +$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/opentensor/bittensor/master/scripts/install.sh)" +``` +2. With pip: +```bash +$ pip3 install bittensor +``` +3. From source: +``` +$ git clone https://github.com/opentensor/bittensor.git +$ python3 -m pip install -e bittensor/ +``` +## 3. Using Bittensor +The following examples showcase how to use the Bittensor API for 3 separate purposes. +### 3.1. Client +Querying the network for generations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).generate + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + prompt = "The quick brown fox jumped over the lazy dog", + num_to_generate = 20 + ) +) +``` +Querying the network for representations. +```python +import bittensor +wallet = bittensor.wallet().create_if_non_existent() +graph = bittensor.metagraph().sync() +print ( bittensor.dendrite( wallet = wallet ).text_last_hidden_state + ( + endpoints = graph.endpoints[graph.incentive.sort()[1][-1]], // The highest ranked peer. + inputs = "The quick brown fox jumped over the lazy dog" + ) +) +// Apply model. +loss.backward() // Accumulate gradients on endpoints. +``` +### 3.2. Server +Serving a custom model. +```python +import bittensor +import torch +from transformers import GPT2Model, GPT2Config +model = GPT2Model( GPT2Config(vocab_size = bittensor.__vocab_size__, n_embd = bittensor.__network_dim__ , n_head = 8)) +optimizer = torch.optim.SGD( [ {"params": model.parameters()} ], lr = 0.01 ) +def forward_text( pubkey, inputs_x ): + return model( inputs_x ) +def backward_text( pubkey, inputs_x, grads_dy ): + with torch.enable_grad(): + outputs_y = model( inputs_x.to(device) ).last_hidden_state + torch.autograd.backward ( + tensors = [ outputs_y.to(device) ], + grad_tensors = [ grads_dy.to(device) ] + ) + optimizer.step() + optimizer.zero_grad() +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 3.3. Validator +Validating models by setting weights. +```python +import bittensor +import torch +graph = bittensor.metagraph().sync() +dataset = bittensor.dataset() +chain_weights = torch.ones( [graph.n.item()], dtype = torch.float32 ) +for batch in dataset.dataloader( 10 ): + // Train chain_weights. +bittensor.subtensor().set_weights ( + weights = chain_weights, + uids = graph.uids, + wait_for_inclusion = True, + wallet = bittensor.wallet(), +) +``` +## 4. Features +### 4.1. CLI +Creating a new wallet. +```bash +$ btcli new_coldkey +$ btcli new_hotkey +``` +Listing your wallets +```bash +$ btcli list +``` +Registering a wallet +```bash +$ btcli register +``` +Running a miner +```bash +$ btcli run +``` +Checking balances +```bash +$ btcli overview +``` +Checking the incentive mechanism. +```bash +$ btcli metagraph +``` +Transfering funds +```bash +$ btcli transfer +``` +Staking/Unstaking from a hotkey +```bash +$ btcli stake +$ btcli unstake +``` +### 4.2. Selecting the network to join +There are two open Bittensor networks: staging (Nobunaga) and main (Nakamoto, Local). +- Nobunaga (staging) +- Nakamoto (main) +- Local (localhost, mirrors nakamoto) +```bash +$ export NETWORK=local +$ python (..) --subtensor.network $NETWORK +or +>> btcli run --subtensor.network $NETWORK +``` +### 4.3. Running a template miner +The following command will run Bittensor's template miner +```bash +$ cd bittensor +$ python ./bittensor/_neuron/text/template_miner/main.py +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.template_miner.neuron().run() +``` +OR with customized settings +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/template_miner/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +For the full list of settings, please run +```bash +$ python3 ~/.bittensor/bittensor/bittensor/_neuron/neurons/text/template_miner/main.py --help +``` +### 4.4. Running a template server +The template server follows a similar structure as the template miner. +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> +``` +or +```python3 +>> import bittensor +>> bittensor.neurons.text.core_server.neuron().run() +``` +For the full list of settings, please run +```bash +$ cd bittensor +$ python3 ./bittensor/_neuron/text/core_server/main.py --help +``` +### 4.5. Serving an endpoint on the network +Endpoints are served to the bittensor network through the axon. The axon is instantiated via a wallet which holds an account on the Bittensor network. +```python +import bittensor +wallet = bittensor.wallet().create().register() +axon = bittensor.axon ( + wallet = wallet, + forward_text = forward_text, + backward_text = backward_text +).start().serve() +``` +### 4.6. Syncing with the chain/ Finding the ranks/stake/uids of other nodes +Information from the chain is collected/formated by the metagraph. +```bash +btcli metagraph +``` +and +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +# --- uid --- +print(meta.uids) +# --- hotkeys --- +print(meta.hotkeys) +# --- ranks --- +print(meta.R) +# --- stake --- +print(meta.S) +``` +### 4.7. Finding and creating the endpoints for other nodes in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_as_tensor = meta.endpoints[0] +endpoint_as_object = meta.endpoint_objs[0] +``` +### 4.8. Querying others in the network +```python +import bittensor +meta = bittensor.metagraph() +meta.sync() +### Address for the node uid 0 +endpoint_0 = meta.endpoints[0] +### Creating the wallet, and dendrite +wallet = bittensor.wallet().create().register() +den = bittensor.dendrite(wallet = wallet) +representations, _, _ = den.forward_text ( + endpoints = endpoint_0, + inputs = "Hello World" +) +``` +## 5. Release +The release manager should follow the instructions of the [RELEASE_GUIDELINES.md](./RELEASE_GUIDELINES.md) document. +## 6. License +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. +## 7. Acknowledgments +**learning-at-home/hivemind** + +%prep +%autosetup -n bittensor-4.0.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-bittensor -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 4.0.1-1 +- Package Spec generated @@ -0,0 +1 @@ +f932e57348fda9a37f8d0e3227242d48 bittensor-4.0.1.tar.gz |