Repository navigation
[FEA](DynamicEmb) Cache serves as a subset of Storage and remove scores; Make External Storage below Storage - #511
Merged
shijieliu merged 10 commits intoOct 28, 2026
Conversation
Contributor
[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
SummaryThe PR moves scores into backing storage, makes the cache use timestamps, and places external storage below 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]
Reviews (6) · Last reviewed commit: "test(dynamicemb): assert exact cache hit..." · Reviewed by Greptile |
jiashuy
commented
Oct 28, 2026
jiashuy
commented
Oct 28, 2026
jiashuy
commented
Oct 28, 2026
jiashuy
commented
Oct 28, 2026
jiashuy
commented
Oct 28, 2026
… 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
force-pushed
the
feat/dynamicemb-cache-storage-ps
branch
from
October 28, 2026 06:05
3dfff25 to
a51273b
Compare
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 |
shijieliu
approved these changes
Oct 28, 2026
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.
Description
Checklist