Repository navigation
[FEA](DynamicEmb) intput per key score by PRECISE_CUSTOMIZED score strategy - #530
Merged
Merged
Conversation
Contributor
[Medium impact] The PR appears safe to merge, with a non-blocking gap in negative-score checks when index dedup is enabled. Findings
SummaryAdds per-key int64 eviction scores through
The previous-review merge bases differ, so this review used the full PR changes. No runtime tests were run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Keys and per-key scores] --> B[Row-wise distribution]
B --> C[Merge repeated keys using MAX]
C --> D[Check scores]
D --> E[Assign storage scores]
E --> F[Read embeddings]
F --> G[Backward updates values only]
Reviews (6) · Last reviewed commit: "[FIX](DynamicEmb) Keep external stores w..." · Reviewed by Greptile |
Collaborator
Author
|
I am planning to remove the |
Collaborator
Author
|
Unit tests passed |
jiashuy
force-pushed
the
feat/dynamicemb-per-key-score
branch
from
November 2, 2026 09:12
50299d6 to
a3e04f2
Compare
…ique max/min
Per-key scores will ride the KJT weights channel as int64. Prepare the two
pieces that act on that channel before the feature itself lands:
- block_bucketize_sparse_features: accept int64 weights next to float32. The
kernel only copies each weight to its new position, so both are bit-exact.
- segmented_unique_cuda: add a `reduce` argument ("sum" default, "max",
"min") for combining the values of a repeated key. node_freq starts from
the identity of the reduction so a representative and its duplicates can
reduce into it in any order.
- segmented_unique_cuda: check that input_frequencies is int64, on the keys'
device and contiguous; the kernel reads it as raw int64 and any other
dtype was silently misread.
Tests: test_int64_weights_channel (bucketize, permute, split keep int64
weights bit-for-bit) and reduce / dtype cases in test_unique_op, both
registered in unit_test.sh.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…el group ShardedDynamicEmbeddingCollection took is_lfu_enabled and has_admit_strategy from the first table only (shard() broke out of its loop after one table), so a collection whose first table was not LFU gathered no frequencies for the LFU tables after it, and one whose first table was LFU handed frequencies to tables that never asked for them. - collect_frequency_requirements groups tables by their sharding type and answers "any LFU / any admit" per sharding; the collection keeps the answer per sharding and the dedup and input dist read it by sharding index. - ctx.frequency_counters gets one entry per sharding, None where the sharding needs none or its input is empty, so it stays aligned with the shardings. - BatchedDynamicEmbeddingTablesV2 keeps frequency_counters only if its group evicts by LFU or admits; a CUSTOMIZED group next to an LFU one receives the counters riding the sharding's weights channel and now drops them. Tests: per-sharding requirements, the kernel-group guard, and an end-to-end mixed LFU/TIMESTAMP collection in test_lfu_scores. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…nd EmbeddingBagCollection A table can take a score per key from the input instead of one score per batch (`DynamicEmbTableOptions.per_key_score`). - `ScoredKeyedJaggedTensor`: a KeyedJaggedTensor with an int64 `scores` tensor beside the values, kept in step by split/permute/to. - Scores go through their own all2all and are placed beside their keys by the bucketize permutation; they stay a separate channel from the frequency counters (LFU / admission). - Tables hand the scores to the key map through one `score_source`, which picks the frequency for an LFU table and the input scores for a CUSTOMIZED one. A key repeated in a batch keeps its largest score (also with `use_index_dedup`); a later batch assigns. - cache path: new keys enter the storage with their own score; the unused score/in_storage arguments of `_load_storage_values` are gone. - Rules: row-wise only, CUSTOMIZED (alone or with NO_EVICTION), no admit_strategy, no VBE, DynamicEmb tables only in the collection, no HybridStorage; every table of a collection sets it or none does. - Tests under test/unit_tests/per_key_score, one entry in unit_test.sh; docs in DynamicEmb_APIs.md and README.md. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…eded in eval, more tests - A negative score warns under safe_check_mode WARNING and raises under ERROR; all-IGNORE tables are not checked. - Evaluation reads no score: a collection that takes a score per key accepts an input without scores while not training, and sends the scores only when the input carries them. - Tests: host-only storage (generic path), (NO_EVICTION, CUSTOMIZED), an input whose features are not in the tables' order, dump then load, evaluation without scores, negative scores under WARNING / ERROR. - Docs follow. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The kernels that read the scores in prefetch are queued on the current stream and can run after the caller has released them; a caller that made them on another stream would see the memory reused underneath those kernels. Record them on the current stream on every prefetch call. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…es them Evaluation may go without scores, but the dedup before the all2all called scores() whenever the collection takes a score per key, so an unscored evaluation input failed with use_index_dedup. Merge scores only from an input that is a ScoredKeyedJaggedTensor; test unscored evaluation with dedup enabled. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Whether the input distribution sends the scores followed each rank's own input type, so ranks given different kinds of evaluation input issued different collectives and could hang. Evaluation reads no score: a collection that takes a score per key now drops them from the input before distribution, on every rank, and sends none. Test an evaluation where ranks are given different kinds of input. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…y.PRECISE_CUSTOMIZED Replace the per_key_score table option by a score strategy of its own: PRECISE_CUSTOMIZED, alone or as (NO_EVICTION, PRECISE_CUSTOMIZED). The input must be a ScoredKeyedJaggedTensor while training. It is stored like CUSTOMIZED (same policy and score name); what differs is where a score comes from. - takes_score_per_key() / DynamicEmbTableOptions.takes_score_per_key replace the field; the strategy is already part of the group key, and combining it with LFU, TIMESTAMP or CUSTOMIZED is refused by the compound-strategy check. admit_strategy is still refused. - HybridStorage is refused before it is built, instead of after. - Tests and docs follow; a test that HybridStorage is refused is added. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
TrainPipelineSparseDist replaces each input_dist._dist.forward with KJTAllToAllForward, which returns KJTSplitsAllToAllMeta (the metadata of a splits all2all the pipeline fuses across modules), not an awaitable. _ScoredSplitsAwaitable then called wait() on it and failed, and the fused path rebuilds the keys' tensors awaitable itself, so it has no channel for per-key scores. Refuse it for now: RwSparseFeaturesDist.forward raises NotImplementedError when it has scores to send and the keys' distribution is the fused metadata. Evaluation sends no scores and is not affected. Tests: check_train_pipeline_is_refused swaps in KJTAllToAllForward as the pipeline does and checks training raises and evaluation does not. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…when given _generic_forward_path passed key_scores to every Storage.find, None included. With caching=False and no HBM budget for values, an external_storage is the only tier and is called there directly; one written against the interface from before per-key scores (PyDictStorage) has no such parameter, so an ordinary training forward raised TypeError. - Pass the keyword only when per-key scores are supplied. - Refuse score_strategy PRECISE_CUSTOMIZED with an external_storage that is the only tier, when the tables are built. Tests: check_external_storage_alone_is_refused. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
jiashuy
force-pushed
the
feat/dynamicemb-per-key-score
branch
from
November 3, 2026 01:35
a3e04f2 to
1669375
Compare
shijieliu
approved these changes
Nov 3, 2026
shijieliu
added a commit
to shijieliu/recsys-examples
that referenced
this pull request
Nov 8, 2026
Merge main up to c6e2bb2 (NVIDIA#514, NVIDIA#530, NVIDIA#532, NVIDIA#498 and three HSTU inference commits). Main's per-key scores and per-sharding frequency counters meet the hierarchical dist in the sharding's Python: - Per-key scores (PRECISE_CUSTOMIZED) travel beside the keys in their own tensor; the hierarchical dist does not carry them. A row-wise EmbeddingCollection whose tables take a score per key raises under output_dist="fused" when it is sharded, and takes TorchRec's dists with the usual warning under "auto". - Frequency counters are decided per sharding. The hierarchical path reads its sharding's entry and gives the op weights exactly when _dedup_indices attaches them. - A rank with no keys for a sharding that counts frequencies sends an empty weights tensor, so every rank sends the same tensors (on main the ranks' all2alls could differ there). - GroupedEmbeddingsLookup keeps one prefetch, which passes index dedup's frequency counters and now main's scores; LFU scores and admission counts under a prefetch pipeline then match the plain loop on TorchRec's dists too. BatchedDynamicEmbedding.prefetch, which nothing calls, goes. PrefetchState.record_stream also records the unique scores. - unique_op.cu: main's reduce and the shared chain insert merge cleanly. test_hier_dist.py checks the per-key-score rule under "fused" and "auto", and LFU with no keys on the last rank. The tests of both sides pass on 1 and 2 nodes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks done
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
Per-key int64 score input for EmbeddingCollection / EmbeddingBagCollection
Summary
Add a per-key int64 score input to DynamicEmb's
EmbeddingCollection(EC) andEmbeddingBagCollection(EBC). The caller supplies one score per key, and the score decides which rows the table evicts. The feature is exposed as a new score strategy,DynamicEmbScoreStrategy.PRECISE_CUSTOMIZED, and the input is aScoredKeyedJaggedTensor.Scores travel on their own channel and are kept separate from the LFU frequency counters. A table uses either frequencies (LFU) or per-key scores (
PRECISE_CUSTOMIZED), never both, and a single function (score_source) chooses between them on every path.The PR has 8 commits: two preparatory ones, the feature, three fixes found in review, and one refactor.
Motivation
Existing strategies (TIMESTAMP, STEP, LFU, CUSTOMIZED) derive the score from the table itself: access time, step, hit count or one scalar per call. Some models know better which rows matter, for example a business weight or a user tier per key.
PRECISE_CUSTOMIZEDlets the caller state that importance for each key instead of one value for the whole batch.Usage
A repeated key in one batch keeps the largest of its scores (MAX). A later batch assigns the new score to the key.
Changes
Preparation
446536b)block_bucketize_sparse_featuresaccepts int64 weights next to float32. The kernel only copies each weight to its new position, so both are bit-exact.segmented_unique_cudagets areduceargument ("sum"by default,"max","min") for combining the values of a repeated key. It also checks thatinput_frequenciesis int64, on the keys' device and contiguous. Any other dtype used to be misread silently.63e021b)ShardedDynamicEmbeddingCollectiontookis_lfu_enabledandhas_admit_strategyfrom the first table only. A collection whose first table was not LFU gathered no frequencies for the LFU tables after it, and one whose first table was LFU handed frequencies to tables that never asked for them.collect_frequency_requirements), andctx.frequency_countershas one entry per sharding.BatchedDynamicEmbeddingTablesV2keeps counters only if its group evicts by LFU or admits.Feature
ScoredKeyedJaggedTensor(scored_kjt.py) is a KJT with a per-key int64_scorestensor.from_kjt,get_scores,without_scores, split, permute,toandrecord_streamall keep the scores.dynamicemb_config.py)PRECISE_CUSTOMIZED = 5.(NO_EVICTION, PRECISE_CUSTOMIZED)among compound strategies.DynamicEmbTableOptions.takes_score_per_keyreports whether a table uses it. Combining it withadmit_strategyraisesValueError.shard/input_dist.py,shard/rw_sharding.py)_ScoredSplitsAwaitable) and permuted with the keys.shard/embedding.py): when index dedup is on, scores of duplicate keys are merged withlargest_score_per_unique_key(ascatter_reduce_amax).key_value_table.py,batched_dynamicemb_function.py,batched_dynamicemb_tables.py)score_source(state, frequency, key_scores)is the single place that picks the score input: LFU gets the frequency, CUSTOMIZED and PRECISE_CUSTOMIZED get the key scores, anything else gets none.get_find_score_arg/_find_keys, the cache lookup and load path, and the three prefetch paths (cache + storage, HBM direct, generic). The publicStorage.findsignature is unchanged.flagged_compacttogether with the keys.preserve_existing=Trueso it does not overwrite a stored score.BatchedDynamicEmbeddingTablesV2._check_scores)DynamicEmbCheckMode: ERROR raises, WARNING warns, IGNORE skips the check.set_scorerejects per-key tables, and scores arerecord_stream'd on the prefetch stream.Fixes made during review
aa8cdff): the scores tensor could be reused by the allocator while the prefetch stream was still reading it.2df92aa): evaluating a plain KJT with dedup enabled calledscores()on a non-scored input and failed.36d4fd2): if some ranks passed scores and others did not, the ranks entered different collectives and the job hung. In eval every rank now drops the scores withwithout_scores.Refactor
DynamicEmbScoreStrategy.PRECISE_CUSTOMIZED(50299d6): the first version used a separateper_key_scoretable option. It is replaced by the new strategy, andper_key_scoreis removed (no deprecation path, the option never shipped). The Hybrid-storage rejection is moved to the place that creates the storage.Restrictions
The PR refuses a configuration with a clear error instead of working around it:
HybridStorageis not supported (NotImplementedError), because it has no need for scores for now.admit_strategy, and no compound with LFU, TIMESTAMP or CUSTOMIZED.PRECISE_CUSTOMIZEDor none do, and the collection must hold only DynamicEmb tables.ScoredKeyedJaggedTensor. Evaluation does not need scores, and they are dropped.Tests
New tests are registered in
test/unit_test.sh:test/unit_tests/per_key_score/test_per_key_score.shruns, in one script:test_scored_kjt.py,test_scored_bucketize.pyandtest_per_key_score_options.py(76 cases);torchrunoftest_per_key_score_dist.py, which covers input dist with and without dedup, EC scores under default, dedup, caching, host-only,(NO_EVICTION, PRECISE_CUSTOMIZED)and reverse-order inputs, dump/load, evaluation without scores (including ranks with mixed inputs), negative scores, EBC pooled scores, and the Hybrid refusal.test_int64_weights_channel.pyand the reduce / dtype cases intest_unique_op.py.test_frequency_requirements.py,test_frequency_counter_guard.pyand a mixed LFU/TIMESTAMP collection intest_lfu_scores.py(test_lfu_scores.shis new).Results on
50299d6, freshly synced and rebuilt on an 8×H100 EOS node:unit_test.sh fwd_bwd: 26 test files, 0 failures. This includes per-key score (76 pytest cases and "per-key score distributed ok") and TWRW ("all modes passed").unit_test.sh load_dump: 5 test files, 0 failures. This covers admission, 72 dump runs, hash_roundrobin, table scope, 144 cross-GPU loads, incremental dump and table_row_wise.Docs
DynamicEmb_APIs.md:PRECISE_CUSTOMIZEDadded to the strategy listing, plus a new "Per-key score" section covering usage, MAX merging and the restrictions.README.md: usage note on feeding scores.Compatibility
Storage.findis internal: its signature is the same.63e021b) changes behavior only for collections that mix LFU and non-LFU tables. Before the fix those collections were wrong.block_bucketize_sparse_featuresandsegmented_unique_cudakeep their float32 and sum defaults.unique_op.cu, bucketize) need the extension to be rebuilt.Checklist