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

Config refactoring #40

Open
wants to merge 10 commits into
base: testnet
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
"bittensor",
"blocktime",
"btcli",
"btlogging",
"CIRCOM",
"circuitized",
"coldkey",
"dtype",
"ezkl",
"fastapi",
"Gbps",
"incentivizes",
"Keypair",
"libudev",
"localnet",
"logrows",
"Mbps",
"metagraph",
"netuid",
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