Repository navigation
fix(dynamicemb): send frequency weights for an empty input under index dedup - #527
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThe PR keeps frequency weights present when a rank has no keys under index dedup.
No actionable issues were found. This was a source review; GPU tests were not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Input for each sharding] --> B{Needs frequency counts?}
B -->|No| C[Append None]
B -->|Yes| D{Has keys?}
D -->|Yes| E[Append counts for unique keys]
D -->|No| F[Append an empty counter tensor]
C --> G[Read this sharding's counter entry]
E --> G
F --> G
G --> H[Attach weights when the entry is not None]
H --> I[Distribute keys and weights]
Reviews (3) · Last reviewed commit: "Merge branch 'main' into fix/index-dedup..." · Reviewed by Greptile |
f1614a1 to
31ef5f0
Compare
…ssion With use_index_dedup=True and an LFU score or an admission strategy, each rank sends how often each deduplicated key occurs, as the weights of the KJT of each sharding. But _dedup_indices adds no counters for a sharding whose input on this rank is empty, and input_dist gives entry i of ctx.frequency_counters to sharding i only when the list is long enough. So: 1. A rank with no keys sends its KJT without weights, while the other ranks send weights. The job hangs in TorchRec's KJT all-to-all. 2. In a collection with two shardings, when the first one is empty on a rank, the first gets the counters of the second, and the second gets none. If other ranks send weights, the job hangs as in 1. If the first sharding is empty on every rank, nothing hangs, but no rank sends counters for the second one, and the LFU scores of its tables fall short of the access counts. Case 2 happens when a TorchRec table sharded data parallel (named in get_planner's data_parallel_embedding_table_names) comes before the DynamicEmb tables of a collection: the shardings come in the order in which the tables first use them. The tests: - test_lfu_scores and test_embedding_admission get --empty-rank-iteration: at that iteration, rank 0 has no keys. - test_lfu_scores gets --data-parallel-table: each collection gets a data-parallel TorchRec table first, with no keys on rank 0. create_model in test_embedding_dump_load gets data_parallel_table for it. - test_lfu_scores.sh gets three runs, all with index dedup: rank 0 empty at iteration 1 on 8 GPUs, and the data-parallel table on 1 GPU and on 8 GPUs. On 1 GPU that sharding is empty on every rank. - test_embedding_admission.py gets the case empty-rank: rank 0 empty at iteration 1 on 8 GPUs, with the timestamp score, so that only admission turns the counters on (test_lfu_scores covers LFU). The checks stay as they are: every LFU score equals the access count, and no key below the threshold is admitted. On main (d0dbc08), on one 8-GPU H100 node (CI image 26.07, TorchRec 1.8.0), each run under a 300 s shell timeout: - The three 8-GPU runs hang in TorchRec's KJT all-to-all. The timeout kills them at 300 s. - The 1-GPU run fails its check: "Table embedding_collection_0_0, Key 35: Expected frequency: 7, Actual score: 5". Co-Authored-By: Claude Opus 5.5 <[email protected]>
…x dedup With use_index_dedup=True and an LFU score or an admission strategy, each rank sends how often each deduplicated key occurs, as the weights of the KJT of each sharding. _dedup_indices added no counters for a sharding whose input on this rank is empty, and input_dist gave entry i of ctx.frequency_counters to sharding i only when the list was long enough. A rank with no keys for a sharding then sent that KJT without weights, while the other ranks sent weights, and the job hung in TorchRec's KJT all-to-all. In a collection with two shardings, an empty first sharding also shifted the counters: the first got those of the second, and the second got none. Now, for an empty input, _dedup_indices appends an empty counter tensor (uint64, on the module's device, like the others). With LFU or admission, ctx.frequency_counters then has one entry per sharding, in sharding order, and input_dist gives entry i to sharding i without the length check. Every rank sends weights for every sharding, and empty weights for an empty input: KJTAllToAll sends the weights of a KJT whenever they are not None, empty ones too. When no input is empty, the weights are the same tensors as before. The comment in create_context said it pre-allocates frequency_counters to "ensure all ranks have the same structure", but both of its branches gave an empty list. create_context now makes the context with empty lists, and its comment says that _dedup_indices fills frequency_counters. Remove the commented-out copy of create_context. On one 8-GPU H100 node (CI image 26.07, TorchRec 1.8.0): - The four runs added by the previous commit pass. - test_lfu_scores.sh: 55/55 runs pass. On main, 52/52 pass; the three more are the new runs. - test_embedding_admission.sh: 13 tests and 71/71 runs pass. On main, 13 tests and 70/70 runs pass; the one more is the new case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say in the DynamicEmbeddingCollectionSharder section that with index dedup and LFU or admission each rank sends how often each deduplicated key occurs, as the KJT weights. Co-Authored-By: Claude Opus 5.5 <[email protected]>
31ef5f0 to
5706694
Compare
|
Rebased onto the latest main (aa0556a, includes #534) and force-pushed; head is now 5706694. Note on the rebase: #530 already made Tested on 8x H100 (EOS) with the wheel built from this head:
Not run: test_embedding_dump_load.sh, and the rest of the admission suite beyond |
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]>
Description
With
use_index_dedup=Trueand an LFU score or an admission strategy, each rank sends how often each deduplicated key occurs, as the KJT weights. A rank with no keys for a sharding sends that KJT without weights, while the other ranks send weights. The job then hangs in TorchRec's KJT all-to-all. When the first of two shardings is empty on every rank (for example, a data-parallel TorchRec table, declared first, that gets no keys), nothing hangs, but the LFU scores fall short of the access counts._dedup_indicesadds no counters for an empty input (its empty branch came with #349), andinput_distgives entry i ofctx.frequency_countersto sharding i only when the list is long enough. So an empty input gets no weights, and an empty first sharding takes the counters of the second.Fix:
_dedup_indicesappends an empty counter tensor. The list then has one entry per sharding, in sharding order.input_distgives entry i to sharding i without the length check. Every rank sends weights for every sharding.create_contextis cleaned up, andDynamicEmb_APIs.mdsays how the counts are sent.Tests:
--empty-rank-iteration), or add a data-parallel table first, with no keys on rank 0 (--data-parallel-table). Four new runs, all with index dedup: LFU with an empty rank (8 GPUs), LFU with the data-parallel table (1 and 8 GPUs), and the admission caseempty-rank(8 GPUs).Table embedding_collection_0_0, Key 35: Expected frequency: 7, Actual score: 5.test_lfu_scores.sh: 55/55 runs pass (on main, 52/52).test_embedding_admission.sh: 13 tests and 71/71 runs pass (on main, 13 tests and 70/70).Note: this PR and #525 both add runs to
test_embedding_admission.sh, and they conflict only in its run-count comment. Whichever lands second needs a rebase there.Checklist
🤖 Generated with Claude Code