Ensure listening coefficients never drops to 0#800
Ensure listening coefficients never drops to 0#800fernandofcampos wants to merge 2 commits intodevfrom
Conversation
447c72b to
eaf0d4d
Compare
5591d37 to
80384a6
Compare
xmariachi
left a comment
There was a problem hiding this comment.
Some comments (a full review on the most complicated parts is pending)
amimart
left a comment
There was a problem hiding this comment.
Thanks, I go some first remarks here, didn't check the whole PR yet
f50ce77 to
47e408e
Compare
| const epsilon = "1e-18" | ||
|
|
||
| // EpsilonDec represents a small positive value (1e-18), used to prevent division by zero or issues with zero values. | ||
| var EpsilonDec = alloraMath.MustNewDecFromString(epsilon) |
There was a problem hiding this comment.
We already have this value in emissions params, it's called EpsilonSafeDiv, please reuse it.
There was a problem hiding this comment.
The problem with using that is that it implies reading from the keeper when we need it. I will see if I can optimize it.
| topicId1 := s.setUpTopic(blockHeight2, workerIndexes, reputerIndexes, stake, alphaRegret) | ||
|
|
||
| // Add additional stake to each reputer for second topic | ||
| for _, index := range reputerIndexes { | ||
| s.MintTokensToAddress(s.addrs[index], stake) | ||
| _, err := s.msgServer.AddStake(s.ctx, &types.AddStakeRequest{ | ||
| Sender: s.addrsStr[index], | ||
| Amount: stake, | ||
| TopicId: topicId1, | ||
| }) | ||
| require.NoError(err) | ||
| } | ||
|
|
||
| // Fund the second topic with the same significant initial stake | ||
| s.MintTokensToAddress(s.addrs[reputerIndexes[0]], initialStake) | ||
| fundTopicMessage = types.FundTopicRequest{ | ||
| Sender: s.addrsStr[reputerIndexes[0]], | ||
| TopicId: topicId1, | ||
| Amount: initialStake, | ||
| } | ||
| _, err = s.msgServer.FundTopic(s.ctx, &fundTopicMessage) | ||
| require.NoError(err) |
There was a problem hiding this comment.
It seems like you're staking and topic funding both inside and outside the setUpTopic function. Is that intended? If not, please review other cases
There was a problem hiding this comment.
I didn't realize setUpTopic was already doing that. I cleaned up the tests.
| // Use a more lenient epsilon value (1% instead of 0.001%) | ||
| testutil.InEpsilon2(s.T(), reputerScore.Score, expectedScores[i].String()) |
There was a problem hiding this comment.
Are these changes compromising reputer scoring accuracy? If yes, has it already been double-checked with the research team to see if it's ok?
There was a problem hiding this comment.
Yes, because of the normalization (check at x/emissions/module/rewards/scores.go). I will double check with research.
fe49dfc to
6e2c27d
Compare
fstecker
left a comment
There was a problem hiding this comment.
As we discussed today, it would be great if you could wait with this PR until we have some potential problems in the design figured out.
| } | ||
|
|
||
| // If all stakes are zero, use epsilon values instead to avoid division by zero | ||
| if allZeroOrEpsilon { |
There was a problem hiding this comment.
Isn't the whole allZeroOrEpsilon thing redundant? If the only thing that happens in there is also inside the if allZero?
| max, err := alloraMath.Max( | ||
| coefficientsPlusLearningRateTimesGradient, | ||
| alloraMath.ZeroDec(), | ||
| EpsilonDec, |
There was a problem hiding this comment.
This wouldn't allow any of the listening coefficients to go below epsilon? I think that should still be allowed, we only need to check that they don't all become zero (or equivalently, their sum isn't zero). I think we already do this elsewhere, so this shouldn't be necessary?
x/emissions/module/rewards/scores.go
Outdated
|
|
||
| // Only normalize coefficients when there are multiple reputers | ||
| // When there's only one reputer, normalization is unnecessary and would force the value to 1.0 | ||
| if len(reputerListeningCoefficients) > 1 { |
There was a problem hiding this comment.
I don't think that's necessary. If there's only one reputer, its listening coefficient doesn't matter anyway (the losses will be whatever this reputer says, what else should it be).
| return nil, nil, errors.Wrapf(err, "GetAllReputersOutput, error normalizing coefficient %d", j) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I'm having second thoughts about the normalization, and now think it might be better to normalize so that the max listening coefficient is 1, instead of normalizing so the sum is 1. That would make the listenedStakeFraction as high as possible and the if listenedStakeFraction.Lt(params.MinStakeFraction) branch less likely to be taken. Which might improve convergence. Maybe. I'll think about it some more.
Purpose of Changes and their Description
Link(s) to Ticket(s) or Issue(s) resolved by this PR
Are these changes tested and documented?
Unreleasedsection ofCHANGELOG.md?Still Left Todo
Fill this out if this is a Draft PR so others can help.