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

v2.0 #185

Merged
merged 205 commits into from
Apr 4, 2024
Merged

v2.0 #185

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
612c9eb
initial changes to hf miner
p-ferreira Jan 29, 2024
afe3993
adds 8bit and 4bit config
p-ferreira Jan 30, 2024
a424e6e
simplifies torch type logic
p-ferreira Jan 30, 2024
843f9a2
adapt zephyr miner to hf miner
p-ferreira Jan 30, 2024
e51ff26
update README for hf miner
p-ferreira Jan 30, 2024
65f3b74
adds should_force_model_loading flag to miners
p-ferreira Jan 30, 2024
1ae7540
miners module refactor
p-ferreira Jan 31, 2024
c2d40f6
runs black on miners code
p-ferreira Jan 31, 2024
9669cab
properly adds miner integration with system prompt args
p-ferreira Jan 31, 2024
dde3840
adds check verification on global logger definition
p-ferreira Feb 1, 2024
9b5b91f
clean main func from hf miner
p-ferreira Feb 1, 2024
a8e3bc8
refactor agent code + adds react agent
p-ferreira Feb 5, 2024
369820b
agents adjustments
p-ferreira Feb 5, 2024
53ca503
adds max iteration to agents
p-ferreira Feb 5, 2024
cc2b5c9
fix load llm issue
p-ferreira Feb 5, 2024
ce160ca
fix max tokens param
p-ferreira Feb 5, 2024
b8dd71b
adds toolminer for experiments
p-ferreira Feb 6, 2024
df7638b
fix error case for non wiki match
p-ferreira Feb 7, 2024
8dc340d
increase wiki retries and fix tool_miner bug
p-ferreira Feb 8, 2024
32e2fbf
dsstore gitignore, change miner base
mccrindlebrian Feb 13, 2024
cd45132
edit StreamPromptingSynapse, and add _forward to BaseStreamMinerNeuron
mccrindlebrian Feb 13, 2024
4c1902b
OpenAIUtils
mccrindlebrian Feb 13, 2024
c5066ce
change llm pipeline for streaming
mccrindlebrian Feb 13, 2024
76b7806
hf_miner to streaming
mccrindlebrian Feb 13, 2024
0cd3820
openai stream miner
mccrindlebrian Feb 13, 2024
7f983b4
echo miner
mccrindlebrian Feb 13, 2024
2b30a33
phrase miner
mccrindlebrian Feb 13, 2024
898b4b8
fix bugs
mccrindlebrian Feb 13, 2024
85c46a2
black entire workspace
mccrindlebrian Feb 13, 2024
9ad977a
add try except in langchain miners
mccrindlebrian Feb 13, 2024
4b4af19
format_send on HuggingFaceMiner
mccrindlebrian Feb 13, 2024
f1e5e57
mock miner
mccrindlebrian Feb 13, 2024
4438f15
add handle_response for StreamMiners
mccrindlebrian Feb 13, 2024
b6cf4a5
remove streaming docs
mccrindlebrian Feb 13, 2024
0735046
remove streaming docs
mccrindlebrian Feb 14, 2024
5fe465d
add client-side querying
mccrindlebrian Feb 14, 2024
1e5e9cb
black, debugging
mccrindlebrian Feb 14, 2024
5478ecd
remove format send bc broke streaming
mccrindlebrian Feb 14, 2024
41d3b5c
remove format_send
mccrindlebrian Feb 14, 2024
443f831
black
mccrindlebrian Feb 14, 2024
aa58e8d
Merge branch 'features/hf-miner' into features/streaming
mccrindlebrian Feb 14, 2024
ae8392e
remove .DS_Store
mccrindlebrian Feb 14, 2024
a129564
add tool miner
mccrindlebrian Feb 14, 2024
da90d8e
add timeout checking to stop streaming tokens
mccrindlebrian Feb 14, 2024
1b63bcd
add timeout checking to all miners
mccrindlebrian Feb 14, 2024
78a8281
add return_streamer logic
mccrindlebrian Feb 15, 2024
c7b52c6
remove force
mccrindlebrian Feb 15, 2024
5eeabb7
add thread closing and queue clearing for huggingface models
mccrindlebrian Feb 16, 2024
1f5e54f
add docstrings, more logic for cleaning
mccrindlebrian Feb 16, 2024
f3ec3fc
add timeout check to openai
mccrindlebrian Feb 16, 2024
ab81674
add streaming_batch_size to config
mccrindlebrian Feb 21, 2024
723b64c
remove dep
mccrindlebrian Feb 21, 2024
5792dfc
add wandb logging if wandb.on
mccrindlebrian Feb 21, 2024
3b4df22
remove get_openai_callback, black repo
mccrindlebrian Feb 21, 2024
784b100
fix batch size bug in config
mccrindlebrian Feb 21, 2024
516fb25
add try except to hf miners
mccrindlebrian Feb 21, 2024
1abe949
add try except to tool_miner
mccrindlebrian Feb 21, 2024
38b9a85
Merge branch 'features/streaming' of github.com:opentensor/prompting …
mccrindlebrian Feb 21, 2024
e1f6ddb
add try except to tool_miner
mccrindlebrian Feb 21, 2024
c86431f
add back in blacklist and priorty, test working
mccrindlebrian Feb 21, 2024
6bae36a
change back logging time
mccrindlebrian Feb 21, 2024
22d562a
develop mock dendrite for testing
mccrindlebrian Feb 22, 2024
f0de609
remove dep
mccrindlebrian Feb 22, 2024
425b31d
add tests for stream miners
mccrindlebrian Feb 22, 2024
5f31d16
add docstrings
mccrindlebrian Feb 23, 2024
b7bdf0b
Merge branch 'main' into features/hf-miner
p-ferreira Feb 23, 2024
13c4bea
Merge branch 'features/hf-miner' into features/streaming
mccrindlebrian Feb 23, 2024
157a9f9
change process timing
mccrindlebrian Feb 23, 2024
d3bfcfb
add constants
mccrindlebrian Feb 23, 2024
38232b1
add default port/id
mccrindlebrian Feb 23, 2024
07a73f3
merge staging
mccrindlebrian Feb 28, 2024
8f12375
remove todo
mccrindlebrian Feb 28, 2024
d1255aa
depreciation on agent miners
mccrindlebrian Feb 28, 2024
e94efae
merge main
mccrindlebrian Feb 28, 2024
46f798e
add depreciation to reqs
mccrindlebrian Feb 28, 2024
51de23f
add log_status
mccrindlebrian Feb 28, 2024
39d8ad0
change version to 1.1.2
mccrindlebrian Feb 28, 2024
8957ff9
add docstrings
mccrindlebrian Feb 29, 2024
4f573fb
move exception clause
mccrindlebrian Feb 29, 2024
d31ec32
remove all agents from PR to separate from features/hf-miners
mccrindlebrian Feb 29, 2024
64d67e7
merge pre-staging, resolve conflicts
mccrindlebrian Feb 29, 2024
860ec69
black
mccrindlebrian Feb 29, 2024
f9863b7
test precommit hook
mccrindlebrian Mar 1, 2024
4b0d76f
add .DS_Store and test precommit hook
mccrindlebrian Mar 1, 2024
cb529ee
Merge branch 'pre-staging' into features/hf-miner
p-ferreira Mar 1, 2024
493e7e4
Update prompting/miners/agents/react_agent.py
p-ferreira Mar 1, 2024
7226fa1
Update prompting/miners/openai_miner.py
p-ferreira Mar 1, 2024
6d34528
update docstring
p-ferreira Mar 1, 2024
70ab932
adds deprecation tags to all agent classes
p-ferreira Mar 1, 2024
1ad9571
Manually remove .DS_Store files
steffencruz Mar 1, 2024
41fd140
Remove .DS_Store in all directories
steffencruz Mar 1, 2024
9186c8b
fix flake8 warnings
p-ferreira Mar 1, 2024
7719a48
drops unnecessary run code for base miner
p-ferreira Mar 1, 2024
10fc0ce
Update prompting/miners/openai_miner.py
p-ferreira Mar 1, 2024
acba249
deprecates tool miner
p-ferreira Mar 1, 2024
cb99e73
Merge pull request #91 from opentensor/features/hf-miner
steffencruz Mar 1, 2024
e12e2fc
merge pre-staging, resolve conflicts, delete stream_tutorial docs
mccrindlebrian Mar 2, 2024
10aae24
change test output type
mccrindlebrian Mar 2, 2024
e72b60a
fix breaking tests
mccrindlebrian Mar 4, 2024
e826bfa
fix streaming test with percentage comparison on timeout:
mccrindlebrian Mar 4, 2024
15e6c91
rework where process_time is calculated to minimize time inconsistancies
mccrindlebrian Mar 4, 2024
c13bfff
check if process_time >= timeout
mccrindlebrian Mar 4, 2024
3567259
samples uids only on candidate uids
mccrindlebrian Mar 5, 2024
e19229d
add additional test when k > number of available uids
mccrindlebrian Mar 5, 2024
d55e953
Update neuron.py
steffencruz Mar 6, 2024
01255d1
black entire repo
mccrindlebrian Mar 6, 2024
bf71611
Merge pull request #145 from opentensor/hotfix/black-pre-staging
steffencruz Mar 7, 2024
d44228c
black
mccrindlebrian Mar 7, 2024
c72b1e4
Merge pull request #143 from opentensor/hotfix/fix-set-weights
mccrindlebrian Mar 7, 2024
ab5f6b2
merge pre-staging
mccrindlebrian Mar 11, 2024
66c7dbd
remove tokenizer mapping for models that use different tokenizers tha…
mccrindlebrian Mar 11, 2024
acf3f0a
remove unfinished wording is docstring
mccrindlebrian Mar 11, 2024
bbfdcfe
remove debugging
mccrindlebrian Mar 12, 2024
d969897
add new readme for pre-staging experiments
mccrindlebrian Mar 12, 2024
e316e93
remove old docs
mccrindlebrian Mar 12, 2024
b847daa
add docs for streaming, and change output types of miners
mccrindlebrian Mar 12, 2024
fe6782c
fix typo
mccrindlebrian Mar 12, 2024
c7caf1a
fix client script
mccrindlebrian Mar 12, 2024
5f9c591
add more to readme
mccrindlebrian Mar 12, 2024
aaed470
format docs to stream_miner_template
mccrindlebrian Mar 12, 2024
8b0a3aa
Update prompting/mock.py
mccrindlebrian Mar 12, 2024
9885128
Update prompting/miners/hf_miner.py
mccrindlebrian Mar 12, 2024
deacce0
Update prompting/utils/config.py
steffencruz Mar 12, 2024
ef911db
Update prompting/utils/uids.py
steffencruz Mar 12, 2024
ad9e1ff
Update prompting/utils/uids.py
steffencruz Mar 12, 2024
29680ec
Update prompting/utils/uids.py
steffencruz Mar 12, 2024
6095539
Merge branch 'pre-staging' into features/change-uid-sampling
mccrindlebrian Mar 12, 2024
03c1df4
fix bug with brackets
mccrindlebrian Mar 12, 2024
9b490b4
remove partial kwargs
mccrindlebrian Mar 12, 2024
326a910
Merge pull request #142 from opentensor/features/change-uid-sampling
steffencruz Mar 12, 2024
f879b48
Merge branch 'pre-staging' into features/streaming
mccrindlebrian Mar 12, 2024
720ec70
Apply suggestions from code review
mccrindlebrian Mar 12, 2024
439fb15
remove depreciated miners
mccrindlebrian Mar 12, 2024
e6359ff
Merge branch 'features/streaming' of github.com:opentensor/prompting …
mccrindlebrian Mar 12, 2024
91330cf
Merge pull request #103 from opentensor/features/streaming
steffencruz Mar 12, 2024
d8cbc16
remove miner from init
mccrindlebrian Mar 12, 2024
3c17dc7
Merge pull request #155 from opentensor/hotfix/remove-tool-miner
mccrindlebrian Mar 12, 2024
de1f84c
add torch type to load_pipeline
mccrindlebrian Mar 12, 2024
7395643
add torch type to load_pipeline in miner
mccrindlebrian Mar 12, 2024
94b80c5
Merge pull request #156 from opentensor/hotfix/add-torch-type
mccrindlebrian Mar 12, 2024
aebea20
merge prestaging into vllm
mccrindlebrian Mar 14, 2024
51660a6
fix test_tasks
mccrindlebrian Mar 14, 2024
6e72729
fix broken mockpipeline
mccrindlebrian Mar 14, 2024
28d3984
add customstreamiterator and remove docs
mccrindlebrian Mar 14, 2024
cfa4014
remove deps in openai
mccrindlebrian Mar 14, 2024
3d9eaef
remove old miners
mccrindlebrian Mar 14, 2024
ef221ae
add return streamer back into load_hf_pipeline for mocking
mccrindlebrian Mar 14, 2024
438fd93
black
mccrindlebrian Mar 14, 2024
48c8363
add vllm section
mccrindlebrian Mar 14, 2024
1324eeb
merge pre-staging into vllm streaming
mccrindlebrian Mar 14, 2024
663ed07
adds asyncio semaphore
p-ferreira Mar 14, 2024
f53427a
change docs for axon port
mccrindlebrian Mar 16, 2024
5e3e4bc
Merge pull request #161 from opentensor/hotfix/readme
steffencruz Mar 16, 2024
cb79147
remove return streamer from vllm
mccrindlebrian Mar 18, 2024
a245e02
test code for semaphore
mccrindlebrian Mar 18, 2024
6462df8
refactors streaming miner with asyncio loop approach
p-ferreira Mar 20, 2024
ea37a31
adds custom simple_hf miner with pseudo streaming
p-ferreira Mar 21, 2024
96a155a
overall logging adjustments
p-ferreira Mar 21, 2024
e8a92dd
Merge branch 'main' into pre-staging
p-ferreira Mar 21, 2024
6036fae
Merge branch 'pre-staging' into features/thread_lock_stream
p-ferreira Mar 21, 2024
314544c
fix merge conflicts
p-ferreira Mar 21, 2024
a2404e6
minor updates
p-ferreira Mar 21, 2024
53b60c1
merge pre-staging into vllm streaming
mccrindlebrian Mar 21, 2024
76dc85f
Merge branch 'features/thread_lock_stream' into features/vllm-streaming
p-ferreira Mar 21, 2024
6f7280f
improves stream encapsulation
p-ferreira Mar 21, 2024
915593a
blacks the repo
p-ferreira Mar 21, 2024
7764676
Merge branch 'features/thread_lock_stream' into features/vllm-streaming
p-ferreira Mar 21, 2024
4b63675
Merge pull request #159 from opentensor/features/vllm-streaming
p-ferreira Mar 21, 2024
7af0793
pipeline adjustments
p-ferreira Mar 21, 2024
856675c
precommit-hook-test
p-ferreira Mar 21, 2024
cfed494
black
mccrindlebrian Mar 21, 2024
c8c47bb
Merge pull request #171 from opentensor/hotfix/black
p-ferreira Mar 21, 2024
0e9d53f
drops debug from repo
p-ferreira Mar 21, 2024
0a2084b
Merge pull request #170 from opentensor/features/thread_lock_stream
p-ferreira Mar 21, 2024
10cd731
merge main into prestaing
mccrindlebrian Mar 27, 2024
1c3de3d
adapts forward test to streaming + bugfix on mock metagraph
p-ferreira Mar 28, 2024
5372f27
remove unneeded parsing in protocol
mccrindlebrian Mar 28, 2024
e103c2b
Remove <|im_start|> with other roles
bkb2135 Apr 2, 2024
b6499f6
Update all_cleaners.py
bkb2135 Apr 2, 2024
40ff2f7
Update all_cleaners.py
bkb2135 Apr 2, 2024
c5fb529
Update all_cleaners.py
bkb2135 Apr 2, 2024
8e84844
Update all_cleaners.py
bkb2135 Apr 2, 2024
123070e
Merge pull request #184 from opentensor/bkb2135-patch-1
mccrindlebrian Apr 2, 2024
6331f30
quick dirty fix on forward
p-ferreira Apr 2, 2024
7b3d082
Filter CS Math Questions
bkb2135 Apr 3, 2024
8233c45
first attempt on parallelizing stream calls
p-ferreira Apr 3, 2024
601b6b7
Merge pull request #186 from opentensor/hotfix/reduce-cs-hallucinations
mccrindlebrian Apr 3, 2024
411b932
change timing logs from dendrite process_time to be timeout
mccrindlebrian Apr 3, 2024
718daae
Merge pull request #187 from opentensor/fix-dendrite-timing
mccrindlebrian Apr 3, 2024
5f463aa
brians refactoring on dendrite
p-ferreira Apr 3, 2024
f826d2b
parallelize streaming with results wrapper
p-ferreira Apr 3, 2024
778620e
Merge branch 'pre-staging' into from-main
p-ferreira Apr 3, 2024
fa29bd4
updates versioning
p-ferreira Apr 3, 2024
f022a0a
adds safe failure clause on forward
p-ferreira Apr 3, 2024
9551663
adapts unit test + fix typo
p-ferreira Apr 4, 2024
65354fe
add doc strings and typing
mccrindlebrian Apr 4, 2024
18f7496
adds timeout on forward pass
p-ferreira Apr 4, 2024
195d011
runs black on validator code
p-ferreira Apr 4, 2024
ddade62
Merge branch 'staging' into pre-staging
p-ferreira Apr 4, 2024
55c0f2f
Merge branch 'pre-staging' into from-main
p-ferreira Apr 4, 2024
802eaad
replace readme for streaming, simplify
mccrindlebrian Apr 4, 2024
83ad35b
fix variable missing from merge
p-ferreira Apr 4, 2024
c5277ed
Merge pull request #190 from opentensor/features/improve-readme-for-s…
mccrindlebrian Apr 4, 2024
ec10276
Merge pull request #182 from opentensor/from-main
mccrindlebrian Apr 4, 2024
0da2f4b
Merge pull request #136 from opentensor/pre-staging
p-ferreira Apr 4, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
__pycache__/
*.py[cod]
*$py.class
.DS_Store
**/.DS_Store


# C extensions
*.so
Expand Down
182 changes: 38 additions & 144 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,110 +19,13 @@ This repository is the **official codebase for Bittensor Subnet 1 (SN1) v1.0.0+,

# Introduction

This repo defines an incentive mechanism to create a distributed conversational AI.
This repo defines an incentive mechanism to create a distributed conversational AI for Subnet 1 (SN1).

Validators and miners are based on large language models (LLM). The [validation process](#validation) uses **[internet-scale datasets](#tools)** and **[goal-driven](#tasks)** behaviour to drive **[human-like conversations](#agents)**.
Validators and miners are based on large language models (LLM). The validation process uses **internet-scale datasets and goal-driven behaviour to drive human-like conversations**.

</div>

# Compute Requirements

1. To run a **validator**, you will need at least 24GB of VRAM.
2. To run the default Zephyr **miner**, you will need at least 18GB of VRAM.

</div>

# Validation
The design of the network's incentive mechanism is based on two important requirements:

### 1. Validation should mimic human interactions

It is imperative that the validation process engages with miners in the same way as real users. The reasons for this are as follows:
- Miners will compete and continuously improve at performing the validation task(s), and so this fine tuning should be aligned with the goals of the subnet.
- It should not be possible to distinguish between validation and API client queries so that miners always serve requests (even when they do not receive emissions for doing so).

In the context of this subnet, miners are required to be intelligent AI assistants that provide helpful and correct responses to a range of queries.

### 2. Reward models should mimic human preferences

In our experience, we have found that it is tricky to evaluate whether miner responses are high quality. Existing methods typically rely on using LLMs to score completions given a prompt, but this is often exploited and gives rise to many adversarial strategies.

In the present version, the validator produces one or more **reference** answers which all miner responses are compared to. Those which are most similar to the reference answer will attain the highest rewards and ultimately gain the most incentive.

**We presently use a combination of string literal similarity and semantic similarity as the basis for rewarding.**

# Tools
Contexts, which are the basis of conversations, are from external APIs (which we call tools) which ensure that conversations remain grounded in factuality. Contexts are also used to obtain ground-truth answers.

Currently, the tooling stack includes:
1. Wikipedia API
2. StackOverflow
3. mathgenerator

More tooling will be included in future releases.

# Tasks
The validation process supports an ever-growing number of tasks. Tasks drive agent behaviour based on specific goals, such as;
- Question answering
- Summarization
- Code debugging
- Mathematics
and more.

Tasks contain a **query** (basic question/problem) and a **reference** (ideal answer), where a downstream HumanAgent creates a more nuanced version of the **query**.

# Agents

In order to mimic human interactions, validators participate in a roleplaying game where they take on the persona of **random** human users. Equipped with this persona and a task, validators prompt miners in a style and tone that is similar to humans and drive the conversation in order to reach a pre-defined goal. We refer to these prompts as **challenges**.

Challenges are based on the query by wrapping the query in an agent persona which results in a lossy "one-way" function. This results in challenges that are overall more interesting, and less predictable.

The [diagram below](#validation-diagram) illustrates the validation flow.

#### Our approach innovatively transforms straightforward queries into complex challenges, a process akin to a 'hash function', requiring advanced NLP for resolution. This transformation is crucial for preventing simple lookups in source documents, ensuring that responses necessitate authentic analytical effort.


# Validation Diagram
![sn1 overview](assets/sn1-overview.png)

# Running Validators
These validators are designed to run and update themselves automatically. To run a validator, follow these steps:

1. Install this repository, you can do so by following the steps outlined in [the installation section](#installation).
2. Install [Weights and Biases](https://docs.wandb.ai/quickstart) and run `wandb login` within this repository. This will initialize Weights and Biases, enabling you to view KPIs and Metrics on your validator. (Strongly recommended to help the network improve from data sharing)
3. Install [PM2](https://pm2.io/docs/runtime/guide/installation/) and the [`jq` package](https://jqlang.github.io/jq/) on your system.
**On Linux**:
```bash
sudo apt update && sudo apt install jq && sudo apt install npm && sudo npm install pm2 -g && pm2 update
```
**On Mac OS**
```bash
brew update && brew install jq && brew install npm && sudo npm install pm2 -g && pm2 update
```
4. Run the `run.sh` script which will handle running your validator and pulling the latest updates as they are issued.
```bash
pm2 start run.sh --name s1_validator_autoupdate -- --wallet.name <your-wallet-name> --wallet.hotkey <your-wallet-hot-key>
```

This will run **two** PM2 processes: one for the validator which is called `s1_validator_main_process` by default (you can change this in `run.sh`), and one for the run.sh script (in step 4, we named it `s1_validator_autoupdate`). The script will check for updates every 30 minutes, if there is an update then it will pull it, install it, restart `s1_validator_main_process` and then restart itself.


> Important: vLLM currently faces a [notable limitation](https://github.com/vllm-project/vllm/issues/3012) in designating a specific GPU for model execution via code. Consequently, to employ a particular CUDA device for your model's operations, it's necessary to manually adjust your environment variable `CUDA_VISIBLE_DEVICES`. For instance, setting `export CUDA_VISIBLE_DEVICES=1,2` will explicitly define the CUDA devices available for use.



# Available Miners

Miners are scored based on the similarity between their completions and the reference answer. Furthermore, they should utilize the same API tools as the validators in order to be able to closely reproduce the reference answer. We currently provide the following miners out-of-the-box:
1. [Zephyr 7B](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta)
2. [OpenAI](https://platform.openai.com/docs/introduction) (GPT variants)
3. wiki-agent ([GPT ReAct agent with langchain](https://python.langchain.com/docs/modules/agents/agent_types/react))


</div>

---

# Installation
This repository requires python3.8 or higher. To install it, simply clone this repository and run the [install.sh](./install.sh) script.
```bash
Expand All @@ -131,70 +34,61 @@ cd prompting
bash install.sh
```

Alternatively, if you are running on a clean Ubuntu machine, you can run `python scripts/setup_ubuntu_machine.sh` to effortlessly install everything you need. If you are wanting to run an OpenAI miner, you will need to place your OpenAI API key in the `OPENAI_API_KEY` variable in the script.

</div>

---
# Running

We encourage miners to use testnet as this gives you a risk-free playground before running on mainnet. If you require test tao, please reach out to [email protected]
# Compute Requirements

Prior to running a miner or validator, you must [create a wallet](https://github.com/opentensor/docs/blob/main/reference/btcli.md) and [register the wallet to a netuid](https://github.com/opentensor/docs/blob/main/subnetworks/registration.md). Once you have done so, you can run the miner and validator with the following commands.
1. To run a **validator**, you will need at least 24GB of VRAM.
2. To run the default huggingface **miner**, you will need at least 18GB of VRAM.

For miners and validators running on mainnet we **strongly encourage** you to use a [local subtensor](https://github.com/opentensor/subtensor).
</div>

# How to Run
You can use the following command to run a miner or a validator.

```bash
# To run the validator
python neurons/validator.py
python <SCRIPT_PATH>
--netuid 1
--subtensor.network <finney/local/test>
--neuron.device cuda
--wallet.name <your validator wallet> # Must be created using the bittensor-cli
--wallet.hotkey <your validator hotkey> # Must be created using the bittensor-cli
--logging.debug # Run in debug mode, alternatively --logging.trace for trace mode

```

```bash
# To run the miner
python neurons/miners/BASE_MINER/miner.py
--netuid 1
--subtensor.network <finney/local/test>
--wallet.name <your miner wallet> # Must be created using the bittensor-cli
--wallet.hotkey <your validator hotkey> # Must be created using the bittensor-cli
--wallet.name <your wallet> # Must be created using the bittensor-cli
--wallet.hotkey <your hotkey> # Must be created using the bittensor-cli
--logging.debug # Run in debug mode, alternatively --logging.trace for trace mode
--axon.port #VERY IMPORTANT: set the port to be one of the open TCP ports on your machine
```
where `BASE_MINER` is [zephyr](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta), which is a fine-tuned Mistral-7B, however you can choose any of the supplied models found in `neurons/miners`.

</div>
where `SCRIPT_PATH` is either:
1. neurons/miners/huggingface/miner.py
2. neurons/miners/openai/miner.py
3. neurons/validator.py

---
For ease of use, you can run the scripts as well with PM2. Installation of PM2 is:
**On Linux**:
```bash
sudo apt update && sudo apt install jq && sudo apt install npm && sudo npm install pm2 -g && pm2 update
```

Example of running a SOLAR miner:
```bash
pm2 start neurons/miners/huggingface/miner.py --interpreter python3 --name solar_miner -- --netuid 1 --subtensor.network finney --wallet.name my_wallet --wallet.hotkey m1 --neuron.model_id NousResearch/Nous-Hermes-2-SOLAR-10.7B --axon.port 21988 --logging.debug
```

# Testnet
We highly recommend that you run your miners on testnet before deploying on main. This is give you an opportunity to debug your systems, and ensure that you will not lose valuable immunity time. The SN1 testnet is **netuid 61**.

# Real-time monitoring with wandb integration
In order to run on testnet, you will need to go through the same hotkey registration proceure as on main, but using **testtao**. You will need to ask for some in the community discord if you do not have any.

Check out real-time public logging by looking at the project [here](https://wandb.ai/opentensor-dev/alpha-validators)
To run:

## License
This repository is licensed under the MIT License.
```text
# The MIT License (MIT)
# Copyright © 2024 Yuma Rao
```bash
pm2 start neurons/miners/huggingface/miner.py --interpreter python3 --name solar_miner -- --netuid 61 --subtensor.network test --wallet.name my_test_wallet --wallet.hotkey m1 --neuron.model_id NousResearch/Nous-Hermes-2-SOLAR-10.7B --axon.port 21988 --logging.debug
```

# 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:
# Limitations
> Important: vLLM currently faces a [notable limitation](https://github.com/vllm-project/vllm/issues/3012) in designating a specific GPU for model execution via code. Consequently, to employ a particular CUDA device for your model's operations, it's necessary to manually adjust your environment variable `CUDA_VISIBLE_DEVICES`. For instance, setting `export CUDA_VISIBLE_DEVICES=1,2` will explicitly define the CUDA devices available for use.

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.
# Resources
The archiecture and methodology of SN1 is complex, and as such we have created a comprehensive resource to outline our design. Furthermore, we have strict requirements for how miners should interact with the network. Below are the currently available resources for additional information:

# 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.
```
1. [SN1 architecture details](docs/SN1_validation.md)
2. [StreamMiner requirements](docs/stream_miner_template.md)
53 changes: 53 additions & 0 deletions docs/SN1_validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

# Validation
The design of the network's incentive mechanism is based on two important requirements:

### 1. Validation should mimic human interactions

It is imperative that the validation process engages with miners in the same way as real users. The reasons for this are as follows:
- Miners will compete and continuously improve at performing the validation task(s), and so this fine tuning should be aligned with the goals of the subnet.
- It should not be possible to distinguish between validation and API client queries so that miners always serve requests (even when they do not receive emissions for doing so).

In the context of this subnet, miners are required to be intelligent AI assistants that provide helpful and correct responses to a range of queries.

### 2. Reward models should mimic human preferences

In our experience, we have found that it is tricky to evaluate whether miner responses are high quality. Existing methods typically rely on using LLMs to score completions given a prompt, but this is often exploited and gives rise to many adversarial strategies.

In the present version, the validator produces one or more **reference** answers which all miner responses are compared to. Those which are most similar to the reference answer will attain the highest rewards and ultimately gain the most incentive.

**We presently use a combination of string literal similarity and semantic similarity as the basis for rewarding.**

# Tools
Contexts, which are the basis of conversations, are from external APIs (which we call tools) which ensure that conversations remain grounded in factuality. Contexts are also used to obtain ground-truth answers.

Currently, the tooling stack includes:
1. Wikipedia API
2. StackOverflow
3. mathgenerator

More tooling will be included in future releases.

# Tasks
The validation process supports an ever-growing number of tasks. Tasks drive agent behaviour based on specific goals, such as;
- Question answering
- Summarization
- Code debugging
- Mathematics
and more.

Tasks contain a **query** (basic question/problem) and a **reference** (ideal answer), where a downstream HumanAgent creates a more nuanced version of the **query**.

# Agents

In order to mimic human interactions, validators participate in a roleplaying game where they take on the persona of **random** human users. Equipped with this persona and a task, validators prompt miners in a style and tone that is similar to humans and drive the conversation in order to reach a pre-defined goal. We refer to these prompts as **challenges**.

Challenges are based on the query by wrapping the query in an agent persona which results in a lossy "one-way" function. This results in challenges that are overall more interesting, and less predictable.

The [diagram below](#validation-diagram) illustrates the validation flow.

#### Our approach innovatively transforms straightforward queries into complex challenges, a process akin to a 'hash function', requiring advanced NLP for resolution. This transformation is crucial for preventing simple lookups in source documents, ensuring that responses necessitate authentic analytical effort.


# Validation Diagram
![sn1 overview](../assets/sn1-overview.png)
Loading
Loading