Repository navigation
feat(dynamicemb): hash_bucket dist_type with a fan-out-invariant global bucket layout - #533
tiankongdeguiji wants to merge 4 commits into
Conversation
[Medium impact] The change affects DynamicEmb table placement, routing, checkpoint loading, and replay. Fix the first-table buffer placement before merging; it can allocate values on host memory that the planner did not reserve. SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Sum fused tables' sizes and HBM budgets] --> B{Values fit HBM budget?}
B -->|Yes| C[Select HBM_ONLY]
C --> D[Pass original options to create_table_state]
D --> E{First table's budget is zero?}
E -->|Yes| F[Allocate every value buffer on host]
E -->|No| G[Allocate value buffers on GPU]
Reviews (5) · Last reviewed commit: "revert(dynamicemb): back out the per-tab..." · Reviewed by Greptile |
d51dd5d to
0b66c74
Compare
…al bucket layout A key's home bucket is hash % shard_capacity // bc, so the keys that share a bucket depend on the number of shards: a checkpoint reloaded at another world size re-deals them, full buckets overflow and insert evicts the surplus (1-2 % of the rows of a near-full table on an 8 -> 1 restore). Add dist_type="hash_bucket": the bucket is the global one, (murmur3(key) & INT64_MAX) % global_capacity // bc with global_capacity = ceil(num_embeddings / bc) * bc, and the shard is that bucket's position, g // ceil(G / S). Per-shard capacity is unchanged (ceil(ceil(N/bc)/S) == ceil(ceil(N/S)/bc)); only the sum over shards may exceed the global count by up to S-1 unused buckets. roundrobin, hash_roundrobin and continuous keep their rules and layouts bit for bit. - LinearBucketTable::home_bucket (types.cuh) replaces the six duplicated bucket formulas; a per-table global capacity pointer on the table, 0 = own capacity. The LruLfu cubin ABI gains the pointer (appended). - DistType::kHashedBucket in the routing kernel (hashed_shard) and key_ownership.owning_shard / OwnershipRule apply the rule from per-feature (global_capacity, shard_capacity), carried by the distributors next to the dist-type codes and validated once on the host. - DynamicEmbTableOptions.global_capacity, set by the planner for hash_bucket tables (fanout * max_capacity under MAX_BUCKET_CAPACITY, which has no whole-table form); init_capacity is raised to max_capacity. - Checkpoint meta records global_capacity / bucket_capacity; a matching layout reads only the rank's own shard file, another dist_type (no longer an error) or another layout reads every file, re-filters and warns once. replay_increment checks global_capacity too. - HYBRID stays lossy (phase 2 designed in the doc), as do NO_EVICTION, MAX_BUCKET_CAPACITY, roundrobin and hash_roundrobin tables. Tests: test_global_bucket_layout.py (kernel / routing / host oracle, planner, 8->1, 1->2, 2->1, 8->3 reloads at 97 % fill lose nothing for HBM-only and CACHING tables, roundrobin control loses 1.5 %, roundrobin and hash_roundrobin checkpoints migrate with a warning); kuairand kernel oracle covers all three hash rules; hash_bucket cases in test_embedding_dump_load.sh (incl. 2->1 / 1->2) and test_table_row_wise.sh; replay global_capacity mismatch. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01JoQS7n2bkEWZws9Rddef49
0b66c74 to
06a8e18
Compare
…yout Conflicts (both sides added a keyword argument at the same spot) resolved by keeping both: `global_capacities` / `global_bucket_layout` from this branch beside `use_ref_counter` from NVIDIA#532 in create_table_state, get_scored_table, LinearBucketTable.__init__, _expand_tables_impl and the HybridStorage tiers; the `table_insert*_single_score` helpers take NVIDIA#532's optional counter and this branch's global capacity pointer. Rebuilt and re-ran on the merged tree: test_global_bucket_layout (31), kuairand (17), replay (36), planner, no_eviction (24), table_rows, expansion, ref counters, table_operation, the erase_async suite (143) incl. the distributed case, and multi-GPU hash_bucket / hash_roundrobin / roundrobin dump-load. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01JoQS7n2bkEWZws9Rddef49
- lookup_torch_binding.cu: the forward declaration repeated the defaults table.cuh already gives (redefinition of default argument), which broke the CMake inference_emb_ops build; drop them from the declaration. - lookup_meta: _table_lookup_fake takes table_global_capacities, matching the op schema the dispatcher hands fake kernels. - Routing kernel (kHashedBucket): sign-extend the key before hashing. An int32 key arrived as the kernel's unsigned index and was zero-extended, while the table and owning_shard hash the int64 key -- half of the negative int32 keys were routed to a rank other than the one a reload would keep them on. - Load across dist_type: refuse when either side is `continuous` (check_dist_type_migration) -- its keys are shard-local ids that no other rule can re-partition; keep the warning path for roundrobin/hash_roundrobin. - Layout warnings are said once per table (shard 0 in the module path, once per process for a direct Storage.load), not once per shard file per rank (suppress_layout_warnings / _warn_layout_once). - Design doc: drop the lossless-HYBRID follow-up section; HYBRID is out of scope. Tests: routing twins agree for int32 keys with negatives (8 cases); continuous checkpoints are refused on both paths; exactly one layout warning per table on the module path and on a direct storage load; CPU test of the fake kernel's signature. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01JoQS7n2bkEWZws9Rddef49
… (PR NVIDIA#534) b9ca916 unintentionally carried the runtime half of the per-table HBM budget change: those edits were sitting uncommitted in this tree while the hash_bucket review findings were being addressed, and a commit takes whole files. The change is unrelated to hash_bucket and is under review as NVIDIA#534, which also carries the planner-side mirror it needs to stay consistent. This restores _create_cache_storage's shared cap_scale split, create_table_state's options[0] host placement, and the DynamicEmb_APIs.md row, exactly as they were before b9ca916. Co-Authored-By: Claude Code <[email protected]>
Comments Outside DiffThese findings could not be posted inline.
|
|
merged in #566 |
Problem
A key's home bucket in a DynamicEmb table is
hash % shard_capacity // bucket_capacity, so the set of keys sharing a bucket depends on the number of shards. Reloading a checkpoint at another world size re-deals them: buckets that were full at 8 ranks overflow at 1, andinsertevicts the surplus (or drops the key asBusy). On a real 8-rank checkpoint folded onto 1 GPU this lost 1.3–2.0 % of the rows of every in-memory table (2.3 % synthetic for CACHING atbucket_capacity=128), while external storage restored exactly.Change
A new
dist_type="hash_bucket". The existingroundrobin,hash_roundrobinandcontinuousrules and layouts are untouched (bit-identical kernels, routing, checkpoints and tests); this PR is purely additive.Under
hash_bucketthe bucket is global and the shard is derived from it:Per-shard capacity is unchanged (
ceil(ceil(N/bc)/S) == ceil(ceil(N/S)/bc)), so memory andmax_capacitystay the same; only the sum over shards may exceedGby up toS-1unused buckets.LinearBucketTable::home_bucket(types.cuh) replaces the six duplicated bucket formulas (lookup / insert / insert_and_evict / erase / scatter_keys_at_slots / bucketize); a per-tableglobal_capacitiespointer on the table (0 = own capacity → old formula).EvictParamsgains the pointer (appended; cubin + fatbins rebuilt together).DistType::kHashedBucket→hashed_shardin the bucketize kernel, andkey_ownership.owning_shard/OwnershipRuleapply the same rule from per-feature(global_capacity, shard_capacity), carried by the distributors next to the dist-type codes and validated once on the host. Ahash_bucketfeature without them is refused, not routed by another modulus.DynamicEmbTableOptions.global_capacity(get_global_table_capacity), set by the planner forhash_buckettables (fanout * max_capacityunderMAX_BUCKET_CAPACITY, which has no whole-table form);init_capacityis raised tomax_capacity(no rehash). Fused tables keep their own.dist_type,global_capacity,bucket_capacity. A matching layout reads only the rank's own shard file; anotherdist_type(an error before, now a warning;continuousstays an error — its keys are shard-local ids) or another layout reads every file, re-filters by the table's rule and warns once per table — the migration path fromroundrobin/hash_roundrobincheckpoints (one-time lossy fold, lossless ever after).replay_incrementchecksglobal_capacitytoo.DynamicEmbStorage(HBM-only / host-only) and the CACHING storage tier, anyS → S'with the sameNandbc, RW ↔ TRW included. HYBRID is out of scope (a key's tier is decided by eviction history, so its two tiers are not a fixed partition of the keys; its layout is unchanged), as are NO_EVICTION andMAX_BUCKET_CAPACITYtables.Docs:
docs/global_bucket_layout_design.md,DynamicEmb_APIs.md,README.md.Tests
test/unit_tests/test_global_bucket_layout.py(31 tests): table kernels vs an independent oracle (and old buckets kept when unset); routing kernel / host rule / oracle agree key for key forS ∈ {1,2,3,8}; planner derivation; 8→1, 1→2, 2→1, 8→3 reloads of a 97 %-full table lose 0 rows (HBM-only and CACHING), random-key training survivors reload losslessly, theroundrobincontrol loses 1.5 %;roundrobinandhash_roundrobincheckpoints migrate into ahash_buckettable with a warning; a different recorded layout is read whole.test_hash_roundrobin_kuairand.py(kernel vs a second CPU implementation, per key, for all three hash rules),test_embedding_dump_load.sh(+hash_bucketat 1/2 ranks and 2→1 / 1→2;hash_roundrobincases unchanged),test_table_row_wise.sh(+hash_bucketparity/jagged/grad and RW↔TRW dump/load),test_replay_increment.py(+global_capacitymismatch).test_embedding_dump_load.pyforhash_bucket(1/2 ranks, cross-world) and for unchangedroundrobin/hash_roundrobin. 8-GPU shell variants not run.🤖 Generated with Claude Code
https://claude.ai/code/session_01JoQS7n2bkEWZws9Rddef49