Skip to content

Commit

Permalink
remove miner's limit of request/min and instead use bandwidth of each…
Browse files Browse the repository at this point in the history
… miner
  • Loading branch information
acer-king committed Sep 25, 2024
1 parent df699ba commit f14998c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 174 deletions.
22 changes: 0 additions & 22 deletions miner/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,6 @@ def base_blacklist(self, synapse) -> Tuple[bool, str]:
if stake < self.blacklist_amt:
return True, f"Blacklisted a low stake {synapse_type} request: {stake} < {self.blacklist_amt} from {hotkey}"

time_window = cortext.MIN_REQUEST_PERIOD * 60
current_time = time.time()

if hotkey not in BaseService.request_timestamps:
BaseService.request_timestamps[hotkey] = deque()

# Remove timestamps outside the current time window
while (BaseService.request_timestamps[hotkey] and
current_time - BaseService.request_timestamps[hotkey][0] > time_window):
BaseService.request_timestamps[hotkey].popleft()

# Check if the number of requests exceeds the limit
if len(BaseService.request_timestamps[hotkey]) >= cortext.MAX_REQUESTS:
return (
True,
f"Request frequency for {hotkey} exceeded: "
f"{len(BaseService.request_timestamps[hotkey])} requests in {cortext.MIN_REQUEST_PERIOD} minutes. "
f"Limit is {cortext.MAX_REQUESTS} requests."
)

BaseService.request_timestamps[hotkey].append(current_time)

return False, f"accepting {synapse_type} request from {hotkey}"

except Exception:
Expand Down
144 changes: 0 additions & 144 deletions validators/dendrite.py

This file was deleted.

2 changes: 1 addition & 1 deletion validators/services/validators/base_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_uid_to_scores_dict(self, uid_to_query_resps, scored_responses: tuple[flo
if model_weight is None:
bt.logging.debug(f"not weight found for this provider {provider} and model {model}")
model_weight = 0
band_width = uid_to_capacity.get(uid).bandwidth_rpm.get(f"{provider}").get(f"{model}")
band_width = uid_to_capacity.get(uid).get(f"{provider}").get(f"{model}")
if band_width is None:
bt.logging.debug(f"no band_width found for this uid {uid}")
band_width = 1
Expand Down
13 changes: 6 additions & 7 deletions validators/weight_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from cortext.protocol import IsAlive, StreamPrompting, ImageResponse, Embeddings
from cortext.metaclasses import ValidatorRegistryMeta
from cortext import MIN_REQUEST_PERIOD
from validators.services import CapacityService, BaseValidator, TextValidator, ImageValidator
from validators.services.cache import QueryResponseCache
from validators.utils import handle_response, error_handler, get_stream_result_as_async_gen, get_stream_result
Expand Down Expand Up @@ -142,7 +141,7 @@ async def update_and_refresh(self, last_update):
async def perform_synthetic_queries(self):
while True:
# wait for MIN_REQUEST_PERIOD minutes.
await asyncio.sleep(MIN_REQUEST_PERIOD * 60)
await asyncio.sleep(cortext.MIN_REQUEST_PERIOD * 60)
bt.logging.info(f"start processing synthetic queries {time.time()}")
start_time = time.time()
# check available bandwidth and send synthetic requests to all miners.
Expand Down Expand Up @@ -192,12 +191,12 @@ async def perform_synthetic_queries(self):

def choose_validator_from_model(self, model):
text_validator = ValidatorRegistryMeta.get_class('TextValidator')(config=self.config, metagraph=self.metagraph)
image_validator = ValidatorRegistryMeta.get_class('ImageValidator')(config=self.config,
metagraph=self.metagraph)
# image_validator = ValidatorRegistryMeta.get_class('ImageValidator')(config=self.config,
# metagraph=self.metagraph)
if model != 'dall-e-3':
return text_validator
else:
return image_validator
# else:
# return image_validator

def should_i_score(self):
# Randomly decide whether to score this query based on scoring_percent
Expand All @@ -211,7 +210,7 @@ async def perform_queries(self, selected_validator, uids_to_query):
uids_to_query_expand = []
for provider, model in provider_to_models:
for uid in uids_to_query:
band_width = self.uid_to_capacity.get(uid).bandwidth_rpm.get(f"{provider}").get(f"{model}")
band_width = self.uid_to_capacity.get(uid).get(f"{provider}").get(f"{model}")
for _ in range(band_width):
query_task = selected_validator.create_query(uid, provider, model)
query_tasks.append(query_task)
Expand Down

0 comments on commit f14998c

Please sign in to comment.