Skip to content

fix(dynamicemb): clear every score word in table_erase_kernel (LruLfu reclaimed slot evicts live keys) - #518

Closed
jyuan-sc wants to merge 1 commit into
NVIDIA:mainfrom
jyuan-sc:jyuan/erase-clear-all-score-words
Closed

jyuan-sc wants to merge 1 commit into
NVIDIA:mainfrom
jyuan-sc:jyuan/erase-clear-all-score-words

Conversation

@jyuan-sc

Copy link
Copy Markdown
Contributor

Description

table_erase_kernel resets only score word 0 of the erased slot. On a two-word {TIMESTAMP, LFU} (LruLfu) table the reclaimed slot keeps the erased key's frequency in word 1. reduce_ranked() ranks reclaimed slots by (frequency, timestamp) exactly like live keys, so a stale high frequency makes the free slot rank worse than live low-frequency keys. The next insert into that bucket evicts a live key while the free slot stays unused, and the bucket's size counter stays one short.

Single-word tables (LFU, LRU, STEP, CUSTOMIZED) are unaffected: word 0 is the only word and ScoreType() is the global minimum, so the reclaimed slot is always picked first.

Fix: clear the whole AoS-contiguous score block in table_erase_kernel, the same loop insert() already runs on its Reclaim and Evict branches. No Python change.

Test: test_lru_lfu_erase_reclaimed_slot_is_reused_before_evicting_live_keys fills one 128-slot bucket at frequency 1, raises key 1 to frequency 5 via an LRU_LFU lookup, erases it, then inserts one new key with insert_and_evict, and asserts no eviction, size back to 128, every other original key still present, and the new key's score block is [fresh timestamp, 1].

The existing test_lru_lfu_insert_after_erase_no_phantom_frequency did not catch this because its stale frequency equals every live key's frequency, so the reclaimed slot won on the timestamp tie-break. Its docstring is updated to describe what it covers (the Reclaim clear in insert()), and it is kept.

Test results (before/after on an H100) will be posted in a follow-up comment.

Related: #508 (ranked evictor on every insert path for LruLfu tables) is the sibling LruLfu fix; this PR is independent of it.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

table_erase_kernel reset only score word 0 of the erased slot. On a
two-word {TIMESTAMP, LFU} (LruLfu) table the reclaimed slot kept the
erased key's frequency in word 1. reduce_ranked() ranks reclaimed slots
by (frequency, timestamp) like live keys, so a stale high frequency made
the free slot lose to live low-frequency keys: the next insert into the
bucket evicted a live key while the free slot stayed unused and the
bucket size counter stayed one short.

Clear the whole AoS-contiguous score block, the same loop insert()
already runs on its Reclaim and Evict branches. Single-word tables are
unaffected: word 0 is the only word and ScoreType() is the global
minimum, so the reclaimed slot was always picked first.

Test: fill one bucket at frequency 1, raise key 1 to frequency 5, erase
it, insert one new key with insert_and_evict; assert no eviction, size
back to capacity, every other original key still present, and the new
key's block is [fresh timestamp, 1]. Fails before the fix (a live key is
evicted) and passes after, on an H100.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Jingping Yuan <[email protected]>
@jyuan-sc

Copy link
Copy Markdown
Contributor Author

Test results, from-source build of this branch (BUILD_VERSION=0.1.11.dev0, torch 2.10.0+cu128, torchrec 1.4.0) run on an H100, corelib/dynamicemb/test/unit_tests/table_operation:

unpatched (0.1.9 wheel, same test file) this branch
test_lru_lfu_erase_reclaimed_slot_is_reused_before_evicting_live_keys FAIL: insert into a bucket with a reclaimed slot evicted live key(s) [102], size stayed 127 PASS
test_lru_lfu_insert_after_erase_no_phantom_frequency PASS PASS
test_table_operation.py (single-word LFU/LRU/STEP tables) not rerun 151 passed

Not run: the 7 score_function tests in test_lru_lfu.py need numba-cuda, which my env does not have (ImportError before and after this change).

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR clears every score word when erasing a key, so a reclaimed LruLfu slot no longer keeps its old frequency.

  • Erased LruLfu slots get reused before live keys are evicted.

Reviews (1) · Last reviewed commit: "fix(dynamicemb): clear every score word ..." · Reviewed by Greptile

@jiashuy
jiashuy self-requested a review October 29, 2026 07:40

@jiashuy jiashuy left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jiashuy

jiashuy commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

resolve conflicts in #523 and merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants