Skip to content

[FEA](DynamicEmb) Cache serves as a subset of Storage and remove scores; Make External Storage below Storage - #511

Merged
shijieliu merged 10 commits into
NVIDIA:mainfrom
jiashuy:feat/dynamicemb-cache-storage-ps
Oct 28, 2026
Merged

shijieliu merged 10 commits into
NVIDIA:mainfrom
jiashuy:feat/dynamicemb-cache-storage-ps

Conversation

@jiashuy

@jiashuy jiashuy commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Checklist

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

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect cached dynamic-embedding tables that use external storage.

Fix external-row removal during replay before merging; removed keys can currently return on the next lookup.

Findings

  1. P1 Erased keys come back ▶

Summary

The PR moves scores into backing storage, makes the cache use timestamps, and places external storage below backing storage.

  • External storage now holds keys evicted from backing storage.

The five supplied earlier threads were manually resolved without explanatory replies. None supplied a Comment number, so they have no numbered previous-finding entries.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Lookup[Training lookup] --> Cache{In cache?}
  Cache -->|Yes| Cached[Use cached value]
  Cache -->|No| Storage{In backing storage?}
  Storage -->|Yes| Fill[Copy value into cache]
  Storage -->|No| External{In external storage?}
  External -->|Yes| Promote[Copy value into backing storage and cache]
  External -->|No| Initialize[Admit and initialize row]
  BackingEviction[Backing storage eviction] --> Spill[Write row to external storage]
  CacheEviction[Cache eviction or flush] --> WriteBack[Write fresh value to its lower tier]
Loading

Reviews (6) · Last reviewed commit: "test(dynamicemb): assert exact cache hit..." · Reviewed by Greptile

@jiashuy jiashuy changed the title Feat/dynamicemb cache storage ps [Fea]/[DynamicEmb] Cache serves as a subset of Storage and remove scores; Make External Storage below Storage Oct 28, 2026
jiashuy and others added 10 commits October 28, 2026 11:35
… cache prefetch path

With caching and an external_storage, the PS used to stand in for the
storage. It is now a third tier: cache -> DynamicEmbStorage -> PS.

- The cache ranks by timestamp only (always TIMESTAMP/LRU); storage owns
  every key's score and the freshest values.
- _prefetch_cache_path takes `external_storage` explicitly. Every key is
  looked up in storage (key-only, so hits update their score there); keys
  storage lacks are fetched from the PS, and keys in neither are admitted,
  initialized and inserted into storage before the cache.
- What storage evicts to make room is spilled to the PS; cache evictions
  write back to storage without touching its score, or to the PS when
  storage has already evicted the key.
- flush_cache no longer overwrites storage scores with the cache's.
- Tests: PS cases now run with a cache smaller than the table (HBM-only
  mode ignores external_storage), the dead PyDictStorage preload branch is
  gone, and a spill test checks trained rows survive storage -> PS.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
After the cache lookup everything is over the misses, indexed by miss
number, with one `miss_pos` mapping back to the unique batch. Where each
miss lives is three masks (in_storage / in_next / admitted) instead of a
chain of compacted index tensors, and the steps are small helpers.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- Write back cache evictions straight to storage when there is no tier
  below it, instead of masking an all-true selection.
- Skip the gather when a selection is every miss in order.
- Reuse the misses' table ids, scatter -1 only for refused keys, and
  drop a sync that the following nonzero() already answers.

test: with storage the full key set, the NO_EVICTION caching test expects
the backing store to hold every key, not just the evicted ones.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…refetch path

- Update every key's score in storage even when the whole batch hit the
  cache; before, a batch with no miss returned before touching storage.
- A key the cache evicts that storage has since evicted goes to the tier
  below, or is dropped (kept as an evicted key under RETAIN_KEY) when there
  is none; it is not re-inserted into storage.
- Describe storage as the owner of scores, not of the freshest values, and
  type it as DynamicEmbStorage.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…_compact

Each mask used to cost a nonzero() sync plus one boolean index per tensor.
flagged_compact does the selection of several 1-D tensors in one pass with one
sync, and returns the index for the 2-D values. Used for the cache hits, the
misses (frequency, storage score and slot ride along), admission, the rows
going into storage and the cache, the next-tier lookup and the write-back.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…orage

Evaluation reads the cache and storage only, so a key spilled to the
external_storage would be treated as missing and get the evaluation
initializer instead of its trained embedding. Raise rather than return
that silently.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
flush_cache now takes external_storage and reuses _write_back_evicted
(moved to key_value_table.py with _select): keys present in storage are
updated in place, keys absent go to the external storage, or are dropped
(or retained via RETAIN_KEY) when there is none. It no longer inserts new
keys into storage, so the storage-expansion helper is removed. Selections
use flagged_compact.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
NO_EVICTION storage never evicts (it expands instead), so a PS below it
would never receive a spill, and _insert_into_storage loads evicted rows
by hash slot, which is wrong for NO_EVICTION. Refuse the combination at
construction with NotImplementedError and document why in
_insert_into_storage.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…o the PS

_insert_and_evict_keys also reports input keys the storage refused (a full
bucket whose scores all beat the new one) as evicted rows with a negative
slot. load_from_flat leaves those values unwritten, so spilling them to the
external storage could overwrite a valid PS row with garbage. Fill them from
the input values with select_insert_failed_values, as HybridStorage does.

Also make _select take an explicit all_rows flag instead of inferring it from
the row count, which says nothing about the order of the index.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…h_in_cache

The cache metrics report the last lookup, which is the prefetch's: a cold
cache misses every key of A, and after A is cached only the keys B shares
with A hit. Derive both counts from the batches' unique (table, key) pairs
instead of asserting loose bounds.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@jiashuy
jiashuy force-pushed the feat/dynamicemb-cache-storage-ps branch from 3dfff25 to a51273b Compare October 28, 2026 06:05
@jiashuy

jiashuy commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

Key-value pairs that exist in the cache but are evicted by the storage layer are either moved to external storage or placed into retain_evicted_keys.

@shijieliu
shijieliu merged commit 1b75680 into NVIDIA:main Oct 28, 2026
1 check passed
@jiashuy jiashuy changed the title [Fea]/[DynamicEmb] Cache serves as a subset of Storage and remove scores; Make External Storage below Storage [FEA](DynamicEmb) Cache serves as a subset of Storage and remove scores; Make External Storage below Storage Nov 3, 2026
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