Repository navigation
[FEA](DynamicEmb) Add the hash_bucket dist_type with a fan-out-invariant global bucket layout - #566
Merged
Merged
Conversation
…ant global bucket layout A key's home bucket is derived from the whole table's capacity instead of the shard's, so the keys that share a bucket do not depend on the fan-out and a checkpoint reloads at another world size without a bucket overflowing. See corelib/dynamicemb/docs/global_bucket_layout_design.md. Rebased onto main (hierarchical dist, int32-as-int64 keys, checkpoint_io split); hash_bucket is refused by the hierarchical dist. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…or hash_bucket test_multi_table_load_dist_type_mismatch now expects the warn-and-repartition behaviour, and owns_key takes num_embeddings optionally (required only for hash_bucket). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…hical output dist The hierarchical dist refuses a hash_bucket table, so the hier_load_dump group (DYNAMICEMB_TEST_OUTPUT_DIST=hierarchical) must not run that section of test_embedding_dump_load.sh. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…rop the checkpoint's name from the design doc DynamicEmb_APIs.md: a hash_bucket table is allocated at max_capacity up front, init_capacity is raised to it, and expanding it in place raises; a table of another size is a different layout, loaded through the migration path. global_bucket_layout_design.md: describe the measured checkpoint as a real production one, without naming it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…and the bucketizer LinearBucketTable::home_bucket and the bucketizer's BucketizeFunctor each wrote the global-bucket arithmetic by hand; both now call the free function home_bucket_of (types.cuh). The hash_bucket route reads its key through stored_key() like the other dist_types. home_bucket's comment now states that *bucket_id is written only when the table has buckets. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ay the host rule does, and refuse a plan made for another fan-out The route took its shard capacity from the table's max_capacity while the host rule (checkpoint load, replay) recomputed it from global_capacity, bucket_capacity and the shard count; a plan made for one fan-out and run at another made them disagree silently. routing_param_tensors now derives it with hashed_shard_capacity and raises when it differs from max_capacity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…dist_type is not continuous With positions the kernel places keys by row range and never reads the feature's dist_type, so a roundrobin, hash_roundrobin or hash_bucket key was routed by a rule its table does not follow, silently. The distributors pass no positions, so only a caller that asks for them is affected (and pays one host sync). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…pacity and bucket_capacity The twin filtered keys by the hash_bucket rule with a global_capacity it re-derived from the default bucket capacity, so a caller passing another bucket_capacity in dynamicemb_options_kwargs got the keys of a different layout on each rank, silently. It now reads the options the planner gave the table, from the new BatchedDynamicEmbeddingTablesV2.dynamicemb_options property. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ot fan-out invariant With one bucket per shard the global capacity is shards x shard rows, so it changes with the fan-out and a reload at another world size may lose rows; the planner said so only in a comment. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…rams ABI so a stale fatbin fails to load EvictParams gained a trailing table_global_capacities, but a cubin built against the old layout still loads: it ignores the new field and places a hash_bucket table's keys by the old rule. The entry points now end in _abi<DYN_EMB_EVICT_ABI>; an image of another layout lacks them and load_from_image raises, naming the fix (rebuild the extension and the fatbins together). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…eta.py in the fwd_bwd group Neither was registered in unit_test.sh, so no group ran them: the lossless-reload and routing checks of the hash_bucket layout never ran in CI. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e LruLfu policy too The compound (TIMESTAMP, LFU) strategy inserts and evicts in the LruLfu cubin, which has its own copy of the home-bucket arithmetic and takes table_global_capacities through EvictParams. The fold and the training-survivors tests ran on the AoT kernel only; a cubin that ignored the field would not have been caught. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
create_model gave every table one bucket per shard (MAX_BUCKET_CAPACITY), whose global capacity changes with the fan-out, so the hash_bucket runs of test_embedding_dump_load.sh never exercised the fan-out-invariant layout nor the reload without re-partitioning. hash_bucket tables now use the default bucket capacity; owns_key derives the global capacity the way the planner does. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… not lossless across fan-outs The API doc listed HYBRID tiers, MAX_BUCKET_CAPACITY and NO_EVICTION tables as "excluded", which reads as refused; the code accepts them, routes their keys by the global rule, and only withholds the fan-out guarantee. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…fan-out A HYBRID table is accepted under hash_bucket but no test built one. HybridStorage.load reads the key -> rank rule from its host tier's options, since the HBM tier's copy rescaled bucket_capacity; the round trip checks every shard gets exactly its keys back. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…cket rule The op's bucketize computed an owner from the key and world_size alone, which is why it refused hash_bucket. hash_bucket keeps the key and needs two numbers per feature, the rows of its table and of one shard; they now travel with dist_types (OwnerRules, Config::global_capacities / shard_capacities, HierDist.setup) and owner_of gains the rule: (murmur3_fmix64(key) & INT64_MAX) % global_capacity / shard_capacity, the key read as the int64 it is. Config::validate refuses a hash_bucket feature without positive capacities, with capacities that name more ranks than the sharding has, or whose table's features differ. The input distributor passes the capacities it validated. Tests: the bucketize hook against DynamicEmb's own bucketize for hash_bucket (int64 and int32 keys, the edges, all three rules in one sharding), the configuration refusals, two model-level cases, and test_embedding_dump_load.sh now runs hash_bucket in the hier group. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… test The two edge-key cases ran the same arithmetic as the random negative-key case on more values, for every world size and sort path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The mixed case (hash_bucket and roundrobin tables) covers the pure one and a rule dispatch besides; each case builds a model on 8 GPUs. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d grow The planner raised init_capacity to max_capacity, create_table_state refused a smaller one and _expand_tables_impl refused to grow, on the ground that the global bucket map is only realised with max_capacity / bucket_capacity buckets. The map does not depend on the table's size, though: keys reach a rank by it (g // P, from global_capacity), and the table already folds it into the buckets it has (home_bucket_of: g % num_buckets). More buckets split the old ones, so growing keeps every key on its rank and the re-insert only moves it within the rank, as for roundrobin; the expansion already passes the global capacities on. At num_buckets == P the fold is the identity, the layout the lossless reload promises. Tests: the planner keeps a small init_capacity; a table starting at 1/32 grows, keeps and finds its keys; a checkpoint of grown tables reloads losslessly at another fan-out. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… and P buckets A table with a global capacity folds the whole table's bucket map into the buckets it has (g % num_buckets). Where num_buckets does not divide the shard's P, the first P mod num_buckets buckets hold one global bucket more; between P/2 and P that is two against one, and at load factor 0.5 the doubled buckets at the front are full and evict. get_expand_info now grows such a table straight to max_capacity once its next size would pass half of it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…m r*P mod num_buckets, not the first ones Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… file's 80 columns No clang-format here, so by hand: the over-long declarations and comments, the arguments of the bucketize launches that sat under the wrong column, and a comment in jit_link.h that had run into the next one. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e four numbers meet The replay filter, the twin, the checkpoint loaders and ScoredHashTable.load each passed (rank, world_size, dist_type, global_capacity=, bucket_capacity=) to owned_key_mask by hand, and the twin once re-derived two of them wrongly. They now build an OwnershipRule (from the table's options where there is one) and ask it for a mask; owned_keys becomes OwnershipRule.keep. The functional API is unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e; dump a new shard count into a new directory Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The change was a reformat with nothing to do with hash_bucket. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…nd fail on a missing name plainly Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ark take hash_bucket A NO_EVICTION table never evicts, so the layout buys it nothing, and the rank of a key under hash_bucket follows from num_embeddings, which such a table only starts from (it grows without bound): a small value leaves ranks without keys and changing it moves every key. DynamicEmbTableOptions now raises for the combination. The benchmark's --dist_type takes hash_bucket and its owner function passes the table's capacities. Three texts that still named only roundrobin and hash_roundrobin (the sharding's error message, output_dist's doc, the replay doc) name hash_bucket too. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Contributor
[Medium impact] The latest changes appear safe to merge; no new blocking issues were found. SummaryAdds
No new actionable issues found. Reviews (5) · Last reviewed commit: "[TEST](DynamicEmb) Run the twin module t..." · Reviewed by Greptile |
…which does not guarantee the keys fit The load grows a table by total rows over capacity, not by bucket occupancy, so a checkpoint built key by key into global buckets that fold into one local bucket of a table that has not grown to max_capacity can still lose rows. Hashed keys do not come like that; the text said the load expands the table so the keys fit, which was too much. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…like any other The planner row of the guide still said init_capacity is raised to max_capacity for hash_bucket; since the growth change it is kept (aligned, clamped to max_capacity). The row now says what a model allocates at startup and what the upper limit is. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…out tests Found while running the tests on EOS: - A forward on a table with a cache pins its keys until its backward, and since NVIDIA#557 a cache raises when a batch finds only pinned ones. insert_keys ran graph-building forwards without a backward, so the half of a 97 %-full shard a cache holds was pinned full after a few chunks. It now runs them under torch.no_grad(), where the forward releases its pins itself. - The uneven-fold growth test inserts a thousand keys a call. A growth is sized for the keys a call brings, so chunks of 16 384 jumped the table most of the way at once and it never stopped between P/2 and P buckets, with or without the rule against that: switching the rule off left the test green. With small chunks it fails without the rule. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…bedding collection The collection reads the dist_type and the hash_bucket layout from the checkpoint's meta and takes every shard file. The test writes a hash_bucket checkpoint by the host rule, split over 1, 2 and 8 shard files, loads it and checks that every key comes back with its own row. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The twin seeds its torchrec reference with the rows each rank's table holds, so it has to decide a key's owner as the table does. Until now only roundrobin was run: a wrong hash_bucket rule, or the wrong global_capacity / bucket_capacity behind it, went unseen. The body of test_twin_module is now a helper that takes the dist_type, and a hash_bucket test runs it over two table sizes that do not divide evenly over the ranks, pooled and sequence. With the twin's owner rule replaced by key % world_size the test fails on 8 ranks. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Collaborator
|
/build |
Collaborator
|
✅ Pipeline #83537653 -- success
Result: 19/20 jobs passed |
shijieliu
approved these changes
Nov 19, 2026
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
Part 1 — What #533 (the original PR) does
Adds the
hash_bucketdist_type and a global bucket layout that does not depend on the number of shards, so a checkpoint reloaded on a different number of GPUs does not overflow buckets or lose rows.Nis the capacity of the whole table,bcthe bucket capacity,Sthe number of shards. The bucket indexgdepends only onNandbc, not onS; a key's shard isg / P. Whenglobal_capacityequals the table capacity the formula reduces to the old one, so the layout of the existing dist_types is unchanged.LinearBucketTable::home_bucket), the routing kernel (hashed_shard) and the host-sidekey_ownership.owning_shard.block_bucketize_sparse_featuresbinding takes new arguments;EvictParamsgets a trailingtable_global_capacities; the table's lookup / insert / erase / evict kernels carryglobal_capacities_(empty for the old tables).dist_typediffers no longer always raises: onlycontinuousis refused; the others are handled by "every rank reads all files and repartitions", with a warning.test_global_bucket_layout.py,test_lookup_meta.py,hash_bucketdump/load cases, and the design docdocs/global_bucket_layout_design.md.Part 2 — What this PR does
Fills in missing capabilities on top of #533, fixes the problems found along the way, and adds tests and docs.
New capabilities
hash_bucket.bucketize.cugetshashed_bucket_owner;Configand the pybind getglobal_capacities/shard_capacities; the config check rejects non-positive capacities, plans that need more ranks thanworld_size, and inconsistent capacities within a table. The owner computation agrees with the table kernel,sparse_block_bucketize_featuresand the host rule. The parameters are cached on the host at construction, so the forward adds no device synchronization.hash_buckettable can start small and grow. The routingglobal_capacitycomes from the maximum layout and does not change with the table's current capacity, so growth only changes the number of buckets inside the table and keys stay on their rank. The forcedinit_capacity = max_capacityand the refusal to expand are removed. When the bucket count does not dividePthe fold is uneven (a run of buckets takes one more global bucket); to keep the table from stopping betweenP/2andPbuckets, the growth policy goes straight tomax_capacitywhen2*target > max_capacity.Fixes and hardening
dyn_emb_*_abi2); a stale fatbin that does not match the extension now fails to load with a clear error instead of silently placing keys by the old layout.block_bucketize_row_poswhile any feature'sdist_typeis notcontinuousnow raises (it used to be silently ignored).global_capacity/bucket_capacityinstead of re-deriving them.hash_bucketcombined withMAX_BUCKET_CAPACITYwarns (the routing is consistent but not fan-out invariant);hash_bucketwithNO_EVICTIONraisesValueError.--dist_type hash_bucket.home_bucket_ofis shared by the table kernels and the bucketizer; the host side decides ownership throughOwnershipRule; the signature ofbucketize_keysis kept as it was; the C++ changes are wrapped to 80 columns.Tests
hash_bucketcases for the hier bucketize test and the config checks, growth and its reload at another fan-out, and uneven-fold growth (keys go in a thousand at a time; with the growth policy switched off this test fails).tests/test_exportable_hash_bucket.py: an inference embedding collection loads ahash_bucketcheckpoint written as 1, 2 and 8 shard files, and every key comes back with its own row (needs the NVE runtime and is not in any group ofunit_test.sh; run on its own, 3 passed).test_global_bucket_layout.pyandtest_lookup_meta.pyare registered in thefwd_bwdgroup ofunit_test.sh; thehier_load_dumpgroup skips the segments that do not apply under hier.insert_keysruns its forward undertorch.no_grad(), so a table with a cache releases the keys it pinned in the forward (since [FIX] DynamicEmb: the cache raises on the keys its insert refuses, flagged by the kernel; pins add up across streams #557 a cache raises when a batch finds only pinned keys).Docs
DynamicEmb_APIs.md,docs/hier_output_dist.mdanddocs/global_bucket_layout_design.mdare updated: what is supported; HYBRID /MAX_BUCKET_CAPACITY/NO_EVICTIONtables do not get the lossless-across-fan-outs guarantee; a load sizes the table by its row count rather than by bucket occupancy (a constructed checkpoint is not guaranteed to fit); dump to a new directory when the shard count changes.Behavior changes
hash_bucket+NO_EVICTION: now raises.block_bucketize_row_posgiven while any feature is notcontinuous: now raises (including forroundrobinandhash_roundrobin).hash_buckettable is no longer forced up tomax_capacity; withoutinit_capacityit still starts atmax_capacity.dist_typediffers: feat(dynamicemb): hash_bucket dist_type with a fan-out-invariant global bucket layout #533's allow-and-warn behavior is kept (exceptcontinuous).Verification (8×H100, container
distributed-recommender:devel_latest)All groups of
corelib/dynamicemb/test/unit_test.sh, one full log per file; failures of the.shfiles are turned into an ERR-trap marker, so a failure shows up as!!! SUBCMD FAILED:fwd_bwdload_dumphierhier_fwd_bwdhier_load_dump51 files in total. No
!!! SUBCMD FAILEDorNo space leftin any log. The skipped cases (64 intest_twin_module.py, 4 intest_batched_dynamic_embedding_tables_v2.py, 1 in incremental dump) are skipped by conditions in the test sources and are unrelated to this PR. All 55 cases oftest_global_bucket_layout.pypass; control experiment: with the growth policy switched off the uneven-fold test fails, with it on it passes.Not verified / known limits
hash_bucketkernels do one more 64-bit modulo and division per key (expected to be negligible), and the hier path reads two more arrays per key; neither has been timed.hiergroups; the owner is just a rank number, so I expect them to be unaffected, but that is an inference.DMPCollection) are not supported, which holds for every dist_type and is not introduced by this PR.max_capacity, or useroundrobin/hash_roundrobin.nb == P, where the fold is the identity); otherwise a bucket holds{g : g ≡ b (mod nb)}, which depends on the fan-out.MAX_BUCKET_CAPACITYandNO_EVICTIONtables still do not get the lossless-across-fan-outs guarantee.Checklist