From 4197e8d5383b3f131728c6fec07ad5b6dcf8a18b Mon Sep 17 00:00:00 2001 From: v0nerd Date: Tue, 9 Jul 2024 16:18:22 -0400 Subject: [PATCH 1/2] fix: miner calls sync at every epoch length --- template/base/miner.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/template/base/miner.py b/template/base/miner.py index 1788e24bd..4bbcc3949 100644 --- a/template/base/miner.py +++ b/template/base/miner.py @@ -111,20 +111,10 @@ def run(self): # This loop maintains the miner's operations until intentionally stopped. try: while not self.should_exit: - while ( - self.block - self.metagraph.last_update[self.uid] - < self.config.neuron.epoch_length - ): - # Wait before checking again. - time.sleep(1) - - # Check if we should exit. - if self.should_exit: - break - - # Sync metagraph and potentially set weights. - self.sync() - self.step += 1 + bt.logging.debug(f"block: {self.block}") + if self.block % self.config.neuron.epoch_length == 0: + self.sync() + time.sleep(12) # If someone intentionally stops the miner, it'll safely terminate operations. except KeyboardInterrupt: From 45f536866ccba95d15053cdfb6f028119cdadcf3 Mon Sep 17 00:00:00 2001 From: v0nerd Date: Tue, 9 Jul 2024 16:19:19 -0400 Subject: [PATCH 2/2] fix: validator non_zero_weights nparray instance check --- template/base/utils/weight_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/template/base/utils/weight_utils.py b/template/base/utils/weight_utils.py index 26133efde..f31eac4eb 100644 --- a/template/base/utils/weight_utils.py +++ b/template/base/utils/weight_utils.py @@ -159,6 +159,11 @@ def process_weights_for_netuid( non_zero_weight_idx = np.argwhere(weights > 0).squeeze() non_zero_weight_uids = uids[non_zero_weight_idx] non_zero_weights = weights[non_zero_weight_idx] + + # Ensure non_zero_weights is a NumPy array + if not isinstance(non_zero_weights, np.ndarray): + non_zero_weights = np.array(non_zero_weights) + if non_zero_weights.size == 0 or metagraph.n < min_allowed_weights: bittensor.logging.warning("No non-zero weights returning all ones.") final_weights = np.ones(metagraph.n) / metagraph.n @@ -167,7 +172,7 @@ def process_weights_for_netuid( elif non_zero_weights.size < min_allowed_weights: bittensor.logging.warning( - "No non-zero weights less then min allowed weight, returning all ones." + "No non-zero weights less than min allowed weight, returning all ones." ) weights = ( np.ones(metagraph.n) * 1e-5