masa-finance / masa-bittensor

Bittensor Subnet Config
https://masa.ai
MIT License
0 stars 0 forks source link

SPIKE: Research Metagraph Storage Persistence #44

Closed teslashibe closed 1 month ago

teslashibe commented 1 month ago

Research how miner scores persists to the metagraph

hide-on-bush-x commented 1 month ago

Communication

Validators communicate with miners through axons and dendrites. Axons are the endpoints that expose the API for the miners, and dendrites are used to communicate these axons. This communication happens over specific ports, with the default being 8091 ( I suggest using 8092 for validators ). This process is demonstrated in the query_and_score method in masa/validator/forward.py.

Storing Miners Information Locally

Validators store information about miners in a state file (state.pt). This is done in the save_state method in masa/base/validator.py. The state can be loaded back into the validator using the load_state method in the same file. However, these methods are not being used in the current setup. ( Will try this afterwards )

Setting Weights ( Metagraph storage )

Validators set weights for miners based on the scores they have received. This is done in the set_weights method in masa/base/validator.py. The weights are processed using torch/numpy and the bittensor CLI, and then set on the blockchain using the subtensor's set_weights method. More details about this method can be found in the subtensor documentation in /bittensor/lib/python3.10/site-packages/bittensor/subtensor.py.

Alternative Storage Methods

Some projects use different methods to store scores, such as SQL databases or server files. However, on the other side most projects use the default set_weights configuration.

Weights are never read by the validator

As far as I understood form the code on our subnet + researching on others projects setting weights is a one way process, you facilitate the information to the subtensor, then the subtensor handles that and distributes based on the reports from all the validators on the subnet.

Extract from bittensor docs:

A subnet validator in a subnet expresses their perspective about how performant subnet miners in the subnet are, through a set of weights

Such weights are aggregated across all the subnet validators in the subnet, to produce a weight matrix W. Subnet validators learn their row in 𝑊 by running the validator module and continuously verifying the responses produced by the subnet miners in terms of speed, intelligence and diversity.

How to see those weights matrix from the python console

import bittensor as bt
subnet = bt.metagraph(1, 'ws://54.205.45.3:9945')
print ('weights', subnet.W )

At the moment, our validators seem to have trouble sending this weights

Yuma consensus: https://docs.bittensor.com/yuma-consensus#weights

Next spike / iteration proposal

Make our validators set weights correctly, now that we have a proper way to double check if they are being set ( with aboves snippet ) we can properly validate that our validators are working on the correct way

mudler commented 1 month ago

@hide-on-bush-x :wave: this ticket was moved to done: what's the changes/outcome of the spike? do we have follow-up cards to track the action items to implement this?

Luka-Loncar commented 2 weeks ago

@hide-on-bush-x do we have any follow up tasks here?

hide-on-bush-x commented 2 weeks ago

Implemented on #46