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

Handle failures to load uids to eval state gracefully. #93

Merged
3 commits merged into from
Apr 1, 2024
Merged
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
26 changes: 15 additions & 11 deletions neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,22 @@ def __init__(self):
# Initialize the UIDs to eval.
if not os.path.exists(self.uids_filepath):
bt.logging.warning("No uids state file found. Starting from scratch.")
hotkeys = (
self.model_tracker.get_miner_hotkey_to_model_metadata_dict().keys()
)
uids = []
for hotkey in hotkeys:
if hotkey in self.metagraph.hotkeys:
uids.append(self.metagraph.hotkeys.index(hotkey))
self.uids_to_eval = set(uids)
else:
with open(self.uids_filepath, "rb") as f:
self.uids_to_eval = pickle.load(f)
self.pending_uids_to_eval = pickle.load(f)
try:
with open(self.uids_filepath, "rb") as f:
self.uids_to_eval = pickle.load(f)
self.pending_uids_to_eval = pickle.load(f)
except Exception as e:
bt.logging.warning(
f"Failed to load uids to eval state. Reason: {e}. Starting from scratch."
)
# We also need to wipe the tracker state in this case to ensure we re-evaluate all the models.
self.model_tracker = ModelTracker()
if os.path.exists(self.tracker_filepath):
bt.logging.warning(
f"Because the uids to eval state failed to load, deleting tracker state at {self.tracker_filepath} so everything is re-evaluated."
)
os.remove(self.tracker_filepath)

# Setup a miner iterator to ensure we update all miners.
# This subnet does not differentiate between miner and validators so this is passed all uids.
Expand Down