Repository navigation
fix(dynamicemb): address NO_EVICTION value rows by row, not by hash slot - #468
Conversation
NO_EVICTION is the only score strategy whose value row differs from its
hash slot: rows come from a per-table auto-increment counter (its score
word is repurposed as the row index) while slots come from the key's hash.
Its key map is also sized 1/max_load_factor times the value buffer, so a
slot can address well past the end of it.
_prefetch_hbm_direct_path translated slot to row on the insert branch only
(score_arg.value), and returned the raw hash slot from the lookup branch's
`h_num_missing == 0` early return. The forward fed that straight into
load_from_flat, so a batch whose keys were all resident read the wrong row
-- or, when the value buffer is allocated to exactly its logical row count,
past the allocation entirely ("an illegal memory access",
dynamic_emb_op.cu:561). The helper for exactly this translation,
_flat_row_indices_for_value_load, was already used by the four
DynamicEmbStorage / HybridStorage.find call sites but never on this path.
Carry the two index spaces separately instead of relying on them
coinciding. PrefetchState gains value_row_indices / update_value_row_indices
(None meaning "same as the slot tensors", so no extra allocation for any
other strategy), and each consumer picks by what it addresses:
load_from_flat, fused_update_for_flat_table -> value buffer -> row
increment_counter, decrement_counter -> ref counter -> slot
This also fixes a quieter defect on the same code: new_indices was
overwritten with the row *before* increment_counter, so newly inserted
NO_EVICTION keys pinned the wrong counter entry while looked-up keys
pinned the right one.
The fault only surfaces on the HBM-direct layout: HybridStorage rejects
NO_EVICTION at construction, and with caching the GPU cache is forced to
TIMESTAMP/LRU, so every slot on that path is a cache slot.
Regression coverage in test_no_eviction_row_indexing.py checks values
rather than liveness -- the DEBUG initializer writes key % 100000, so a
wrong-row read fails on the number instead of waiting for a page fault.
It spans both failure modes (crashing and silent), a rehash, the backward
index space, and the caching layout's spill/fill boundary.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
/build |
Greptile SummaryThe PR separates hash-slot indices from value-row indices so NO_EVICTION tables access values by their assigned rows while reference counters remain slot-addressed.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
K[Unique keys] --> F[Hash-table find or insert]
F --> S[Hash-slot indices]
F --> R[Value-row indices]
S --> C[Increment/decrement reference counters]
R --> L[Load embeddings in forward]
R --> U[Apply optimizer updates in backward]
Reviews (3): Last reviewed commit: "refactor(dynamicemb): let value_row_indi..." | Re-trigger Greptile |
|
❌ Pipeline #64821462 -- failed
Result: 14/16 jobs passed |
|
When using a pure GPU table (without caching) in NO_EVICTION mode, if all forward keys are found in the table, the lookup embedding will be incorrect. This PR fixed this issue. We already distinguished the score/index usage in NO_EVICTION mode, but missed on "all hit" branch on prefech_hbm_direct code path. |
…PrefetchState update_slot_indices was never anything but a copy of slot_indices. Every path that produced the pair either cloned it outright or masked positions that the source tensor had already been given the same value, and the one conditional mask (`indices < 0` on the HBM-direct path) was a no-op because every failure path in the insert/lookup kernels writes the literal -1 -- there is no other negative sentinel. Its only load-bearing use was as a mode flag (`use_counter`), which slot_indices answers identically since the two are None together on every path. Removing it also retires a dead store: ctx.slot_indices was recorded for the backward pass and never read. decrement_counter now uses it, which is what it always should have been indexed by. update_value_row_indices, added alongside value_row_indices in the previous commit, goes with it. It differed from value_row_indices only for a key whose key-map insert failed -- reachable solely via InsertResult::Illegal (key collides with a reserved sentinel) or ::Busy (bucket full *and* every slot pinned by the ref counter). NO_EVICTION keeps the key map at twice the value-row count and expands without a max_capacity ceiling, so Busy is not reachable in practice, and guarding those branches is not worth a per-batch tensor clone. rows_or_slots() now serves the forward and backward passes alike. Net effect: two int64 clones per batch removed (one on the cache path, one on HBM-direct), PrefetchState down to the two index tensors that actually mean different things -- slot_indices for the hash table and the ref counter beside it, value_row_indices for the flat value buffer. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
/build |
|
✅ Pipeline #64985004 -- success
Result: 15/16 jobs passed |
…dress PrefetchState carried the value row as an optional override of slot_indices, with rows_or_slots() resolving the two at every read. Decide it once at assembly instead: NO_EVICTION gets the row its score word holds, every other strategy gets the slot tensor itself. A consumer then reads value_row_indices without having to know which of the two index spaces it is holding, and the field sits next to slot_indices so the pair reads as one decision. _prefetch_hbm_direct_path returns indices as the rows for those strategies rather than None. The two row writes are guarded by `rows is not indices` rather than by the strategy: while rows aliases indices the write to indices has already covered it, and testing identity keeps the code correct if rows ever stops being an alias -- it would then simply be filled explicitly with the same values, where a strategy test would skip it and leave stale rows behind. No behavioural change. Every path hands consumers the same tensor object rows_or_slots() would have returned; only the field's own value differs, being the slot tensor rather than None when the two coincide. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
/build |
|
✅ Pipeline #65390487 -- success
Result: 15/16 jobs passed |
NO_EVICTION is the only score strategy whose value row differs from its hash slot: rows come from a per-table auto-increment counter (its score word is repurposed as the row index) while slots come from the key's hash. Its key map is also sized 1/max_load_factor times the value buffer, so a slot can address well past the end of it.
_prefetch_hbm_direct_path translated slot to row on the insert branch only (score_arg.value), and returned the raw hash slot from the lookup branch's
h_num_missing == 0early return. The forward fed that straight into load_from_flat, so a batch whose keys were all resident read the wrong row -- or, when the value buffer is allocated to exactly its logical row count, past the allocation entirely ("an illegal memory access", dynamic_emb_op.cu:561). The helper for exactly this translation, _flat_row_indices_for_value_load, was already used by the four DynamicEmbStorage / HybridStorage.find call sites but never on this path.Carry the two index spaces separately instead of relying on them coinciding. PrefetchState gains value_row_indices / update_value_row_indices (None meaning "same as the slot tensors", so no extra allocation for any other strategy), and each consumer picks by what it addresses:
load_from_flat, fused_update_for_flat_table -> value buffer -> row
increment_counter, decrement_counter -> ref counter -> slot
This also fixes a quieter defect on the same code: new_indices was overwritten with the row before increment_counter, so newly inserted NO_EVICTION keys pinned the wrong counter entry while looked-up keys pinned the right one.
The fault only surfaces on the HBM-direct layout: HybridStorage rejects NO_EVICTION at construction, and with caching the GPU cache is forced to TIMESTAMP/LRU, so every slot on that path is a cache slot.
Regression coverage in test_no_eviction_row_indexing.py checks values rather than liveness -- the DEBUG initializer writes key % 100000, so a wrong-row read fails on the number instead of waiting for a page fault. It spans both failure modes (crashing and silent), a rehash, the backward index space, and the caching layout's spill/fill boundary.
Description
Checklist