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

Fix miner sync issue and validator non_zero_weights edge case #103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 4 additions & 14 deletions template/base/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion template/base/utils/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down