Skip to content

Commit

Permalink
Config refactoring (#40)
Browse files Browse the repository at this point in the history
* Refactor omron entrypoint and configuration

* More args-config refactoring

* Rename config to cli_parser. Still ugly, but as for me a bit better

* 'Dry run' entry point and downloading model files chunk-by-chunk

* 'full_path' and 'full_path_role' improvements

* New default folder for external files

* --certificate-path fix for validator

* Do not mess with EZKL!

* Minor updates and cleanup

- localnet test port 9946 -> 9944 to match upstream
- update dependencies
- refactor circuit.py to use cli_parser instead of env var
- stop auto update from checking if repo is initialized if auto update is disabled
- cleanup devcontainer

---------

Co-authored-by: Hudson Graeme <[email protected]>
Co-authored-by: Eric <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 4ccccce commit d214a56
Show file tree
Hide file tree
Showing 20 changed files with 726 additions and 550 deletions.
26 changes: 17 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Built from https://github.com/inference-labs-inc/tensor-tools/blob/main/bittensor-devcontainer/Dockerfile
"image": "ghcr.io/inference-labs-inc/bittensor-devcontainer:latest",
// "build": {
// // Path is relative to the devcontainer.json file.
// "context": "..",
// "dockerfile": "Dockerfile"
// },
// // Path is relative to the devcontainer.json file.
// "context": "..",
// "dockerfile": "Dockerfile"
// },
// "runArgs": ["--platform=linux/amd64"],

// Features to add to the dev container. More info: https://containers.dev/features.
Expand All @@ -24,17 +24,25 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// "postCreateCommand": [
// "uv sync --locked",
// "source .venv/bin/activate.fish"
// ],

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/home/vscode/.venv/bin/python"
}
"terminal.integrated.defaultProfile.linux": "fish"
// "python.defaultInterpreterPath": "/home/vscode/.venv/bin/python"
},
"extensions": [
"ms-python.black-formatter",
"ms-python.python"
]
}
},
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ensure_newline_before_comments=True
line_length=88
split_on_trailing_comma=True
known_third_party=fastapi,bittensor
known_first_party=_validator,_miner,constants,utils,execution_layer,deployment_layer,miner,validator,protocol,models,constants
known_first_party=_validator,_miner,constants,utils,execution_layer,deployment_layer,miner,validator,protocol,models,constants,cli_parser
4 changes: 2 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Running miner locally for development:
```sh
python miner.py \
--netuid 1 \
--subtensor.chain_endpoint ws://127.0.0.1:9946 \
--subtensor.chain_endpoint ws://127.0.0.1:9944 \
--wallet.name miner \
--wallet.hotkey default \
--subtensor.network local \
Expand All @@ -67,7 +67,7 @@ Running validator locally for development:
```sh
python validator.py \
--netuid 1 \
--subtensor.chain_endpoint ws://127.0.0.1:9946 \
--subtensor.chain_endpoint ws://127.0.0.1:9944 \
--wallet.name validator \
--wallet.hotkey default \
--subtensor.network local \
Expand Down
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
"bittensor",
"blocktime",
"btcli",
"btlogging",
"CIRCOM",
"circuitized",
"coldkey",
"dtype",
"ezkl",
"fastapi",
"Gbps",
"hexsha",
"incentivizes",
"Keypair",
"libudev",
"localnet",
"logrows",
"Mbps",
"metagraph",
"netuid",
Expand Down
22 changes: 11 additions & 11 deletions docs/running_on_staging.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ Run the following command to mint yourself tokens on your chain.

```bash
# Mint tokens for the owner
btcli wallet faucet --wallet.name owner --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli wallet faucet --wallet.name owner --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Balance: τ0.000000000 ➡ τ100.000000000
# Mint tokens to your validator.
btcli wallet faucet --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli wallet faucet --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Balance: τ0.000000000 ➡ τ100.000000000
```

Expand All @@ -118,7 +118,7 @@ btcli wallet faucet --wallet.name validator --subtensor.chain_endpoint ws://127.
The commands below establish a new subnetwork on the local chain. The cost will be exactly τ100.000000000 for the first network you create.

```bash
btcli subnet create --wallet.name owner --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli subnet create --wallet.name owner --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Your balance is: τ200.000000000
>> Do you want to register a subnet for τ100.000000000? [y/n]:
>> Enter password to unlock key: [YOUR_PASSWORD]
Expand All @@ -133,15 +133,15 @@ Enroll your validator and miner on the network. This gives your two keys unique

```bash
# Register the miner
btcli subnet register --wallet.name miner --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli subnet register --wallet.name miner --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Enter netuid [1] (1): 1
>> Continue Registration? [y/n]: y
>> ⠦ 📡 Submitting POW...
>> ✅ Registered


# Register the validator
btcli subnet register --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli subnet register --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Enter netuid [1] (1): 1
>> Continue Registration? [y/n]: y
>> ⠦ 📡 Submitting POW...
Expand All @@ -153,7 +153,7 @@ btcli subnet register --wallet.name validator --wallet.hotkey default --subtenso
This bootstraps the incentives on your new subnet by adding stake into its incentive mechanism.

```bash
btcli stake add --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli stake add --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944
>> Stake all Tao from account: 'validator'? [y/n]: y
>> Stake:
τ0.000000000 ➡ τ100.000000000
Expand All @@ -164,20 +164,20 @@ btcli stake add --wallet.name validator --wallet.hotkey default --subtensor.chai
Ensure both the miner and validator keys are successfully registered.

```bash
btcli subnet list --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli subnet list --subtensor.chain_endpoint ws://127.0.0.1:9944
Subnets - finney
NETUID NEURONS MAX_N DIFFICULTY TEMPO CON_REQ EMISSION BURN(τ)
1 2 256.00 10.00 M 1000 None 0.00% τ1.00000
2 128

btcli wallet overview --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli wallet overview --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9944
Subnet: 1
COLDKEY HOTKEY UID ACTIVE STAKE(τ) RANK TRUST CONSENSUS INCENTIVE DIVIDENDS EMISSION(ρ) VTRUST VPERMIT UPDATED AXON HOTKEY_SS58
miner default 0 True 100.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0 0.00000 14 none 5GTFrsEQfvTsh3WjiEVFeKzFTc2xcf…
1 1 2 τ100.00000 0.00000 0.00000 0.00000 0.00000 0.00000 ρ0 0.00000
Wallet balance: τ0.0

btcli wallet overview --wallet.name miner --subtensor.chain_endpoint ws://127.0.0.1:9946
btcli wallet overview --wallet.name miner --subtensor.chain_endpoint ws://127.0.0.1:9944
Subnet: 1
COLDKEY HOTKEY UID ACTIVE STAKE(τ) RANK TRUST CONSENSUS INCENTIVE DIVIDENDS EMISSION(ρ) VTRUST VPERMIT UPDATED AXON HOTKEY_SS58
miner default 1 True 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0 0.00000 14 none 5GTFrsEQfvTsh3WjiEVFeKzFTc2xcf…
Expand All @@ -191,8 +191,8 @@ miner default 1 True 0.00000 0.00000 0.00000 0.00000 0.00000
Use the following commands to run the miner and validator against the local chain.

```bash
pm2 start neurons/miner.py --interpreter python3 --name miner -- --netuid 1 --subtensor.chain_endpoint ws://127.0.0.1:9946 --wallet.name miner --wallet.hotkey default
pm2 start neurons/validator.py --interpreter python3 --name validator -- --netuid 1 --subtensor.chain_endpoint ws://127.0.0.1:9946 --wallet.name validator --wallet.hotkey default
pm2 start neurons/miner.py --interpreter python3 --name miner -- --netuid 1 --subtensor.chain_endpoint ws://127.0.0.1:9944 --wallet.name miner --wallet.hotkey default
pm2 start neurons/validator.py --interpreter python3 --name validator -- --netuid 1 --subtensor.chain_endpoint ws://127.0.0.1:9944 --wallet.name validator --wallet.hotkey default
```

[View all acceptable CLI arguments →]
Expand Down
47 changes: 24 additions & 23 deletions neurons/_miner/miner_session.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
# from __future__ import annotations
import json
import time
import traceback
import json
from typing import Tuple, Union

import bittensor as bt
import websocket

import cli_parser
from _validator.models.request_type import RequestType
from constants import (
SINGLE_PROOF_OF_WEIGHTS_MODEL_ID,
STEAK,
VALIDATOR_REQUEST_TIMEOUT_SECONDS,
VALIDATOR_STAKE_THRESHOLD,
)

from protocol import QueryForProofAggregation, QueryZkProof, ProofOfWeightsSynapse
from utils import wandb_logger
import websocket
from execution_layer.verified_model_session import VerifiedModelSession
from deployment_layer.circuit_store import circuit_store
from utils import AutoUpdate, clean_temp_files
from execution_layer.generic_input import GenericInput
from _validator.models.request_type import RequestType
from execution_layer.verified_model_session import VerifiedModelSession
from protocol import ProofOfWeightsSynapse, QueryForProofAggregation, QueryZkProof
from utils import AutoUpdate, clean_temp_files, wandb_logger


class MinerSession:

axon: Union[bt.axon, None] = None

def __init__(self, config):
self.config = config
def __init__(self):
self.configure()
self.check_register(should_exit=True)
self.auto_update = AutoUpdate()
self.log_batch = []
if self.config.disable_blacklist:
if cli_parser.config.disable_blacklist:
bt.logging.warning(
"Blacklist disabled, allowing all requests. Consider enabling to filter requests."
)
Expand All @@ -42,10 +41,10 @@ def start_axon(self):
bt.logging.info(
"Starting axon. Custom arguments include the following.\n"
"Note that any null values will fallback to defaults, "
f"which are usually sufficient. {self.config.axon}"
f"which are usually sufficient. {cli_parser.config.axon}"
)

axon = bt.axon(wallet=self.wallet, config=self.config)
axon = bt.axon(wallet=self.wallet, config=cli_parser.config)
bt.logging.info(f"Axon created: {axon.info()}")

# Attach determines which functions are called when a request is received.
Expand All @@ -60,11 +59,11 @@ def start_axon(self):
# Serve passes the axon information to the network + netuid we are hosting on.
# This will auto-update if the axon port of external ip has changed.
bt.logging.info(
f"Serving axon on network: {self.subtensor.chain_endpoint} with netuid: {self.config.netuid}"
f"Serving axon on network: {self.subtensor.chain_endpoint} with netuid: {cli_parser.config.netuid}"
)
axon.serve(netuid=self.config.netuid, subtensor=self.subtensor)
axon.serve(netuid=cli_parser.config.netuid, subtensor=self.subtensor)
bt.logging.info(
f"Served axon on network: {self.subtensor.chain_endpoint} with netuid: {self.config.netuid}"
f"Served axon on network: {self.subtensor.chain_endpoint} with netuid: {cli_parser.config.netuid}"
)

# Start the miner's axon, making it active on the network.
Expand All @@ -88,7 +87,7 @@ def run(self):
step += 1
try:
if step % 10 == 0:
if not self.config.no_auto_update:
if not cli_parser.config.no_auto_update:
self.auto_update.try_update()
else:
bt.logging.info(
Expand All @@ -111,7 +110,9 @@ def run(self):

if step % 24 == 0 and self.subnet_uid is not None:
try:
self.metagraph = self.subtensor.metagraph(self.config.netuid)
self.metagraph = self.subtensor.metagraph(
cli_parser.config.netuid
)
bt.logging.info(
f"Step:{step} | "
f"Block:{self.metagraph.block.item()} | "
Expand Down Expand Up @@ -156,10 +157,10 @@ def check_register(self, should_exit=False):

def configure(self):
# === Configure Bittensor objects ====
self.wallet = bt.wallet(config=self.config)
self.subtensor = bt.subtensor(config=self.config)
self.metagraph = self.subtensor.metagraph(self.config.netuid)
wandb_logger.safe_init("Miner", self.wallet, self.metagraph, self.config)
self.wallet = bt.wallet(config=cli_parser.config)
self.subtensor = bt.subtensor(config=cli_parser.config)
self.metagraph = self.subtensor.metagraph(cli_parser.config.netuid)
wandb_logger.safe_init("Miner", self.wallet, self.metagraph, cli_parser.config)

def proof_blacklist(self, synapse: QueryZkProof) -> Tuple[bool, str]:
"""
Expand Down Expand Up @@ -197,7 +198,7 @@ def _blacklist(
returns: (is_blacklisted, reason)
"""
try:
if self.config.disable_blacklist:
if cli_parser.config.disable_blacklist:
bt.logging.trace("Blacklist disabled, allowing request.")
return False, "Allowed"

Expand Down
2 changes: 1 addition & 1 deletion neurons/_validator/core/validator_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, config: ValidatorConfig):
self.config.check_register()
self.auto_update = AutoUpdate()
self.score_manager = ScoreManager(
self.config.metagraph, self.config.user_uid, self.config.full_path
self.config.metagraph, self.config.user_uid, self.config.full_path_score
)
self.response_processor = ResponseProcessor(
self.config.metagraph,
Expand Down
9 changes: 6 additions & 3 deletions neurons/_validator/validator_session.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from __future__ import annotations

import sys

import bittensor as bt

import cli_parser
from _validator.config import ValidatorConfig
from _validator.core.validator_loop import ValidatorLoop
from utils import clean_temp_files
import sys


class ValidatorSession:
def __init__(self, config: bt.config):
self.config = ValidatorConfig(config)
def __init__(self):
self.config = ValidatorConfig(cli_parser.config)
self.validator_loop = ValidatorLoop(self.config)

def run(self):
Expand Down
Loading

0 comments on commit d214a56

Please sign in to comment.