Repository navigation
[FEA](DynamicEmb) Store a value row for every key in LinearBucketTable & DynamicEmbStorage - #515
Conversation
[High impact] The changes since the previous review appear safe to merge. SummaryThe PR separates value rows from hash slots, so growth can rebuild the key map without moving embeddings or optimizer state.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Key lookup] --> B[Hash slot]
B --> C[Stored value row]
C --> D[Embedding and optimizer state]
B --> E[Scores and reference counters]
F[Growth] --> G[Rebuild key map]
G --> C
Reviews (10) · Last reviewed commit: "[FIX](DynamicEmb) Call the global 64-bit..." · Reviewed by Greptile |
|
All unit tests passed. Next, I will refactor the implementation of the NO_EVICTION policy. |
Until now a key's value row was its hash slot, so a rehash had to move every value, and NO_EVICTION kept the row in the score word at the cost of the score. A table built with use_rows now stores a row for each key in its own per-slot int32 `rows` column and reports that row as the key's index. A row is allocated from an auto-incrementing per-table counter the first time a key occupies a slot, and then stays with the slot: the key that evicts the occupant, or reuses the slot after an erase, inherits it. Rows therefore stay dense, and a rehash can carry them along instead of moving values. - table_resolve_rows kernel maps slots to rows (allocating for a slot that has none); negative entries pass through, while overflow slots and a missing row without `allocate` are asserted. - LinearBucketTable(use_rows): lookup/insert/insert_and_evict/export report rows; erase keeps reporting presence; reset and copy_table_from carry rows. - Rehash support: insert_carrying_rows re-inserts a key with its row, and carry_rows_from re-places the rows of reclaimed (erased) slots into free slots of the new table with two small kernels that allocate only O(reclaimed). - Cache tables keep slot == row (their reference counters are keyed by slot), so use_rows is not supported together with overflow. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
DynamicEmbStorage (except NO_EVICTION) now builds its key map with use_rows, so a key keeps its value row when the table is rehashed: the expansion carries rows along (insert_carrying_rows, plus carry_rows_from for the rows of reclaimed slots) instead of moving every value. Things keyed by slot rather than by row are fixed to use slots: the multi-word score blocks in export and checkpoint load (LinearBucketTable.slots_of), and the packed slot_index of an incremental dump, which now carries slot and row for such a table. Incremental dump and replay keep the rows of the source: - meta["num_rows"] is the source's row counter, which the replica adopts. - An erase that is retained records the packed slot/row it left reclaimed (meta["erased_slot_index"]). Replay removes the erased keys, then restores those reclaimed slots (restore_reclaimed_slots), then writes the upserts, so add A / erase A / add B ends with B at A's slot and row, and a slot nobody took stays reclaimed with its row on a replica that never held A. - An erase without RETAIN_KEY is allowed but marks the table (erase_untracked); the dump reports it and replay_increment refuses such a delta before writing anything. Tests: replay round trip with an erased tail, add/erase/add within one window, a reclaimed slot for a key the replica never held, an unretained erase, and restore_reclaimed_slots on its own. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ect prefetch DynamicEmbStorage stores a value row per key, so lookup and insert report rows, not hash slots. _prefetch_hbm_direct_path still passed those results straight to increment_counter and saved them as slot_indices for the backward pass. The reference counters are keyed by hash slot, so a forward protected unrelated slots and left the rows it was using open to eviction: an overlapping forward could replace a row before the backward had updated it. LinearBucketTable.lookup and insert can now also return the hash slots (return_slots), and _find_keys passes that on. The prefetch path counts and saves slots for the counters, and keeps the value rows separately for addressing the value buffer, which is how it already treated NO_EVICTION. A table whose row is its slot is unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
_expand_tables_impl rebuilt the key map without passing use_rows, so the replacement defaulted to False for a DynamicEmbStorage. The expansion then took the slot-addressed path and read each key's value at its hash slot, while the values are stored at the key's row: existing keys got other keys' embeddings and optimizer state, and the new map lost its rows. Pass the old map's use_rows to the replacement, so rows are carried and values stay where they are. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…c rehash insert insert_carrying_rows went into _deterministic_insert without the num_scores_ == 1 check that every other deterministic entry point makes. That helper reads and writes one score word per key, so on a two-word LRU_LFU table a rehash under DEMB_DETERMINISM_MODE touched the wrong bucket and score positions. Add the same assertion. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…reclaimed slot restore_reclaimed_slots assumed every slot a delta reports as reclaimed is empty or already reclaimed on the replica. That fails when the source evicts A with B and erases B before the next dump: the delta holds neither (no live key took the slot), only B's erase, so the replica, which never held B, still holds A in the slot and nothing overwrites it. The kernel now handles the three states a slot can be in, in one pass: - empty: claimed, reclaimed, and given the row; - reclaimed: must already own that row (asserted, not overwritten, so a diverged replica is not hidden); - a live key: erased the way the erase kernel does (score words cleared, digest emptied, bucket_sizes decremented), then the slot owns the row. A locked slot, or a lost race for one, means something else is writing to the table and is asserted. It is rewritten on the Table/Bucket accessors, like the other slot-level replay write, instead of the raw key column, so it can touch the digest, scores and bucket count; the Python side is a single call. Tests: restore on its own after a real erase, and a replay round trip where the source evicts a key for one it then erases, comparing the replica's table with the source's. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The per-key columns of an incremental dump are gathered across the ranks and so reach every receiver, but num_rows and erased_slot_index stayed local to the rank that produced the delta. A gathered delta handed to every replica rank (say, written by rank 0 only) then had each receiver apply another rank's row counter and reclaimed slots: replay could assert on slots it does not hold, or leave the counter below rows already restored, so a later insert reused an occupied row. Both fields are now lists with one entry per source rank, in rank order (_all_gather_by_rank, which unlike the merging evicted-key gather keeps each rank's part apart). Replay picks the receiver's own entry before it writes anything (_for_this_rank): its shard index for a gathered delta, the only entry for one that was not gathered, and anything else is rejected. They stay in meta[i], per table, like slot_index. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
erase_untracked was one boolean on the table state, which covers every logical table of a storage. An erase without RETAIN_KEY on table A set it, and the dump then reported it for table B as well, so a delta holding only B was refused by replay for good. Keep the set of logical tables that had such an erase, mark only the one erased from, and read that table's entry when dumping. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
0c60b51 to
6cad828
Compare
NO_EVICTION used to keep a value row in each key's score word, with its own counter, so the score could not carry anything else and every path that read a score had to know that. Now it is a mode of a table that, like every other storage, keeps a row per key in the table's rows column. - NO_EVICTION alone keeps no score (a constant word that is never written); (NO_EVICTION, CUSTOMIZED) keeps CUSTOMIZED's. Other combinations are refused. - The score-as-row machinery is gone: no_eviction_assign_scores and its kernel, the next-index counter, and the helpers that decoded rows from scores. - The value buffer is exactly half the key map from the start (not init_capacity, which need not be a whole number of buckets), and an expansion keeps it so. - A NO_EVICTION table is sized for expansion by the rows it has handed out, not by the keys it holds: an erased key's slot keeps its row, so rows can outnumber keys. - Allocating a row at or past the value buffer's size is asserted on the device (row_limits), kept in step with the buffer through every expansion. - Loading a checkpoint sizes a table by the keys in the file. It passed only the part that overran the value buffer, which undercounted, and a table could be left without the rows to hold them. - incremental_dump and replay_increment refuse tables whose strategy contains NO_EVICTION: they have no timestamp to take a delta by, and their erased keys are the user's to manage. - HybridStorage still refuses NO_EVICTION. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- incremental_dump: erase_untracked is the dump group's, not the dumping rank's. A delta gathers every rank's keys and slots and is handed whole to every receiver, so one rank's untracked erase has to taint it whichever rank's copy is shipped; the other per-rank fields were already gathered. - set_score accepts (NO_EVICTION, CUSTOMIZED) in either order: the check compared the whole strategy with CUSTOMIZED, so a user score could never be set on the table the strategy exists for. - Loading a checkpoint is sized by the keys this rank keeps, counted from the key file, not by every key in it. A checkpoint can hold many ranks' keys and each rank keeps its own share; a NO_EVICTION table has no max_capacity to stop it growing for the rest. - replay_increment documents that a source expansion (rehash) ends the delta chain: a target's capacity does not change by itself, so replay rejects the deltas of a source whose capacity no longer matches. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… docs - incremental_dump skips a table whose score_strategy contains NO_EVICTION with a warning instead of raising. Raising midway through a model dumped with an integer threshold lost what the modules before it had already drained (retained erased and evicted keys); skipping happens before anything is drained. replay_increment still refuses such a table. - DynamicEmb_APIs.md: describe (NO_EVICTION, CUSTOMIZED) and set_score for it, NO_EVICTION's value buffer being half its key map and its expansion by rows handed out, loads sized by the keys a rank keeps, the new incremental_dump meta (packed slot_index, num_rows, erased_slot_index, erase_untracked), and what replay_increment now requires (retained erases, the source growing ends the delta chain, no NO_EVICTION tables). Drop what no longer holds. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
All unit tests passed. Ready to merge. A child process is spawned and asserted to throw an error in |
GlanceFeatures
Bug fixes
Limitations
Docs / tests
|
Switch the per-slot value row, the per-table row counters and the row limits from int32 to int64, and the row kernels with them. A packed `slot << 32 | row` cannot hold an int64 row, so the dump's slot_index of a table that stores rows is now an [N, 2] int64 tensor (key slot, value row), and so is the erased_slot_index. HybridStorage keeps its 1-D slot_index. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A table that stores rows now reports each erased slot as a (slot, row) pair, so one erased slot is a [1, 2] tensor and numel() is 2. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
dyn_emb declares its own atomicAdd overloads, which hide the CUDA one for unsigned long long, so the int64 row counters did not compile. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
unit tests passed |
Summary
A key's value used to live at its hash slot, so the value buffer was exactly as
large as the key map and a key could never move without its value moving with it.
This PR gives every key a value row of its own, kept apart from the hash slot:
per table.
moving values.
mode of the same mechanism, and the old score-as-row code is deleted.
reproduces the source's placement exactly.
Why
its value to the new slot. Now the key keeps its row; only the key map is
rebuilt and the value buffer is extended in place.
word and a counter of its own, so the score could carry nothing else and every
path that read a score had to know about it.
key map at twice its value buffer, which only works if a slot is not a row.
What changes
LinearBucketTable (scored_hashtable.py, src/table_operation/)
row_limits_: int64, one per table.
takes the next row of its table; every later occupant (the key that evicts it,
or reuses it after an erase) inherits that row.
hash slots, which state keyed by slot (reference counters, score blocks) needs.
rows and re-places reclaimed (erased) slots with theirs, so no row is lost and
no value moves.
DynamicEmbStorage (key_value_table.py, batched_dynamicemb_function.py)
value buffer is addressed by row. The HBM-direct prefetch keeps both.
NO_EVICTION
score, and set_score works for it. Other combinations are refused.
keeps it so.
an erased key's slot keeps its row, so rows can outnumber keys.
Incremental dump / replay (incremental_dump.py, batched_dynamicemb_tables.py)
value row); meta["erased_slot_index"] is a list of [M, 2] tensors, one per
source rank. meta["num_rows"] is carried per source rank too. HybridStorage
keeps its 1-D slot_index (tier bit + slot).
ends with the same keys at the same slots owning the same rows.
logical table and combined across ranks into one boolean, otherwise the delta
is refused.
ends the delta chain, so the target has to be rebuilt from a full checkpoint.
refuses them.
Safety net
the device (table_resolve_rows: row < row_limits[table]), with no host sync.
Limits are set at creation and after every expansion.
Bug fixes
could overrun its buffer (1500 keys into a 1024-row table did not expand). It is
now sized by the keys this rank owns (_count_owned_keys).
they are moved to the device as int64 in the load/store helpers.
still holding a live key) and asserts that a reclaimed slot already owns its row.
atomicAdd overloads that hide the CUDA one).
Limitations
table) and the inference table (InferenceLinearBucketTable) still use the hash
slot as the value row; use_rows is rejected for a cache / enable_overflow table.
(refused).
are [N, 2]); checkpoint contents are unchanged.
Tests
New or reworked tests:
victim's row, an erased slot keeping its row, rehash carrying rows and reclaimed
slots, restoring reclaimed slots (including a row beyond 2^32), the row-limit
assertion (in a subprocess, since it kills the CUDA context), and its default.
NO_EVICTION alone / with CUSTOMIZED; key map exactly twice the value buffer
through an expansion; unaligned init_capacity; expansion following rows rather
than keys; erase-and-reinsert never outgrowing the buffer; checkpoint load
expands for every key in it.
round trips with erased keys, add/erase/add in one window, untracked erases
(including the group-wide flag on 8 ranks), NO_EVICTION tables skipped / refused,
[N, 2] slot_index and erased_slot_index.
Test status (commit fccdcf5, fresh
git reset --hard+ rebuild on two EOS nodes):load path.
device assert kills that subprocess's CUDA context); the test passes.
Suggested reviewing order
insert_carrying_rows, carry_rows_from, set_row_limits).
rehash helpers and the restore kernel.
DynamicEmbStorage.load, _encode_slot_index, the replay write path.
metadata, NO_EVICTION skip/refusal.
Checklist