opentensor / subtensor

Bittensor Blockchain Layer
The Unlicense
130 stars 143 forks source link

Fix root subnetwork weights normalization #412

Closed igoralferov closed 3 months ago

igoralferov commented 3 months ago

Summary:

Weights are upscaled to u16 for storage. Therefore, weight normalization is required after weights extraction from storage.

Detailed explanation of the fix:

Without re-normalization original validator weights are being distorted by upscaling process before being applied for subnet emissions consensus. As one of the consequences, it allows validators which set weights uniformly across subnetworks to have bigger emissions impact on subnets vs those validators who have higher variance in the weights they set.

The following example illustrates that. Let's say: validator 1 sets equal weights for 4 subnets: 0.25, 0.25, 0.25, 0.25 to sn1, sn2, sn3, sn4 validator 2 sets equal weights for 10 subnets: 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 to sn 1 .. 10 validator 3 sets variable weights for 3 subnets: 0.75, 0.2, 0.05, to sn1, sn2, sn3

Max upscale to u16 makes these weight vectors to look like this in storage: validator 1 = 65535, 65535, 65535, 65535, 0, 0, 0, 0, 0, 0, 0, … validator 2 = 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 0, … validator 3 = 65535, 17476, 4369, 0, 0, 0, 0, 0, 0, 0, …

Sum of the weights: Validator 1 has the sum = 262140 Validator 2 has the sum = 655350 Validator 3 has the sum = 87380

As a result, validator weights are distorted for emissions accounting.

E.g. for subnet 2 original weights are: from validator 1 = 0.25 from validator 2 = 0.1 from validator 3 = 0.2

But for consensus emissions calculation they are accounted as: from validator 1 = 65535 from validator 2 = 65535 from validator 3 = 17476

It doesn't correlate with original weights. If we assume equal stakes of these 3 validators, validator 2 with weight 0.1 was able to have 4x bigger impact on subnet 2 rank than validator 3 with weight 0.2.