Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion logicnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import miner
from . import utils

__version__ = "1.4.1"
__version__ = "1.4.3"
version_split = __version__.split(".")
__spec_version__ = (
(1000 * int(version_split[0]))
Expand Down
10 changes: 8 additions & 2 deletions logicnet/validator/miner_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_miner_info(self):
query_axons,
synapse,
deserialize=False,
timeout=10,
timeout=60,
)
responses = {
uid: response.response_dict
Expand All @@ -100,7 +100,13 @@ def update_miners_identity(self):
miner_distribution = {}
for uid, info in valid_miners_info.items():
# info = self.all_uids_info[int(uid)] if int(uid) in self.all_uids_info else MinerInfo(**info)
info = MinerInfo(**info)
miner_state = self.all_uids_info.setdefault(
uid,
{"scores": [], "reward_logs": []},
)
miner_state.category = info.get("category", "")
miner_state.epoch_volume = info.get("epoch_volume") if info.get("epoch_volume") else 512
info = miner_state
rate_limit_per_validator: dict = get_rate_limit_per_validator(
metagraph=self.validator.metagraph,
epoch_volume=info.epoch_volume,
Expand Down
8 changes: 8 additions & 0 deletions logicnet/validator/rewarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def __call__(self, uids, responses: list[LogicSynapse], base_synapse: LogicSynap

total_uids = valid_uids + invalid_uids
rewards = valid_rewards + invalid_rewards

for invalid_uid in invalid_uids:
reward_logs.append({
"task_uid": task_uid,
"similarity": 0,
"correctness": 0,
"process_time": 0,
})
return total_uids, rewards, reward_logs

def _get_correctness(
Expand Down
4 changes: 2 additions & 2 deletions neurons/miner/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, config=None):
self.volume_per_validator = (
logicnet.utils.volume_setting.get_rate_limit_per_validator(
self.metagraph,
self.config.miner.total_volume,
self.config.miner.epoch_volume,
self.config.miner.min_stake,
)
)
Expand Down Expand Up @@ -128,7 +128,7 @@ async def priority(self, synapse: LogicSynapse) -> float:
miner.volume_per_validator = (
logicnet.utils.volume_setting.get_rate_limit_per_validator(
miner.metagraph,
miner.config.miner.total_volume,
miner.config.miner.epoch_volume,
miner.config.miner.min_stake,
)
)
Expand Down
2 changes: 1 addition & 1 deletion neurons/validator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.4.1"
__version__ = "1.4.3"
version_split = __version__.split(".")
__spec_version__ = (
(1000 * int(version_split[0]))
Expand Down
79 changes: 51 additions & 28 deletions neurons/validator/validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from dotenv import load_dotenv
load_dotenv()
import pickle
import time
import threading
import datetime
Expand Down Expand Up @@ -389,37 +390,59 @@ def update_scores_on_chain(self):
bt.logging.success(f"\033[1;32m✅ Updated scores: {self.scores}\033[0m")

def save_state(self):
"""Saves the state of the validator to a file."""

torch.save(
{
"step": self.step,
"all_uids_info": self.miner_manager.all_uids_info,
},
self.config.neuron.full_path + "/state.pt",
)

"""Saves the state of the validator to a file using pickle."""
state = {
"step": self.step,
"all_uids_info": self.miner_manager.all_uids_info,
}
try:
# Open the file in write-binary mode
with open(self.config.neuron.full_path + "/state.pkl", "wb") as f:
pickle.dump(state, f)
bt.logging.info("State successfully saved to state.pkl")
except Exception as e:
bt.logging.error(f"Failed to save state: {e}")
def load_state(self):
"""Loads the state of the validator from a file."""

# Load the state of the validator from file.
"""Loads state of validator from a file, with fallback to .pt if .pkl is not found."""
# TODO: After a transition period, remove support for the old .pt format.
try:
path = self.config.neuron.full_path + "/state.pt"
bt.logging.info(
"\033[1;32m🧠 Loading validator state from: " + path + "\033[0m"
)
state = torch.load(path, weights_only=True) # Set weights_only=True
self.step = state["step"]
all_uids_info = state["all_uids_info"]
for k, v in all_uids_info.items():
v = v.to_dict()
self.miner_manager.all_uids_info[k] = MinerInfo(**v)
bt.logging.info("\033[1;32m✅ Successfully loaded state\033[0m")
path_pt = self.config.neuron.full_path + "/state.pt"
path_pkl = self.config.neuron.full_path + "/state.pkl"

# Try to load the newer .pkl format first
try:
bt.logging.info(f"Loading validator state from: {path_pkl}")
with open(path_pkl, "rb") as f:
state = pickle.load(f)

# Restore state from pickle file
self.step = state["step"]
self.miner_manager.all_uids_info = state["all_uids_info"]
bt.logging.info("Successfully loaded state from .pkl file")
return # Exit after successful load from .pkl

except Exception as e:
bt.logging.warning(f"Failed to load from .pkl format: {e}")

# If .pkl loading fails, try to load from the old .pt file (PyTorch format)
try:
bt.logging.info(f"Loading validator state from: {path_pt}")
state = torch.load(path_pt)

# Restore state from .pt file
self.step = state["step"]
self.miner_manager.all_uids_info = state["all_uids_info"]
bt.logging.info("Successfully loaded state from .pt file")

except Exception as e:
bt.logging.error(f"Failed to load from .pt format: {e}")
self.step = 0 # Default fallback when both load attempts fail
bt.logging.error("Could not find previously saved state or error loading it.")

except Exception as e:
self.step = 0
bt.logging.info(
"\033[1;33m⚠️ Could not find previously saved state.\033[0m", e
)
self.step = 0 # Default fallback in case of an unknown error
bt.logging.error(f"Error loading state: {e}")


def store_miner_infomation(self):
miner_informations = self.miner_manager.to_dict()
Expand Down