Repository navigation
Fix empty batch hang fundamentally - #349
Conversation
Greptile SummaryThis PR fixes a distributed hang caused by a dtype mismatch in Confidence Score: 5/5Safe to merge — the dtype fix is correct and the previous review concern about empty-batch lengths casting has been addressed. Both the CUDA kernel change and the Python empty-batch early-exit are consistent and correct. The only remaining finding is a P2 style issue (missing torch.no_grad() around a test forward pass) that does not affect correctness or reliability. No files require special attention.
|
| Filename | Overview |
|---|---|
| corelib/dynamicemb/src/unique_op.cu | Root-cause fix: changes new_lengths tensor dtype from at::kInt (int32) to at::kLong (int64) in both the empty-case early-return and the general allocation path, and updates the DataType dispatch argument passed to get_new_length_and_offsets accordingly. Consistent and correct. |
| corelib/dynamicemb/dynamicemb/shard/embedding.py | Adds an early-return for the empty-batch case (num_elements == 0) that produces a KeyedJaggedTensor with lengths cast to torch.int64, preventing dtype mismatch with the non-empty path when distributed ranks have uneven batches. .to(torch.int64) on lengths aligns with the offsets cast already present. |
| corelib/dynamicemb/test/unit_tests/test_sequence_embedding_fw.py | Adds an extra iteration after num_iterations that gives rank 0 an empty KeyedJaggedTensor (all-zero lengths, no values) while other ranks get normal non-empty features, directly reproducing the multi-rank hang scenario from issue #341. |
| corelib/dynamicemb/test/test_batched_dynamic_embedding_tables_v2.py | Adds a single-rank "all keys missed in eval" corner-case forward pass; minor style issue — the new call runs outside torch.no_grad() while the model is still in eval mode. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[input_feature_splits loop] --> B{num_elements == 0?}
B -- Yes --> C[Build KJT with lengths cast to int64]
C --> D[Append empty reverse_indices int64]
D --> E[features_by_shards.append\ncontinue]
B -- No --> F[expand_table_ids_cuda]
F --> G[segmented_unique_cuda]
G --> H[compute_dedup_lengths_cuda]
H --> I{new_lengths_size == 0?}
I -- Yes --> J[Return empty int64 lengths\nzero int64 offsets]
I -- No --> K[Allocate new_lengths as int64\nAllocate new_offsets as int64]
K --> L[get_new_length_and_offsets\nDataType::Int64 + DataType::Int64]
L --> M[Return new_lengths int64\nnew_offsets int64]
J --> N[Build KJT with int64 lengths]
M --> N
N --> E
Reviews (2): Last reviewed commit: "Cast lengths to int64 explictly in dedup..." | Re-trigger Greptile
Description
There is an issue when fed empty batch to the DMP model on a single rank while other rank's batch are not empty.
It was fixed previously, and this PR provides:
dedup_features.lengths: hang issue is because the data type mismatched due to different code path.Checklist