Skip to content

Commit

Permalink
Logging Updates (#61)
Browse files Browse the repository at this point in the history
* Update Mining.md

* logging augmented b64 images

* removing deprecated get_metagraph endpoint from validator_proxy

* removing metagraph fastapi endpoint

* Moving tensor to PIL conversion to b64_encode

* __init__.py

* not logging b64 encoded images

* shebang
  • Loading branch information
dylanuys authored Sep 11, 2024
1 parent 98c3af4 commit cd8951c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 29 deletions.
Empty file added bitmind/miner/__init__.py
Empty file.
13 changes: 7 additions & 6 deletions bitmind/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
import base64
import torch

def b64_encode(image):
if isinstance(image, torch.Tensor):
image = transforms.ToPILImage()(image.cpu().detach())
image_bytes = BytesIO()
image.save(image_bytes, format="JPEG")
return base64.b64encode(image_bytes.getvalue())

def prepare_image_synapse(image: Image):
"""
Expand All @@ -37,12 +43,7 @@ def prepare_image_synapse(image: Image):
Returns:
ImageSynapse: An instance of ImageSynapse containing the encoded image and a default prediction value.
"""
if isinstance(image, torch.Tensor):
image = transforms.ToPILImage()(image.cpu().detach())

image_bytes = BytesIO()
image.save(image_bytes, format="JPEG")
b64_encoded_image = base64.b64encode(image_bytes.getvalue())
b64_encoded_image = b64_encode(image)
return ImageSynapse(image=b64_encoded_image)


Expand Down
Empty file added bitmind/utils/__init__.py
Empty file.
4 changes: 3 additions & 1 deletion bitmind/validator/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ async def forward(self):
data_aug_params = random_aug_transforms.params

bt.logging.info(f"Querying {len(miner_uids)} miners...")
axons = [self.metagraph.axons[uid] for uid in miner_uids]
responses = await self.dendrite(
axons=[self.metagraph.axons[uid] for uid in miner_uids],
axons=axons,
synapse=prepare_image_synapse(image=image),
deserialize=True
)
Expand All @@ -125,6 +126,7 @@ async def forward(self):
wandb_data['data_aug_params'] = data_aug_params
wandb_data['label'] = label
wandb_data['miner_uids'] = list(miner_uids)
wandb_data['miner_hotkeys'] = list([axon.hotkey for axon in axons])
wandb_data['predictions'] = responses
wandb_data['correct'] = [
np.round(y_hat) == y
Expand Down
1 change: 1 addition & 0 deletions docs/Mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ First, make sure to update `miner.env` with your **wallet**, **hotkey**, and **m

```bash
MODEL_PATH=./mining_models/base.pth
NEURON_PATH=./neurons/npr_miner.py
NETUID=34 # or 168
SUBTENSOR_NETWORK=finney # or test
SUBTENSOR_CHAIN_ENDPOINT=wss://entrypoint-finney.opentensor.ai:443 # or wss://test.finney.opentensor.ai:443/
Expand Down
22 changes: 0 additions & 22 deletions neurons/validator_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ def __init__(
methods=["GET"],
dependencies=[Depends(self.get_self)],
)
self.app.add_api_route(
"/metagraph",
self.get_metagraph,
methods=["GET"],
dependencies=[Depends(self.get_self)],
)

self.loop = asyncio.get_event_loop()
self.proxy_counter = ProxyCounter(
Expand Down Expand Up @@ -116,22 +110,6 @@ async def healthcheck(self, request: Request):
self.authenticate_token(authorization)
return {'status': 'healthy'}

async def get_metagraph(self, request: Request):
authorization: str = request.headers.get("authorization")

if not authorization:
raise HTTPException(status_code=401, detail="Authorization header missing")

self.authenticate_token(authorization)

metagraph = self.validator.metagraph
return {
'uids': [str(uid) for uid in metagraph.uids],
'ranks': [float(r) for r in metagraph.R],
'incentives': [float(i) for i in metagraph.I],
'emissions': [float(e) for e in metagraph.E]
}

async def forward(self, request: Request):
authorization: str = request.headers.get("authorization")

Expand Down
2 changes: 2 additions & 0 deletions setup_miner_env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

sudo apt update -y
sudo apt install python3-pip -y
sudo apt install nano -y
Expand Down
2 changes: 2 additions & 0 deletions setup_validator_env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

sudo apt update -y
sudo apt install python3-pip -y
sudo apt install nano -y
Expand Down

0 comments on commit cd8951c

Please sign in to comment.