Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
surcyf123 committed Jan 11, 2024
1 parent 5bfbf31 commit 24badc8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion start_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def update_and_restart(pm2_name, wallet_name, wallet_hotkey, address, autoupdate):
global current_version
subprocess.run(["pm2", "start", "validators/validator.py", "--interpreter", "python3", "--name", pm2_name, "--", "--wallet.name", wallet_name, "--wallet.hotkey", wallet_hotkey, "--netuid", "18", "--subtensor.network", "local", "--subtensor.chain_endpoint", address, "--logging.debug"])
subprocess.run(["pm2", "start", "validators/validator.py", "--interpreter", "python3", "--name", pm2_name, "--", "--wallet.name", wallet_name, "--wallet.hotkey", wallet_hotkey, "--netuid", "18", "--subtensor.network", "local", "--subtensor.chain_endpoint", address])
while True:
latest_version = get_version()
print(f"Current version: {current_version}")
Expand Down
2 changes: 1 addition & 1 deletion state.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions template/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ async def deterministic_score(uid: int, syn, weight: float):

for miner_b64, vali_b64 in zip(syn.completion["b64s"], vali_b64s):
if miner_b64[:50] != vali_b64[:50]:
bt.logging.info(f"image for UID {uid} does not match the correct image! Score = 0")
return 0

bt.logging.info(f"returned image for UID {uid} matches the correct image! Score = {weight}")
return weight


Expand Down
4 changes: 2 additions & 2 deletions template/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ async def call_anthropic(prompt, temperature, model, max_tokens=2048, top_p=1, t
await asyncio.sleep(0.5)

async def call_stability(prompt, seed, steps, cfg_scale, width, height, samples, sampler):
bt.logging.debug(f"calling stability for {prompt, seed, steps, cfg_scale, width, height, samples, sampler}")
# bt.logging.info(f"calling stability for {prompt, seed, steps, cfg_scale, width, height, samples, sampler}")
bt.logging.info(f"calling stability for {prompt[:50]}...")

# Run the synchronous stability_api.generate function in a separate thread
meta = await asyncio.to_thread(
Expand All @@ -419,7 +420,6 @@ async def call_stability(prompt, seed, steps, cfg_scale, width, height, samples,

# Convert image binary data to base64
b64s = [base64.b64encode(artifact.binary).decode() for image in meta for artifact in image.artifacts]

return b64s


Expand Down
23 changes: 18 additions & 5 deletions validators/image_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class ImageValidator(BaseValidator):
def __init__(self, dendrite, config, subtensor, wallet):
super().__init__(dendrite, config, subtensor, wallet, timeout=60)
super().__init__(dendrite, config, subtensor, wallet, timeout=30)
self.streaming = False
self.query_type = "images"
self.model = "dall-e-2"
Expand Down Expand Up @@ -84,9 +84,16 @@ async def b64_to_image(self, b64):
return await asyncio.to_thread(Image.open, BytesIO(image_data))

async def download_image(self, url, session):
async with session.get(url) as response:
content = await response.read()
return await asyncio.to_thread(Image.open, BytesIO(content))
bt.logging.debug(f"Starting download for URL: {url}")
try:
async with session.get(url) as response:
bt.logging.info(f"Received response for URL: {url}, Status: {response.status}")
content = await response.read()
bt.logging.info(f"Read content for URL: {url}, Content Length: {len(content)}")
return await asyncio.to_thread(Image.open, BytesIO(content))
except Exception as e:
bt.logging.error(f"Exception occurred while downloading image from URL {url}: {e}")
raise

async def process_download_result(self, uid, download_task):
try:
Expand Down Expand Up @@ -134,20 +141,26 @@ async def score_responses(self, query_responses, uid_to_question, metagraph):
if syn.provider == "OpenAI":
score_task = template.reward.dalle_score(uid, image_url, self.size, syn.messages, self.weight)
else:
pass
score_task = template.reward.deterministic_score(uid, syn, self.weight)

score_tasks.append((uid, asyncio.create_task(score_task)))

await asyncio.gather(*(dt[1] for dt in download_tasks), *(st[1] for st in score_tasks))

bt.logging.info("Processing download results.")
download_results = [self.process_download_result(uid, dt) for uid, dt in download_tasks]
await asyncio.gather(*download_results)
bt.logging.info("Completed processing download results.")

bt.logging.info("Processing score results.")
score_results = [self.process_score_result(uid, st, scores, uid_scores_dict) for uid, st in score_tasks]
await asyncio.gather(*score_results)
bt.logging.info("Completed processing score results.")

if uid_scores_dict != {}:
bt.logging.info(f"scores = {uid_scores_dict}")
bt.logging.info(f"Final scores: {uid_scores_dict}")

bt.logging.info("score_responses process completed.")
return scores, uid_scores_dict, self.wandb_data

4 changes: 2 additions & 2 deletions validators/text_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class TextValidator(BaseValidator):
def __init__(self, dendrite, config, subtensor, wallet: bt.wallet):
super().__init__(dendrite, config, subtensor, wallet, timeout=75)
super().__init__(dendrite, config, subtensor, wallet, timeout=60)
self.streaming = True
self.query_type = "text"
self.model = "gpt-3.5-turbo" # "gpt-4-1106-preview"
Expand Down Expand Up @@ -103,7 +103,7 @@ async def start_query(self, available_uids, metagraph) -> tuple[list, dict]:

def should_i_score(self):
random_number = random.random()
will_score_all = random_number < 1 / 2
will_score_all = random_number < 1 / 6
bt.logging.info(f"Random Number: {random_number}, Will score text responses: {will_score_all}")
return will_score_all

Expand Down
3 changes: 2 additions & 1 deletion validators/weight_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def perform_synthetic_scoring_and_update_weights(self):
await asyncio.sleep(10)

def select_validator(self, steps_passed):
return self.image_vali if steps_passed % 5 in (0, 1, 2) else self.text_vali
return self.image_vali if steps_passed % 5 in (0, 1, 2) else self.text_vali

async def get_available_uids(self):
"""Get a dictionary of available UIDs and their axons asynchronously."""
Expand Down Expand Up @@ -140,6 +140,7 @@ async def process_modality(self, selected_validator, available_uids):

async def update_weights(self, steps_passed):
""" Update weights based on total scores, using min-max normalization for display. """
bt.logging.info("updated weights")
avg_scores = self.total_scores / (steps_passed + 1)

# Normalize avg_scores to a range of 0 to 1
Expand Down

0 comments on commit 24badc8

Please sign in to comment.