Skip to content

fix(dynamicemb): address NO_EVICTION value rows by row, not by hash slot - #468

Merged
shijieliu merged 3 commits into
NVIDIA:mainfrom
jiashuy:fix/dynamicemb-no-eviction-row-indexing
Aug 31, 2026
Merged

shijieliu merged 3 commits into
NVIDIA:mainfrom
jiashuy:fix/dynamicemb-no-eviction-row-indexing

Conversation

@jiashuy

@jiashuy jiashuy commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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.

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]>
@jiashuy

jiashuy commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The 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.

  • Adds explicit value-row propagation through prefetch, forward loading, and backward optimizer updates.
  • Removes redundant cloned update-slot tensors from cache and HBM-direct paths.
  • Adds GPU regression coverage for resident and mixed lookups, resizing, backward updates, and caching spill/flush behavior.
  • Registers the new regression suite in the unit-test runner.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
corelib/dynamicemb/dynamicemb/batched_dynamicemb_function.py Separates value-row addressing from hash-slot counter addressing throughout HBM-direct prefetch, forward, and backward.
corelib/dynamicemb/test/unit_tests/test_no_eviction_row_indexing.py Adds focused CUDA regression tests covering NO_EVICTION row correctness across lookup, resize, update, and cache-tier transitions.
corelib/dynamicemb/test/unit_test.sh Adds the new NO_EVICTION regression module to the forward/backward test suite.

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]
Loading

Reviews (3): Last reviewed commit: "refactor(dynamicemb): let value_row_indi..." | Re-trigger Greptile

@JacoCheung

JacoCheung commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #64821462 -- failed

Job Status Log
pre_check ✅ success view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 14/16 jobs passed

View full pipeline

@jiashuy

jiashuy commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@jiashuy
jiashuy requested a review from shijieliu August 27, 2026 07:23
…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]>
@jiashuy

jiashuy commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #64985004 -- success

Job Status Log
pre_check ✅ success view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ✅ success view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 15/16 jobs passed

View full pipeline

…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]>
@jiashuy

jiashuy commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #65390487 -- success

Job Status Log
pre_check ✅ success view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ✅ success view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 15/16 jobs passed

View full pipeline

@shijieliu
shijieliu merged commit 605623b into NVIDIA:main Aug 31, 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