opentensor / subtensor

Bittensor Blockchain Layer
The Unlicense
130 stars 143 forks source link

Normalise weights in Root Epoch Calculation #415

Closed distributedstatemachine closed 3 months ago

distributedstatemachine commented 3 months ago

Description

This PR was original created by Igor, but taking it over, as its easier to manage.

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.

Related Issue(s)

Type of Change

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.