Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organic Request Update #83

Merged
merged 5 commits into from
Oct 15, 2024
Merged
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
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
Loading