-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdendrite.py
32 lines (26 loc) · 881 Bytes
/
dendrite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import bittensor as bt
from protocol import TextToImage
from typing import List
import asyncio
import torchvision.transforms as transforms
class AsyncDendritePool:
def __init__(self, wallet, metagraph):
self.metagraph = metagraph
self.dendrite = bt.dendrite(wallet=wallet)
async def async_forward(
self,
uids: List[int],
query: TextToImage,
timeout: float = 12.0
):
def call_single_uid(uid):
query_copy = query.copy()
return self.dendrite(
self.metagraph.axons[uid],
synapse=query_copy,
timeout=timeout
)
async def query_async():
corutines = [call_single_uid(uid) for uid in uids]
return await asyncio.gather(*corutines)
return await query_async()