Skip to content

Commit

Permalink
Organic Request Update (#83)
Browse files Browse the repository at this point in the history
* timeout -> 10

* slightly lowering timeout

* preprocess images in validator proxy

* typo
  • Loading branch information
dylanuys authored Oct 15, 2024
1 parent 1e633a1 commit 24b4769
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions neurons/validator_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from starlette.concurrency import run_in_threadpool
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from cryptography.exceptions import InvalidSignature
from PIL import Image
from io import BytesIO
import bittensor as bt
import pandas as pd
import numpy as np
Expand All @@ -16,13 +18,22 @@
import httpx
import threading
import socket
import base64

from bitmind.protocol import ImageSynapse
from bitmind.image_transforms import base_transforms
from bitmind.protocol import ImageSynapse, prepare_image_synapse
from bitmind.utils.uids import get_random_uids
from bitmind.validator.proxy import ProxyCounter
import bitmind


def preprocess_image(b64_image):
image_bytes = base64.b64decode(b64_image)
image_buffer = BytesIO(image_bytes)
pil_image = Image.open(image_buffer)
return base_transforms(pil_image)


class ValidatorProxy:
def __init__(
self,
Expand Down Expand Up @@ -131,10 +142,12 @@ async def forward(self, request: Request):
bt.logging.warning("[ORGANIC] No recent miner uids found, sampling random uids")
miner_uids = get_random_uids(self.validator, k=self.validator.config.neuron.sample_size)

image = preprocess_image(payload['image'])

bt.logging.info(f"[ORGANIC] Querying {len(miner_uids)} miners...")
predictions = await self.dendrite(
axons=[metagraph.axons[uid] for uid in miner_uids],
synapse=ImageSynapse(image=payload['image'], prediction=-1),
synapse=prepare_image_synapse(image=image),
deserialize=True,
timeout=9
)
Expand Down

0 comments on commit 24b4769

Please sign in to comment.