Skip to content

[FEA](DynamicEmb) Add the hash_bucket dist_type with a fan-out-invariant global bucket layout - #566

Merged
shijieliu merged 34 commits into
NVIDIA:mainfrom
jiashuy:pr533-rebase
Nov 19, 2026
Merged

shijieliu merged 34 commits into
NVIDIA:mainfrom
jiashuy:pr533-rebase

Conversation

@jiashuy

@jiashuy jiashuy commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Part 1 — What #533 (the original PR) does

Adds the hash_bucket dist_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.

G   = ceil(N / bc)          C_g = G * bc          P = ceil(G / S)
h   = fmix64(key) & INT64_MAX
g   = (h % C_g) / bc        shard = g / P         local = g % P
  • N is the capacity of the whole table, bc the bucket capacity, S the number of shards. The bucket index g depends only on N and bc, not on S; a key's shard is g / P. When global_capacity equals the table capacity the formula reduces to the old one, so the layout of the existing dist_types is unchanged.
  • The rule is implemented in three places that must agree key by key: the table kernel (LinearBucketTable::home_bucket), the routing kernel (hashed_shard) and the host-side key_ownership.owning_shard.
  • Interface changes: block_bucketize_sparse_features binding takes new arguments; EvictParams gets a trailing table_global_capacities; the table's lookup / insert / erase / evict kernels carry global_capacities_ (empty for the old tables).
  • Loading a checkpoint whose dist_type differs no longer always raises: only continuous is refused; the others are handled by "every rank reads all files and repartitions", with a warning.
  • Adds test_global_bucket_layout.py, test_lookup_meta.py, hash_bucket dump/load cases, and the design doc docs/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

  1. The hierarchical output dist supports hash_bucket. bucketize.cu gets hashed_bucket_owner; Config and the pybind get global_capacities / shard_capacities; the config check rejects non-positive capacities, plans that need more ranks than world_size, and inconsistent capacities within a table. The owner computation agrees with the table kernel, sparse_block_bucketize_features and the host rule. The parameters are cached on the host at construction, so the forward adds no device synchronization.
  2. A hash_bucket table can start small and grow. The routing global_capacity comes 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 forced init_capacity = max_capacity and the refusal to expand are removed. When the bucket count does not divide P the fold is uneven (a run of buckets takes one more global bucket); to keep the table from stopping between P/2 and P buckets, the growth policy goes straight to max_capacity when 2*target > max_capacity.

Fixes and hardening

  1. fatbin ABI guard: the evict cubin's entry points carry an ABI version (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.
  2. The routing shard capacity is derived with the same function as the host rule, and a plan made for another number of shards is refused.
  3. Passing block_bucketize_row_pos while any feature's dist_type is not continuous now raises (it used to be silently ignored).
  4. The twin module reads each table's own global_capacity / bucket_capacity instead of re-deriving them.
  5. hash_bucket combined with MAX_BUCKET_CAPACITY warns (the routing is consistent but not fan-out invariant); hash_bucket with NO_EVICTION raises ValueError.
  6. The benchmark accepts --dist_type hash_bucket.
  7. Refactors: home_bucket_of is shared by the table kernels and the bucketizer; the host side decides ownership through OwnershipRule; the signature of bucketize_keys is kept as it was; the C++ changes are wrapped to 80 columns.

Tests

  1. New tests: lossless reload under LruLfu (the JIT cubin path), HYBRID round trip at the same fan-out, hash_bucket dump/load with ordinary bucket capacities, hash_bucket cases 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).
  2. New tests/test_exportable_hash_bucket.py: an inference embedding collection loads a hash_bucket checkpoint 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 of unit_test.sh; run on its own, 3 passed).
  3. test_global_bucket_layout.py and test_lookup_meta.py are registered in the fwd_bwd group of unit_test.sh; the hier_load_dump group skips the segments that do not apply under hier.
  4. The test helper insert_keys runs its forward under torch.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

  1. DynamicEmb_APIs.md, docs/hier_output_dist.md and docs/global_bucket_layout_design.md are updated: what is supported; HYBRID / MAX_BUCKET_CAPACITY / NO_EVICTION tables 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_pos given while any feature is not continuous: now raises (including for roundrobin and hash_roundrobin).
  • A hash_bucket table is no longer forced up to max_capacity; without init_capacity it still starts at max_capacity.
  • Loading a checkpoint whose dist_type differs: feat(dynamicemb): hash_bucket dist_type with a fan-out-invariant global bucket layout #533's allow-and-warn behavior is kept (except continuous).

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 .sh files are turned into an ERR-trap marker, so a failure shows up as !!! SUBCMD FAILED:

Group Files Result
fwd_bwd 35 all passed
load_dump 5 all passed
hier 3 all passed
hier_fwd_bwd 5 all passed
hier_load_dump 3 all passed

51 files in total. No !!! SUBCMD FAILED or No space left in any log. The skipped cases (64 in test_twin_module.py, 4 in test_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 of test_global_bucket_layout.py pass; control experiment: with the growth policy switched off the uneven-fold test fails, with it on it passes.

Not verified / known limits

  • Performance is not measured. The hash_bucket kernels 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.
  • The cross-node paths (rail, proxy) are not reached by the single-node hier groups; the owner is just a rank number, so I expect them to be unaffected, but that is an inference.
  • Inference export is only tested for loading a checkpoint, not through the whole NVE chain. DynamicEmb currently supports model parallelism only: data-parallel replicas and 2D parallel (DMPCollection) are not supported, which holds for every dist_type and is not introduced by this PR.
  • A load sizes the table by its row count: keys that are uniformly hashed almost surely fit, but a checkpoint constructed per global bucket is not guaranteed to. For a strict guarantee start from max_capacity, or use roundrobin / hash_roundrobin.
  • Losslessness across fan-outs holds only when the table has grown to full size (nb == P, where the fold is the identity); otherwise a bucket holds {g : g ≡ b (mod nb)}, which depends on the fan-out.
  • HYBRID, MAX_BUCKET_CAPACITY and NO_EVICTION tables still do not get the lossless-across-fan-outs guarantee.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

jiashuy and others added 29 commits November 18, 2026 08:08
…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]>
…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]>
…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]>
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; no new blocking issues were found.

Summary

Adds hash_bucket routing with a shared global bucket layout, plus checkpoint, growth, and hierarchical-distribution support. The latest update adds twin-model tests and shares their runner with existing tests.

  • Hash bucket tables keep each key’s global bucket fixed across shard counts.
  • Hierarchical output routing now sends hash bucket keys to their owning rank.
  • Checkpoint loading now repartitions keys when the saved table layout differs.
  • The eviction kernel rejects a mismatched ABI instead of loading it silently.

No new actionable issues found.

Reviews (5) · Last reviewed commit: "[TEST](DynamicEmb) Run the twin module t..." · Reviewed by Greptile

Comment thread corelib/dynamicemb/DynamicEmb_APIs.md Resolved
jiashuy and others added 3 commits November 19, 2026 09:26
…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]>
@jiashuy jiashuy changed the title Pr533 rebase [FEA](DynamicEmb) Add the hash_bucket dist_type with a fan-out-invariant global bucket layout Nov 19, 2026
jiashuy and others added 2 commits November 19, 2026 12:28
…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]>
@shijieliu

Copy link
Copy Markdown
Collaborator

/build

@JacoCheung

JacoCheung commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #83537653 -- success

Job Status Log
pre_check ❌ failed view
train_build_x86 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
prepare-jet-eos-hier ✅ success view
prepare-jet-gb300-hier-dist ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ✅ success view
unit_test_tp_4gpu ✅ success view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view
exportable_embedding_test_1gpu ✅ success view
inference_test_nve_2605_1gpu ✅ success view
train_build_arm64 ✅ success view

Result: 19/20 jobs passed

View full pipeline

@shijieliu
shijieliu merged commit 07b2fd6 into NVIDIA:main Nov 19, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants