-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathforward.py
More file actions
82 lines (64 loc) · 3.45 KB
/
forward.py
File metadata and controls
82 lines (64 loc) · 3.45 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# The MIT License (MIT)
# Copyright © 2025 Quant by OpenGradient
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import os
import time
import bittensor as bt
from quant.protocol import QuantQuery, QuantSynapse
from quant.validator.reward import get_rewards
from quant.utils.uids import get_random_uids
async def forward(self):
"""
The forward function is called by the validator every time step.
It is responsible for querying the network and scoring the responses.
Args:
self (:obj:`bittensor.neuron.Neuron`): The neuron object which contains all the necessary state for the validator.
"""
# TODO(developer): Define how the validator selects a miner to query, how often, etc.
# get_random_uids is an example method, but you can replace it with your own.
miner_uids = get_random_uids(self, k=self.config.neuron.sample_size)
wallet_address = os.getenv("SOLANA_WALLET")
if not wallet_address:
bt.logging.error("SOLANA_WALLET environment variable is not set. Using a default value.")
wallet_address = "5HHSqMvTCvgtzdqFb5BbtYjB8cEiJjf8UZ6p5rQczagL"
question = self.questioner.choose_question()
bt.logging.info(f"Choosen question: '{question}'")
query = QuantQuery(
query=question,
userID=wallet_address,
metadata={
"Create_Proof": "True",
"Type": "Validator_Test",
"validator_id": self.wallet.hotkey.ss58_address
}
)
# The dendrite client queries the network.
responses = await self.dendrite(
# Send the query to selected miner axons in the network.
axons=[self.metagraph.axons[uid] for uid in miner_uids],
# Create a proper QuantQuery object and pass it to QuantSynapse
synapse=QuantSynapse(
query=query
),
# All responses have the deserialize function called on them before returning.
# You are encouraged to define your own deserialization function.
deserialize=True,
)
# Log the results for monitoring purposes.
bt.logging.info(f"Received responses: {responses}")
# Adjust the scores based on responses from miners.
rewards = get_rewards(self, query=query, responses=responses)
bt.logging.info(f"Scored responses: {rewards}")
# Update the scores based on the rewards. You may want to define your own update_scores function for custom behavior.
self.update_scores(rewards, miner_uids)
time.sleep(int(os.getenv("VALIDATOR_CADENCE", 500)))