fix(epoch): emit decayed old bond entries absent from new in mat_ema_alpha_sparse#2584
Open
hconsulting987654321-blip wants to merge 1 commit intoopentensor:mainfrom
Conversation
…alpha_sparse The sparse EMA function `mat_ema_alpha_sparse` previously only emitted output entries present in the `new` matrix. Old bond entries that existed in `old_row` but were absent from `new_row` had their decayed values computed into `decayed_values` but never emitted, causing bonds to drop to zero instantly rather than decaying gradually via EMA. This diverged from the dense equivalent `mat_ema_alpha` and broke the intended bond decay behavior: when a validator removes their weight to a miner, the bond should decay by factor `(1 - alpha)` per epoch rather than being zeroed immediately. Fix: after processing new_row entries, iterate over decayed_values for columns absent from new_row and emit any non-zero decayed value. Output is sorted by column index to maintain the sparse row invariant. Also fix the corresponding test that was asserting the buggy behavior (expected `0.0` corrected to `0.9` for `alpha=0.1`, `old=1.0`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mat_ema_alpha_sparseonly emitted sparse output entries present in thenewmatrix. Old bond entries absent fromnew_rowhad their decayed values computed ((1 - alpha) * old_val) but never emitted, causing bonds to drop to zero instantly instead of decaying gradually.mat_ema_alphaand breaks the bond decay semantics: when a validator removes weight to a miner, the bond should decay by(1 - alpha)per epoch, not zero immediately.new_rowloop, iteratedecayed_valuesfor columns not innew_rowand emit non-zero entries. Output is sorted by column index to maintain the sparse row invariant.test_math_sparse_mat_ema_alphato assert the correct value (0.9instead of0.0foralpha=0.1,old=1.0,new=0.0).Root cause
Fix
Test plan
cargo test -p pallet-subtensor -- mat_ema— all 15 tests passtest_math_sparse_mat_ema_alphanow correctly validates old-only-entry decaytest_mat_ema_alpha_sparse_*) continue to pass🤖 Generated with Claude Code