Repository navigation
Conversation
With use_index_dedup=True, ShardedDynamicEmbeddingCollection._dedup_indices
hands the KJT values to segmented_unique_cuda, which takes int64 and uint64
keys only. int32 keys raise "Unsupported key dtype: must be int64 or uint64"
on the first forward. Without index dedup they work.
Extend the index dedup tests with int32 keys:
- test_twin_module: int32 keys on the sequence collection, with and without
index dedup. The DynamicEmb model reads int32 keys, and its outputs over
10 training iterations must match the TorchRec model, which reads the same
keys as int64. This checks the forward, the gradients and the table
updates. The key dtype joins the (is_pooled, pooling_mode, max_bag_size)
parameter, so the pooled collection, which has no index dedup, gets no
int32 items.
- test_sequence_embedding_fw (--key_dtype int32), run by
test_sequence_embedding.sh on 2 and 8 GPUs: each batch is also looked up
as int32 keys. The embeddings must equal the int64 lookup's, and each
row of a DynamicEmb table must hold the DEBUG initializer's value,
key % 100000. That is the value the lookup returns without index dedup,
and the check does not depend on the dedup of int64 keys, which the int64
lookup and the twin reference also use. The last batch leaves rank 0
without keys, so the empty branch of the dedup runs next to ranks that
dedup int32 keys.
- test_lfu_scores (--key-dtype int32), run by test_lfu_scores.sh on 1 and 8
GPUs: the LFU score of an int32 key must equal its true access count, with
and without index dedup, with and without a cache.
- test_embedding_admission: cases int32-keys-{hbm-direct,hybrid,cache} on 1
and 8 GPUs, which count admission frequency through the dedup. The cache
case uses a threshold of 2: its keys spread over 8000 values per table,
where a threshold of 4 admits one key of all 8 tables and 2 admits 365.
- validate_admission_keys checks both directions, for every case: each key
in a table reached the threshold, and each key a rank owns that reached
the threshold is in its table.
test_sequence_embedding_bw is not extended: it drives
BatchedDynamicEmbeddingTablesV2 directly, whose forward casts the keys to
index_type and never reaches _dedup_indices. Nor is
test_multi_embedding_collection_fw: each of its collections takes the same
_dedup_indices path as test_sequence_embedding_fw.
On main (d0dbc08), on one 8-GPU H100 node, every int32 run with index dedup
fails with that error, raised at the segmented_unique_cuda call in
_dedup_indices: the 12 int32 test_twin_module items with index dedup at 1
GPU and at 8 GPUs (12 failed, 69 passed, 64 skipped), both
test_sequence_embedding_fw runs (2 and 8 GPUs), the 4 LFU runs and the 6
admission cases. The int32 runs without index dedup pass: the other 12 twin
items, the 2-GPU forward run with its DEBUG value check, and the 4 LFU
runs. All 70 int64 admission cases pass the two-sided check.
Two broken versions of the next commit's fix show what the new checks
catch. Frequency counters of 1 for int32 keys fail all 6 int32 admission
cases, each with keys that reached the threshold and were not admitted.
Reverse indices shifted by one fail test_sequence_embedding_fw on the DEBUG
value check at the first batch, while its int32 and int64 lookups agree.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
With use_index_dedup=True, ShardedDynamicEmbeddingCollection._dedup_indices passes the KJT values to segmented_unique_cuda as they come. The kernel takes int64 and uint64 keys only, so int32 keys raise "Unsupported key dtype: must be int64 or uint64" on the first forward. Without index dedup int32 keys work, because the lookup widens them to int64 (features.values().long()). _dedup_indices widens int32 keys to int64 for segmented_unique_cuda and returns the unique keys in the input dtype. So: - the dedup compares the same 64-bit keys the tables store, made by the same sign extension as in the lookup; - the bucketize, the input all-to-all and the lookup see the dtype they see without index dedup; - a rank with empty input, which passes its keys on unchanged, sends the same dtype as the ranks that dedup. The reverse indices and the LFU and admission frequency counters do not depend on the key dtype. int64 and uint64 keys are not copied: they reach segmented_unique_cuda as they are, and .to() returns the same tensor. Why not int32 support inside segmented_unique_cuda: it would add kernel instantiations for this one caller, since the lookup's own dedup (batched_dynamicemb_function.segmented_unique) only sees index_type keys. Widening in Python keeps the kernel's key types the same as the tables'. The cost is two copies, small next to the dedup and the all-to-all: the int32 keys widened to int64, and the unique keys narrowed back to int32. Tests, on one 8-GPU H100 node (CI image 26.07, TorchRec 1.8.0): - The int32 runs added by the previous commit all pass: 24 test_twin_module items at 1 GPU and at 8 GPUs, 3 test_sequence_embedding_fw runs, 8 LFU runs and 6 admission cases. Without this fix those with index dedup fail with the error above: 12 twin items at each GPU count, 2 forward runs, 4 LFU runs and 6 admission cases. - Related suites with the previous commit's tests, main -> this branch: test_twin_module.sh 12 failed, 69 passed, 64 skipped -> 81 passed, 64 skipped, at 1 GPU and at 8 GPUs; test_sequence_embedding.sh 19/21 -> 21/21 runs pass; test_pooled_embedding.sh 11/11 -> 11/11; test_lfu_scores.sh 56/60 -> 60/60; test_embedding_admission.sh 13 passed and 70/76 runs -> 13 passed and 76/76 runs. On main only the int32 runs with index dedup fail; on this branch nothing fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say in the DynamicEmbeddingCollectionSharder section what use_index_dedup does and which key dtypes it takes: int32 and int64, with int32 keys deduplicated as int64 and passed on as int32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks done
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryFixes int32 keys with
No actionable issues were found. GPU tests were not run during this review. Reviews (1) · Last reviewed commit: "docs(dynamicemb): int32 keys under index..." · Reviewed by Greptile |
3 tasks done
Collaborator
|
closed as merged in #544 |
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
With
use_index_dedup=True, a sharded DynamicEmb embedding collection fails on its first forward when its keys are int32. The user seesValueError: Unsupported key dtype: must be int64 or uint64. The same int32 keys work without index dedup.The index dedup (
_dedup_indices) passes the keys tosegmented_unique_cudaas they come, and that kernel takes int64 and uint64 keys only. Without index dedup, the lookup widens the keys to int64 first, so the kernel never sees int32 keys.Fix:
_dedup_indiceswidens int32 keys to int64 forsegmented_unique_cuda, the same widening the lookup does, and returns the unique keys as int32. The input all-to-all and the lookup see the same dtype as without index dedup, also on a rank with no keys. int64 and uint64 keys are not copied. The docs say which key dtypesuse_index_deduptakes.Tests:
test_twin_module.sh81 passed, 64 skipped (1 and 8 GPUs),test_sequence_embedding.sh21/21,test_pooled_embedding.sh11/11,test_lfu_scores.sh60/60,test_embedding_admission.sh13 passed and 76/76.Checklist
🤖 Generated with Claude Code