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

Features/limit repeated queries #93

Merged
merged 20 commits into from
Feb 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change random.choices to np.random.choice to ensure that UIDs are unique
  • Loading branch information
steffencruz committed Feb 7, 2024
commit 2279438b743e0df77c72e5a6d0ea451fc12f6bea
6 changes: 3 additions & 3 deletions prompting/utils/uids.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
import random
import numpy as np
import bittensor as bt
from typing import List

Expand All @@ -21,7 +21,7 @@ def get_random_uids(
coldkeys = {}
ips = {}
# shuffled list of all UIDs
all_uids = random.choices(self.metagraph.uids.tolist(), k=self.metagraph.n.item())
all_uids = np.random.choice(range(self.metagraph.n.item()), size=self.metagraph.n.item(), replace=False)
all_coldkeys = self.metagraph.coldkeys
all_ips = [axon.ip for axon in self.metagraph.axons]
for uid in all_uids:
Expand Down Expand Up @@ -55,7 +55,7 @@ def get_random_uids(
ip_threshold = (1-self.config.neuron.unique_ip_prob) ** ip_counts

# Take the product of the two probabilities as the likelihood of querying the same coldkey and ip again
if random.random() > ck_threshold * ip_threshold:
if np.random.random() > ck_threshold * ip_threshold:
continue

coldkeys[coldkey] = coldkeys.get(coldkey, 0 ) + 1
Expand Down