Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/VALIDATOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Using Together AI and Open AI simplifies setup and reduces local resource requir
echo "TOGETHERAI_API_KEY=your_together_ai_api_key" > .env
echo "OPENAI_API_KEY=your_openai_api_key" >> .env
echo "HF_TOKEN=your_hugging_face_token" >> .env (needed for some vLLM model)
echo "USE_TORCH=1" >> .env
```

### Step 3: Run the Validator
Expand Down
7 changes: 5 additions & 2 deletions logicnet/base/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, config=None):

# Set up initial scoring weights for validation
bt.logging.info("\033[1;32m⚖️ Building validation weights.\033[0m")
self.scores = torch.zeros_like(self.metagraph.S, dtype=torch.float32)
self.scores = torch.zeros_like(self.metagraph.S.clone().detach(), dtype=torch.float32)

# Init sync with the network. Updates the metagraph.
self.resync_metagraph()
Expand Down Expand Up @@ -205,12 +205,15 @@ def set_weights(self):
bt.logging.trace("top10 values", raw_weights.sort()[0])
bt.logging.trace("top10 uids", raw_weights.sort()[1])

# Convert uids to a PyTorch tensor before processing
uids_tensor = self.metagraph.uids.clone().detach()

# Process the raw weights to final_weights via subtensor limitations.
(
processed_weight_uids,
processed_weights,
) = bt.utils.weight_utils.process_weights_for_netuid(
uids=self.metagraph.uids.to("cpu"),
uids=uids_tensor.to("cpu"),
weights=raw_weights.to("cpu"),
netuid=self.config.netuid,
subtensor=self.subtensor,
Expand Down
10 changes: 10 additions & 0 deletions logicnet/utils/regex_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import re

def extract_numerical_part(text):
# Use regex to find the first occurrence of a number
match = re.search(r'[-+]?\d*\.?\d+|\d+', text)
if match:
return match.group(0)
else:
# Return a specific message or None if no numerical value is found
return "No numerical value found"
13 changes: 11 additions & 2 deletions logicnet/validator/rewarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from logicnet.protocol import LogicSynapse
from sentence_transformers import SentenceTransformer
from logicnet.utils.model_selector import model_selector
from logicnet.utils.regex_helper import extract_numerical_part

SIMILARITY_WEIGHT = 0.2
CORRECTNESS_WEIGHT = 0.8
Expand Down Expand Up @@ -235,8 +236,16 @@ def _compare_numerical_answers(self, ground_truth: str, miner_answer: str):
for char in formatting_chars:
ground_truth = ground_truth.replace(char, '')
miner_answer = miner_answer.replace(char, '')
gt_value = sympy.sympify(ground_truth.strip())
miner_value = sympy.sympify(miner_answer.strip())

# Extract numerical values
gt_value_str = extract_numerical_part(ground_truth)
miner_value_str = extract_numerical_part(miner_answer)

if gt_value_str is None or miner_value_str is None:
raise ValueError("No numerical value found in one of the answers.")

gt_value = sympy.sympify(gt_value_str)
miner_value = sympy.sympify(miner_value_str)

abs_difference = abs(gt_value - miner_value)
epsilon = 1e-8
Expand Down
4 changes: 3 additions & 1 deletion neurons/validator/validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from dotenv import load_dotenv
load_dotenv()
import time
import threading
import datetime
Expand Down Expand Up @@ -378,7 +380,7 @@ def load_state(self):
bt.logging.info(
"\033[1;32m🧠 Loading validator state from: " + path + "\033[0m"
)
state = torch.load(path)
state = torch.load(path, weights_only=True) # Set weights_only=True
self.step = state["step"]
all_uids_info = state["all_uids_info"]
for k, v in all_uids_info.items():
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
bittensor==6.9.4
bittensor==8.5.1
Pillow==10.2.0
PyYAML==6.0.1
setuptools==68.0.0
setuptools==70.0.0
slowapi==0.1.8
tqdm==4.65.0
httpx==0.26.0
numpy==1.26.4
numpy==2.0.1
openai==1.35.14
sentence-transformers==3.0.1
python-dotenv==1.0.1
Expand Down