Repository navigation
Relax alignment requirements(remove pow of 2) in dynamicemb - #312
Conversation
Greptile SummaryThis PR replaces the power-of-2 alignment constraint for dynamic embedding table capacities with a lighter Key changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["EmbeddingConfig.num_embeddings"] --> B["math.ceil(num_embeddings / world_size)"]
B --> C["align_to_table_size(n)\n⌈n / 16⌉ × 16"]
C --> D{per-rank capacity\n< bucket_capacity?}
D -- Yes --> E["align_to_table_size(bucket_cap)"]
D -- No --> F["num_aligned_embedding_per_rank"]
E --> F
F --> G["DynamicEmbTableOptions.max_capacity"]
H["global_hbm_for_values"] --> I["ceil(global_hbm / world_size)\n= local_hbm_for_values"]
I --> J{local_hbm\n< 1 bucket?}
J -- Yes --> K["Warn + round up to\nbucket_size_in_bytes"]
J -- No --> L["get_constraint_capacity()\n= floor(capacity/bucket_cap) × bucket_cap"]
K --> L
G --> M["Hash Table Capacity\n(multiple of 16)"]
L --> N["Cache HBM Capacity\n(multiple of bucket_cap)"]
|
ef6726b to
704460b
Compare
c3bb4f0 to
9a8e88c
Compare
…LE_ALIGN_SIZE PR NVIDIA#312 introduced `align_to_table_size` which rounds capacity up to multiples of DEMB_TABLE_ALIGN_SIZE (16). However the C++ hash table internally rounds capacity to multiples of `bucket_capacity` (default 128). When `num_embeddings / world_size` is already a multiple of 16 but not 128, `_validate_configs` skipped setting `num_aligned_embedding_per_rank`, causing `max_capacity` to be unaligned. During `expand()`, value tables were allocated with the unaligned `max_capacity` while the hash table could return indices up to its actual (larger) capacity, leading to out-of-bounds CUDA memory access. Changes: - `align_to_table_size` now accepts an `alignment` parameter (default unchanged for backward compatibility). - `_validate_configs` always sets `num_aligned_embedding_per_rank` and aligns to `bucket_capacity`. - `_dyn_emb_table_size_per_rank` takes `bucket_capacity` for alignment. - `expand()` uses `key_index_map.capacity()` for value table allocation to match the actual hash table capacity. - Updated unit tests to reflect bucket_capacity-based alignment. Fixes NVIDIA#328 Made-with: Cursor
…LE_ALIGN_SIZE (#329) * fix: align DynamicEmb capacity to bucket_capacity instead of DEMB_TABLE_ALIGN_SIZE PR #312 introduced `align_to_table_size` which rounds capacity up to multiples of DEMB_TABLE_ALIGN_SIZE (16). However the C++ hash table internally rounds capacity to multiples of `bucket_capacity` (default 128). When `num_embeddings / world_size` is already a multiple of 16 but not 128, `_validate_configs` skipped setting `num_aligned_embedding_per_rank`, causing `max_capacity` to be unaligned. During `expand()`, value tables were allocated with the unaligned `max_capacity` while the hash table could return indices up to its actual (larger) capacity, leading to out-of-bounds CUDA memory access. Changes: - `align_to_table_size` now accepts an `alignment` parameter (default unchanged for backward compatibility). - `_validate_configs` always sets `num_aligned_embedding_per_rank` and aligns to `bucket_capacity`. - `_dyn_emb_table_size_per_rank` takes `bucket_capacity` for alignment. - `expand()` uses `key_index_map.capacity()` for value table allocation to match the actual hash table capacity. - Updated unit tests to reflect bucket_capacity-based alignment. Fixes #328 Made-with: Cursor * style: remove unreachable bucket_cap guard in _validate_configs align_to_table_size(n, alignment=bucket_cap) always returns >= bucket_cap for positive n, so the floor check is dead code. Made-with: Cursor * fix: align max_capacity to bucket_capacity in DynamicEmbTableOptions.__post_init__ Without this, a misaligned max_capacity causes the expand() early-exit guard (self._capacity == self.options.max_capacity) to never fire, since the C++ hash table silently rounds capacity up to bucket_capacity. Made-with: Cursor
…of-2 Adapt to upstream dynamicemb PR (NVIDIA/recsys-examples#312) which relaxes table capacity alignment from power-of-2 to multiples of DEMB_TABLE_ALIGN_SIZE (16), reducing memory waste. Replace local _next_power_of_2 with the new align_to_table_size API and update wheel to 0.0.1+20260331.bea6b4b. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Description
Checklist