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
7 changes: 3 additions & 4 deletions openvalidators/gating.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def add_args(cls, parser: argparse.ArgumentParser):
parser.add_argument(
"--gating.num_uids",
type=int,
default=1024,
help="Number of uids to gate on",
help="Number of uids to gate on. Default is pulled from subtensor directly",
)
parser.add_argument(
"--gating.learning_rate",
Expand Down Expand Up @@ -137,7 +136,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
self.config = config
self.num_uids = config.gating.num_uids
self.device = torch.device(self.config.neuron.device)
Expand Down Expand Up @@ -228,7 +227,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
5 changes: 4 additions & 1 deletion openvalidators/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def __init__(self):

# Init the gating model which learns which miners to select for each query.
bt.logging.debug("loading", "gating_model")
if not self.config.gating.num_uids:
self.config.gating.num_uids = self.subtensor.max_n(self.config.netuid)

if self.config.neuron.mock_gating_model:
self.gating_model = MockGatingModel(self.metagraph.n.item())
elif self.config.neuron.use_custom_gating_model:
Expand All @@ -116,7 +119,7 @@ def __init__(self):
self.gating_model = GatingModel(metagraph=self.metagraph, config=self.config).to(self.device)
bt.logging.debug(str(self.gating_model))

# Dendrite pool for querying the network during training.
# Dendrite pool for querying the network during training.
bt.logging.debug("loading", "dendrite_pool")
if self.config.neuron.mock_dendrite_pool:
self.dendrite_pool = MockDendritePool()
Expand Down
2 changes: 1 addition & 1 deletion openvalidators/reward/diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_rewards( self, prompt: str, completions: List[str], name: str ) -> torch

# Check if completions are empty, return 0 if so
if len(completions) == 0:
return torch.tensor([])
return torch.tensor([]).to(self.device)

# Get embeddings for all completions.
embeddings = self.get_embeddings( completions )
Expand Down
5 changes: 3 additions & 2 deletions openvalidators/reward/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self) -> None:
self.count = 0
self.mean = 0.0
self.var = 0.0
self.count_limit = 1000
self.count_limit = 3000

def normalize_rewards( self, rewards: torch.FloatTensor ) -> torch.FloatTensor:
"""
Expand All @@ -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