Skip to content
Merged
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
15 changes: 12 additions & 3 deletions openvalidators/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ def get_random_uids(self, k: int, exclude: List[int] = None) -> torch.LongTensor
If `k` is larger than the number of available `uids`, set `k` to the number of available `uids`.
"""
candidate_uids = []
avail_uids = []

for uid in range(self.metagraph.n.item()):
uid_is_available = check_uid_availability(self.metagraph, uid, self.config.neuron.vpermit_tao_limit)
uid_is_not_excluded = exclude is None or uid not in exclude

if uid_is_available and uid_is_not_excluded:
candidate_uids.append(uid)
if uid_is_available:
avail_uids.append(uid)
if uid_is_not_excluded:
candidate_uids.append(uid)

# Check if candidate_uids contain enough for querying, if not grab all avaliable uids
if len(candidate_uids) > k:
available_uids = torch.tensor(candidate_uids, dtype=torch.int64).to(self.device)
else:
available_uids = torch.tensor(avail_uids, dtype=torch.int64).to(self.device)


available_uids = torch.tensor(candidate_uids, dtype=torch.int64).to(self.device)
uids = torch.tensor(random.sample(available_uids.tolist(), k), dtype=torch.int64)
return uids

Expand Down
4 changes: 2 additions & 2 deletions openvalidators/gating.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(
config = GatingModel.config()
if model_name is not None:
config.gating.model_name = model_name
config.gating.num_uids = num_uids if num_uids is not None else metagraph.n
config.gating.num_uids = num_uids if num_uids is not None else config.gating.num_uids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would we handle it when the gating.num_uids is < or > metagraph.n ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we should set the gating.num_uids to be greater than metagraph.n. That way the gating model will have enough embeddings in its linear layer for any increases in uids

self.config = config
self.num_uids = config.gating.num_uids
self.device = torch.device(self.config.neuron.device)
Expand Down Expand Up @@ -228,7 +228,7 @@ def __init__(
config = SentenceEmbedGatingModel.config()
if model_name is not None:
config.gating.model_name = model_name
config.gating.num_uids = num_uids if num_uids is not None else metagraph.n
config.gating.num_uids = num_uids if num_uids is not None else config.gating.num_uids
self.config = config
self.num_uids = config.gating.num_uids
self.device = torch.device(self.config.neuron.device)
Expand Down
3 changes: 2 additions & 1 deletion openvalidators/reward/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def normalize_rewards( self, rewards: torch.FloatTensor ) -> torch.FloatTensor:
- This function uses Welford's online algorithm to update the mean and variance.
- It standardizes the reward values using the updated mean and variance.
- It then scales the standardized values to the 0-1 range using the error function (erf) as a CDF.
"""
"""
# Get the number of rewards (successful responses).
new_count = rewards.numel()

Expand Down Expand Up @@ -88,6 +88,7 @@ def apply( self, prompt: str, responses: List[ bt.DendriteCall ], name: str) ->
""" Applies the reward model across each call. Unsuccessful responses are zeroed.
"""
# Get indices of correctly responding calls.

successful_completions_indices: List[int] = [ idx for idx, resp in enumerate(responses) if resp.is_success ]

# Get all completions from responding calls.
Expand Down