Repository navigation
feat(dynamicemb): erase_by_score for lru_lfu tables, per named table - #536
Merged
Merged
Conversation
…r word erase_by_score / erase_by_score_async refused a (TIMESTAMP, LFU) table, whose keys carry two score words. The kernel already takes num_scores and score_index and clears every score word of an erased slot; only the Python checks were in the way. A (TIMESTAMP, LFU) table now qualifies for both TIMESTAMP and LFU, and the strategy named picks the word compared: TIMESTAMP word 0 (the last-access timestamp, an expiry whatever the frequency), LFU word 1 (the raw access count, whatever the age). The word comes from get_physical_score_order, so (TIMESTAMP, LFU) and (LFU, TIMESTAMP) behave the same. It is threaded from the module (erase_score_word) through DynamicEmbStorage.erase_by_score and _erase_state_by_score to LinearBucketTable.erase_by_score(score_word=...), which passes it to the kernel as score_index. An LRU_LFU table must name the word; any other multi-word layout is still refused. The layouts check, the untracked-erase marking and the chunking are unchanged. The docs note that an LFU-only erase also removes keys that were just admitted, since the count never decays. Tests (test_erase_by_score_lru_lfu.py): each word compared alone (a stale key erased however frequent, a fresh rare key erased by LFU), both words cleared and the reclaimed slot taken before any live key, pinned slots spared, both tuple orders, and erase_by_score_async on a model mixing LFU and (TIMESTAMP, LFU) tables. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jingping Yuan <[email protected]>
erase_by_score_async erased every table whose score strategy qualifies, at one threshold. Tables that share a module but need their own threshold -- a TTL of a day on one and of 90 days on another -- could not be told apart, and a timestamp-scored table with no TTL was erased too. Add table_names: Optional[Sequence[str]] = None to the module method and to the model-level function. None keeps today's behavior. Otherwise the scan is narrowed to the tables named, in table order; storage and the kernel already take a table-id list. One call per threshold; the calls on a module queue in order, each with its own handle. Everything is still checked before anything starts. An empty list or a bare str, a name that is not a table of the module (on a model: of any module), and a table the strategy does not erase are errors. On a model, each module gets the names it holds, and a module that holds none is not started. The new erase_table_ids does the narrowing and check_table_names the argument check. The scan, the kernel, chunking, the gate, the untracked-erase marking and the lru_lfu word selection are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jingping Yuan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jingping Yuan <[email protected]>
…evice_timestamp erase_by_score_async(model, ..., table_names=...) raised for a name that no module of this rank's model holds. Under TABLE_ROW_WISE a table lives on one node's ranks only, so the same call raised on every other rank. strict=False now skips such names: a rank that holds none of them erases nothing and its result is (0, 0). A held name that the strategy does not erase is still an error. strict defaults to True, so nothing changes for existing callers. The module method keeps its check: every name must be a table of that module. device_timestamp, the device clock a TIMESTAMP threshold is read from, is exported from dynamicemb; the docs and the example use it from there instead of dynamicemb_extensions. The package now imports torch before dynamicemb_extensions, as every submodule does: the extension needs libc10, which torch loads, so "import dynamicemb" in a fresh process would otherwise fail where torch/lib is not on LD_LIBRARY_PATH. The docs also say how to get counts per table: one call per table, each table being scanned once either way. Tests (test_erase_table_filter.py): names a rank does not hold are skipped, a rank that holds none erases nothing, and a held name the strategy does not erase is still refused with strict=False. dynamicemb.device_timestamp() works in a fresh process with torch/lib off LD_LIBRARY_PATH. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jingping Yuan <[email protected]>
Contributor
[Medium impact] The PR appears safe to merge, with a non-blocking correction needed in the TTL example. Findings
SummaryAdds score-based erase for
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["erase_by_score_async"] --> B["Check arguments and requested names"]
B --> C["Select tables held by each module"]
C --> D["Check all selected modules"]
D --> E["Queue one erase per module"]
E --> F["Choose timestamp or frequency word"]
F --> G["Scan selected tables in chunks"]
G --> H["Spare pinned keys; clear every score word of erased keys"]
H --> I["Return combined counts"]
Reviews (3) · Last reviewed commit: "Merge branch 'main' into jyuan/erase-by-..." · Reviewed by Greptile |
jiashuy
reviewed
Nov 6, 2026
…e, clock-safe tests - Rename BatchedDynamicEmbeddingTablesV2.erase_table_ids to get_erase_table_ids. - Remove the score_name parameter of LinearBucketTable.erase_by_score: no caller passes it, and on a (TIMESTAMP, LFU) table it could only select the timestamp word; score_word names the word to compare. - The table-filter tests and the model test of test_erase_by_score_lru_lfu.py no longer assume the GPU clock has run for hours. They still take their reference from device_timestamp(), shifted past it by the oldest age they set, so every timestamp they write is at or after the clock and none underflows. Tests (H100): test_erase_async.sh 180 passed; test_erase_distributed and test_erase_stress all cases passed; test_lru_lfu.py 36 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jingping Yuan <[email protected]>
shijieliu
approved these changes
Nov 9, 2026
shijieliu
added a commit
to shijieliu/recsys-examples
that referenced
this pull request
Nov 9, 2026
Merge main up to d03198c (NVIDIA#536, NVIDIA#534, NVIDIA#529, NVIDIA#527, NVIDIA#526). - NVIDIA#527 sends empty weights for an empty input under index dedup, the change this branch made in shard/embedding.py: the merge keeps main's docstring and comments and this branch's needs_counters, the same condition. - NVIDIA#529 adds PrefetchState.key_map_generation and _slots_after_rehash, and looks a prefetched batch's slots up again in its backward when a later prefetch rehashed the table. Git put _slots_after_rehash between PrefetchState's fields and this branch's record_stream, which then fell out of the class without a conflict; the merge puts it back. The lookup's row map (out_rows, grad_rows) only says where rows go, and the forward's load_from_flat_by reads value rows, which a storage keeps through a rehash. - NVIDIA#534 (each table's HBM budget in fused groups), NVIDIA#536 (erase_by_score for lru_lfu tables, per named table) and NVIDIA#526 (VMMTensor frees after the queued work) merge without conflicts. Every file of test/unit_test.sh passes on one node, each group's .sh files with its DYNAMICEMB_TEST_GROUP, and so does the HSTU end-to-end test on one node and on 2. On 2 nodes test_hier_dist.py (122), test_hier_overflow.py (79) and test_hier_pipeline.py (45) pass, and on 4 nodes test_hier_dist.py (122). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Summary
erase_by_score_async(#532) gains three things.(TIMESTAMP, LFU)(lru_lfu) tables. The strategy you pass picks the score word compared:TIMESTAMPcompares the last-access time, andLFUcompares the access count.table_namesfilter, so tables that share a batched module can be erased at different thresholds: one call per threshold.strict=False, which skips names the calling rank doesn't hold, so the same call works on every rank under table-wise and table-row-wise sharding.strictdefaults toTrue, so existing callers see no change.device_timestamp, the device clock aTIMESTAMPthreshold is read from, is now exported fromdynamicemb.The motivating use is a per-table time-to-live in online training. At a training checkpoint boundary, keys not accessed within each table's max age are erased, so an id that comes back starts from a fresh embedding. The threshold is
device_timestamp() - max_age_ns.Changes
Four commits, in order:
6f170efErase by score on(TIMESTAMP, LFU)tables, by either word.num_scoresandscore_indexand clears every score word of an erased slot (fix(dynamicemb): clear every score word in table_erase_kernel #523); only the Python checks were in the way.(TIMESTAMP, LFU)table now qualifies for bothTIMESTAMPandLFU. The word compared comes fromget_physical_score_order, so(TIMESTAMP, LFU)and(LFU, TIMESTAMP)behave the same.erase_score_word) throughDynamicEmbStorage.erase_by_scoretoLinearBucketTable.erase_by_score(score_word=...), which hands it to the kernel asscore_index.LFU-only erase also removes keys that were just admitted, because the count never decays.ba123d8Narrowerase_by_score_asyncto named tables.erase_by_score_async(model, ...)andBatchedDynamicEmbeddingTablesV2.erase_by_score_async(...)taketable_names: Optional[Sequence[str]] = None.Nonekeeps the current behaviour: every table the strategy erases.str(TypeError).DynamicEmb_APIs.mdhas an example with two tables at two TTLs, one call each.1f7308fDocs only: generic table names in that example.0c64430strict=Falsefor the model-level call, anddevice_timestampexported fromdynamicemb.strict=False, a name that no module of this rank's model holds is skipped instead of raising. A rank that holds none of the names erases nothing and returns(0, 0). A held name that the strategy doesn't erase still raises. The module method keeps its own check.device_timestampcan be imported fromdynamicemb; the docs and the example use it from there. The package imports torch beforedynamicemb_extensions, as every submodule does, since the extension needs the libraries torch loads.The scan, the chunking, the gate, the layouts check and the
erase_untrackedmarking are unchanged. Nothing changes in CUDA.This PR is independent of #518, which was closed; the same kernel fix landed as #523, which is already on
main.Tests
On an H100:
test/unit_tests/erase_async/test_erase_by_score_lru_lfu.py(new, 16 tests): each word compared on its own; both words cleared and the reclaimed slot reused before any live key is evicted; pinned slots spared; both tuple orders behave the same; a model mixingLFUand(TIMESTAMP, LFU)tables.test/unit_tests/erase_async/test_erase_table_filter.py(new, 16 tests): only the named table is erased; two tables at two thresholds back to back;Noneequals naming every table; bad names refused with nothing erased; at model level each module gets the names it holds and a bad name starts no module; withstrict=Falsenames this rank doesn't hold are skipped, a rank holding none erases nothing, and a held name the strategy doesn't erase is still refused;import dynamicemb; dynamicemb.device_timestamp()works in a fresh process without torch's lib directory onLD_LIBRARY_PATH.test_erase_by_score.pyandtest_erase_api.pyare updated for the new acceptance rules.bash test/unit_tests/erase_async/test_erase_async.sh: 180 passed, 0 skipped.test_erase_distributedandtest_erase_stressreport all cases passed.test/unit_tests/table_operation/test_lru_lfu.py: 36 passed.The four commits merge cleanly onto the current
main(c6e2bb2); nothing onmainsince2d1dfcbtouchescorelib/dynamicemb.Integration evidence
We integrated this branch into an online-training loop for a production recommendation model.
table_names=[name]andstrict=False. One extra pass right after a checkpoint restore, before the first training step.Follow-ups
We plan to send these as separate PRs after this one, and would welcome the maintainers' view on the approach.
erase_by_scoreerases, for incremental dumps and delta updates.erase_by_scorerecords nothing about what it erases. A table it removed keys from is markederase_untracked,incremental_dumpreports the mark, andreplay_incrementrefuses the delta. So a delta from a TTL table can't carry the TTL's deletions to a replica or to serving, which then keep the expired keys, and online training can't use a TTL and delta updates together.erase_by_score, matchingerase_keys(..., EvictedItemMode.RETAIN_KEY). The erased keys, with their slot indices for tables that store rows, are appended to the bufferpop_erased_keysdrains;incremental_dumpcarries them inerased_keys/erased_slot_index; and the table isn't markederase_untracked, so its deltas stay replayable.Note: erased count vs table size
When a table is at capacity, the drop in table size between checkpoints combines new inserts, capacity evictions and the erase, so the erase count alone doesn't predict the next table size. That's correct behaviour, but a sentence in the docs may save users some confusion.
Checklist
🤖 Generated with Claude Code