Skip to content

[FIX](DynamicEmb): evict LruLfu tables through the ranked evictor on every insert path - #508

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
jyuan-sc:bug-lru-lfu-load-eviction
Oct 29, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
jyuan-sc:bug-lru-lfu-load-eviction

Conversation

@jyuan-sc

Copy link
Copy Markdown
Contributor

Fix the issue:

An LruLfu table (score_strategy=(TIMESTAMP, LFU), two score words per key) device-asserts in LinearBucket::reduce (types.cuh:414, Assertion num_scores_ == 1 failed) whenever a CONST or ASSIGN insert lands in a full bucket.

The AoT insert / insert_and_evict kernels choose the evictor from the score policy of the call, not from the table layout: only an LruLfu call reaches the LruLfu cubin and its ranked evictor. Every other policy runs table_insert_kernel with DefaultEvictor, which calls the single-score reduce(), and that asserts on a 2-word bucket. Callers that do this on an LruLfu table:

  • checkpoint load: _load_key_values places multi-word keys with ScorePolicy.CONST before scattering the score blocks, so a load asserts as soon as one bucket overflows;
  • the backward refresh storage.insert(..., preserve_existing=True) (CONST), when a refreshed key is no longer in its full bucket;
  • rehash on expand (ASSIGN);
  • ScoredHashTable.load (ASSIGN).

Symptom: resuming training from a checkpoint of a full LruLfu table crashes with this assert, either during the load or in the first training steps.

Details

  • kernels.cuh: DefaultEvictor picks the victim of a 2-word bucket with reduce_ranked and the default LruLfu comparator: frequency ascending, ties by timestamp ascending, the same order the cubin uses. Single-score tables keep the existing reduce() call. This covers every AoT CONST / ASSIGN path listed above.
  • key_value_table.py: _load_key_values places multi-word keys with the table's own LruLfu policy and a zero frequency delta instead of CONST. A full bucket therefore evicts through the LruLfu cubin and honors a custom score_function; scatter_score_blocks then overwrites both words as before.
  • Load semantics: the victims are the lowest-ranked keys already in the table, which are keys from earlier load batches. The incoming key is always admitted, as for single-score loads (score_for_compare is the max value for every policy). Keys inside one batch are locked during the kernel and cannot evict each other.

Tests

New cases in test/unit_tests/table_operation/test_lru_lfu.py, on a single 128-slot bucket with exact oracles. For load cases the oracle checks the evicted set equals the lowest-frequency keys, and every surviving key's value row and [ts, freq] block equals its dump.

  • load overflow across batches (both logical column orders) and within one batch
  • load overflow with a custom score_function (evicts by the function's ranking)
  • CONST / ASSIGN x insert / insert_and_evict into a full bucket
  • preserve_existing storage insert into a full bucket
  • storage insert overflow evicts the lowest frequency
  • batched training overflow (hbm / host / caching): forward find-or-insert plus backward refresh over 8 steps
  • single-score (TIMESTAMP / LFU) load overflow, as a regression check

Without the fix, 10 of the 15 new cases hit the device assert. With the fix, on main 1ba40f2 + this commit (1 GPU, RTX PRO 6000):

suite result
test/unit_tests/table_operation/test_lru_lfu.py 35 passed (15 new, each also run in its own process)
test/unit_tests/table_operation/test_table_operation.py 583 passed
torchrun --nproc_per_node=1 -m pytest test/unit_tests/table_operation/test_table_dump_load.py 204 passed
test/test_batched_dynamic_embedding_tables_v2.py 387 passed, 4 skipped

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Fixes full-bucket insertion into two-word LruLfu tables.

  • Full LruLfu buckets rank victims across insert paths.
  • Checkpoint loads use the table’s LruLfu ranking.

No actionable issues were found. Tests were not run during this review.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into bug-lru-lfu-loa..." · Reviewed by Greptile

@shijieliu
shijieliu requested a review from jiashuy October 27, 2026 01:08
…ery insert path

Loading a checkpoint into a {TIMESTAMP, LFU} (LruLfu) table device-asserted
`num_scores_ == 1` in LinearBucket::reduce as soon as a bucket overflowed.
The AoT insert / insert_and_evict kernels pick the evictor by the call's
score policy, not by the table layout, so a 2-word table reaches the
single-score reduce() whenever the caller passes CONST or ASSIGN: load
placement (_load_key_values), backward refresh (preserve_existing),
rehash and ScoredHashTable.load.

- DefaultEvictor ranks a 2-word bucket with the default LruLfu comparator
  (frequency asc, then timestamp asc) via reduce_ranked() instead of
  reduce().
- _load_key_values places multi-word keys with the table's own LruLfu
  policy and a zero frequency delta, so a full bucket evicts through the
  LruLfu cubin (honoring a custom score_function); the score blocks are
  then scattered as before.
- Tests: load overflow across batches (lowest frequency evicted, rows
  intact, both column orders), single-batch overflow, custom
  score_function on load, CONST/ASSIGN insert and insert_and_evict into a
  full bucket, preserve_existing insert, storage insert overflow, batched
  training overflow (hbm/host/caching), and single-score LRU/LFU load
  overflow regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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

@shijieliu
shijieliu merged commit 5e3fb55 into NVIDIA:main Oct 29, 2026
1 check passed
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.

3 participants