Skip to content

Commit 5c8df7a

Browse files
authored
Merge pull request #769 from macrocosm-os/staging
v2.19.8: - Disable tqdm for logits. - Fix weight synchronization. - Fix rewards averaging. - Make MSRv2 rewards linear. - Add weight setter unit tests.
2 parents e1bc8a7 + b42b7de commit 5c8df7a

File tree

12 files changed

+415
-325
lines changed

12 files changed

+415
-325
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ __pycache__/
88
*.npy
99
*.npz
1010
prompting/storage/
11+
validator_rewards.jsonl
12+
test_validator_rewards.jsonl
13+
uid_tracker.sqlite*
1114

1215
# C extensions
1316
*.so

gpu_container/vllm/reproducible_vllm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
import numpy as np
55
import torch
6+
from tqdm import tqdm
67
from vllm import LLM, SamplingParams
78

9+
tqdm.disable = True
10+
811

912
class ReproducibleVLLM:
1013
def __init__(

prompting/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def _version_to_int(version_str: str) -> int:
7-
version_split = version_str.split(".") + ["0", "0"] # in case a verson doesn't have third element, e.g. 3.0
7+
version_split = version_str.split(".") + ["0", "0"] # in case a version doesn't have third element, e.g. 3.0
88
major = int(version_split[0])
99
minor = int(version_split[1])
1010
patch = int(version_split[2])

prompting/llms/vllm_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def generate_logits(
143143
continue_final_message=continue_last_message,
144144
)
145145

146-
outputs = self.model.generate(prompt, vllm_params)
146+
outputs = self.model.generate(prompt, vllm_params, use_tqdm=False)
147147

148148
if not outputs or not outputs[0].outputs[0].logprobs:
149149
return {}

prompting/weight_setting/weight_setter.py

Lines changed: 177 additions & 156 deletions
Large diffs are not rendered by default.

prompting/weight_setting/weight_synchronizer.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import numpy as np
66
from loguru import logger
77

8-
from shared.constants import WHITELISTED_VALIDATORS_UIDS
98
from shared.epistula import create_header_hook
109

1110

@@ -16,25 +15,23 @@ def __init__(self, metagraph: bt.Metagraph, wallet: bt.Wallet, weight_dict: dict
1615
self.wallet = wallet
1716
self.current_hotkey = wallet.hotkey.ss58_address
1817
self.uid = metagraph.hotkeys.index(self.current_hotkey)
19-
# Handle testnet case.
20-
validator_uids = set([uid for uid in WHITELISTED_VALIDATORS_UIDS if uid < metagraph.n.item()])
18+
self.validator_uids = np.where(np.array(metagraph.validator_permit))[0].tolist()
2119

22-
self.weight_matrix = np.zeros((len(validator_uids), metagraph.n.item()))
23-
self.stake_matrix = np.array([metagraph.S[uid] for uid in validator_uids])
20+
self.weight_matrix = np.zeros((len(self.validator_uids), metagraph.n.item()))
21+
self.stake_matrix = np.array([metagraph.S[uid] for uid in self.validator_uids])
2422

25-
self.validator_uids = np.array(validator_uids)
26-
self.validator_hotkeys = np.array([metagraph.hotkeys[uid] for uid in validator_uids])
23+
self.validator_hotkeys = np.array([metagraph.hotkeys[uid] for uid in self.validator_uids])
2724
self.validator_addresses = np.array(
2825
[
2926
f"{metagraph.axons[uid].ip}:{metagraph.axons[uid].port}"
30-
for uid in validator_uids
27+
for uid in self.validator_uids
3128
if uid < metagraph.n.item()
3229
]
3330
)
3431

3532
self.weight_dict = weight_dict
3633

37-
self.request_tracker = np.zeros(len(validator_uids))
34+
self.request_tracker = np.zeros(len(self.validator_uids))
3835

3936
async def make_epistula_request(self, weight_matrix: np.ndarray, validator_address: str, validator_hotkey: str):
4037
"""Make an epistula request to the validator at the given address."""
@@ -83,13 +80,9 @@ async def send_weight_matrixes(self, weight_matrix: np.ndarray):
8380

8481
async def process_weight_dict(self):
8582
for uid, weights in self.weight_dict.items():
86-
# Verify uid is in whitelist
87-
validator_indices = np.where(self.validator_uids == uid)[0]
88-
if len(validator_indices) == 0:
89-
logger.error(f"Invalid validator UID {uid}, not in whitelist")
90-
continue
91-
92-
# Update the weight matrix for this validator
93-
validator_idx = validator_indices[0]
94-
self.weight_matrix[validator_idx] = weights
95-
self.request_tracker[validator_idx] = 1
83+
if uid in self.validator_uids:
84+
validator_index = self.validator_uids.index(uid)
85+
self.weight_matrix[validator_index] = weights
86+
self.request_tracker[validator_index] = 1
87+
else:
88+
logger.warning(f"UID {uid} is not a validator, skipping")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "prompting"
3-
version = "2.19.7"
3+
version = "2.19.8"
44
description = "Subnetwork 1 runs on Bittensor and is maintained by Macrocosmos. It's an effort to create decentralised AI"
55
authors = ["Kalei Brady, Dmytro Bobrenko, Felix Quinque, Steffen Cruz, Richard Wardle"]
66
readme = "README.md"

shared/epistula.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def query_miners(
175175
logger.info(
176176
f"Responses success: {responses_valid}/{len(uids)}. "
177177
f"Responses exception: {responses_exception}/{len(uids)}. "
178-
f"Reponses invalid: {responses_error}/{len(uids)}"
178+
f"Responses invalid: {responses_error}/{len(uids)}"
179179
)
180180
return results
181181
except Exception as e:

shared/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def SUBTENSOR(self) -> Subtensor:
263263
self._subtensor = Subtensor(network=subtensor_network)
264264
return self._subtensor
265265

266+
def metagraph_force_sync(self) -> Metagraph:
267+
self._last_update_time = 0
268+
return self.METAGRAPH
269+
266270
@property
267271
def METAGRAPH(self) -> Metagraph:
268272
if time.time() - self._last_update_time > 1200:

shared/uids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_random_uids(k: int | None = 10**6, exclude: list[int] = None, own_uid: i
8080
if exclude is None or uid not in exclude:
8181
candidate_uids.append(uid)
8282

83-
# Check if candidate_uids contain enough for querying, if not grab all avaliable uids
83+
# Check if candidate_uids contain enough for querying, if not grab all available uids
8484
if 0 < len(candidate_uids) < k:
8585
logger.warning(
8686
f"Requested {k} uids but only {len(candidate_uids)} were available. To disable this warning reduce the sample size (--neuron.sample_size)"

0 commit comments

Comments
 (0)