From 87b46b4a22753f2529d1b9cf886973b91f71edd7 Mon Sep 17 00:00:00 2001 From: pycorn0729 Date: Fri, 20 Dec 2024 04:49:35 +0900 Subject: [PATCH] chore: fix bugs for state --- neurons/validator.py | 3 --- template/base/validator.py | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/neurons/validator.py b/neurons/validator.py index 0c509b00..bbf86d02 100644 --- a/neurons/validator.py +++ b/neurons/validator.py @@ -42,9 +42,6 @@ class Validator(BaseValidatorNeuron): def __init__(self, config=None): super(Validator, self).__init__(config=config) - bt.logging.info("load_state()") - self.load_state() - # TODO(developer): Anything specific to your use case you can do here async def forward(self): diff --git a/template/base/validator.py b/template/base/validator.py index 9f6f22ab..d3536afa 100644 --- a/template/base/validator.py +++ b/template/base/validator.py @@ -66,6 +66,9 @@ def __init__(self, config=None): bt.logging.info("Building validation weights.") self.scores = np.zeros(self.metagraph.n, dtype=np.float32) + # Load the state of the validator from file. + self.load_state() + # Init sync with the network. Updates the metagraph. self.sync() @@ -382,6 +385,13 @@ def load_state(self): # Load the state of the validator from file. state = np.load(self.config.neuron.full_path + "/state.npz") - self.step = state["step"] - self.scores = state["scores"] - self.hotkeys = state["hotkeys"] + if "step" in state: + self.step = state["step"] + self.scores = state["scores"] + self.hotkeys = state["hotkeys"] + else: + # Set up initial scoring weights for validation + bt.logging.info("Building validation weights.") + self.step = 0 + self.scores = np.zeros(self.metagraph.n, dtype=np.float32) + self.hotkeys = copy.deepcopy(self.metagraph.hotkeys)