Skip to content

Commit

Permalink
refactor: try to make mturk task non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvis8x7b committed Feb 25, 2024
1 parent 5eb8f71 commit cbde40b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from datetime import datetime
import threading
import time
import functools
from typing import Dict, Tuple
from concurrent.futures import ThreadPoolExecutor

import bittensor as bt
from commons.llm.openai_proxy import Provider
Expand Down Expand Up @@ -42,6 +44,7 @@ def __init__(self):
self.thread: threading.Thread = None
self.lock = asyncio.Lock()
self.hotkey_to_request: Dict[str, RankingRequest] = {}
self.executor = ThreadPoolExecutor(max_workers=4)

async def forward_result(self, synapse: RankingResult) -> RankingResult:
bt.logging.info("Received consensus from validators")
Expand Down Expand Up @@ -98,12 +101,15 @@ async def forward_ranking_request(self, synapse: RankingRequest) -> RankingReque
)

elif scoring_method.casefold() == ScoringMethod.AWS_MTURK:
# send off to MTurk workers... will timeout on validator side
create_mturk_status = MTurkUtils.create_mturk_task(
# send off to MTurk workers in a non-blocking way
loop = asyncio.get_event_loop()
task = functools.partial(
MTurkUtils.create_mturk_task,
prompt=synapse.prompt,
completions=synapse.completions,
reward_in_dollars=0.01,
)
await loop.run_in_executor(self.executor, task)
else:
bt.logging.error("Unrecognized scoring method!")

Expand Down

0 comments on commit cbde40b

Please sign in to comment.