Skip to content

fix(dynamicemb): bucketize int32 keys by the int64 key a table stores - #524

Closed
shijieliu wants to merge 2 commits into
NVIDIA:mainfrom
shijieliu:fix/int32-key-owner-20261026
Closed

shijieliu wants to merge 2 commits into
NVIDIA:mainfrom
shijieliu:fix/int32-key-owner-20261026

Conversation

@shijieliu

Copy link
Copy Markdown
Collaborator

Description

With int32 KJTs under roundrobin or hash_roundrobin, a key that a checkpoint load or a delta replay puts on one rank is looked up on another rank. Nothing raises. After a load, the model misses those keys and returns fresh rows for them.

A table stores an int32 key widened to int64 with its sign, and a checkpoint or a delta holds that int64 key. Load and replay place each key by it, through key_ownership. The bucketize reads an int32 key in 32 bits instead. Under hash_roundrobin at W ranks, about (W - 1)/W of the negative keys then go to another rank, and so do about (W - 1)/W of all keys when W is not a power of two. Under roundrobin negative keys go to another rank at world sizes such as 7 or 100.

Fix: both bucketize kernels get the rank of a roundrobin or hash_roundrobin key from one helper, cyclic_bucket. It widens the key to 64 bits with its sign and works in 64 bits, which is the rule of key_ownership. Keys keep their dtype, int64 keys keep their ranks, and continuous does not change. The docs and comments that state the rules say how an int32 key is read.

Tests (H100, CI image 26.07):

  • test_hash_roundrobin_kuairand.py: every int32 and int64 key has to get the rank that key_ownership gives (edge and random keys, 1 to 255 ranks, both rules).
  • test_embedding_dump_load.sh: int32 keys, negative ones included, are dumped and loaded under hash_roundrobin at 8 and 7 ranks and under roundrobin at 7 ranks.
  • On main (d0dbc08): 16 of the 94 kuairand cases fail, all int32. Under hash_roundrobin at 8 ranks, 1786 of 4110 int32 keys get another rank. The 3 int32 dumps pass, and the 3 loads fail on every rank with Key <k> must exist in table of rank <r>.
  • With this PR: all 94 kuairand cases and all 228 invocations of test_embedding_dump_load.sh pass (225 on main). test_twin_module.sh (513 passed), test_sequence_embedding.sh (18 runs), test_pooled_embedding.sh (11 runs), test_table_row_wise.sh (26 runs) and test_incremental_dump.sh (189 passed) pass, as on main.

Checklist

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

🤖 Generated with Claude Code

shijieliu and others added 2 commits October 29, 2026 11:59
A table stores an int32 key widened to int64 with its sign, and a
checkpoint or a delta holds that int64 key. key_ownership places each
key by it when a checkpoint is loaded or a delta is replayed. The
bucketize places the int32 key of the KJT. The two agree only if the
bucketize gives an int32 key the rank of the int64 key with the same
value. These tests check that.

- test_hash_roundrobin_kuairand.py
  - test_bucketize_kernel_matches_cpu_reference also runs with int32
    keys, and also at 3 and 7 ranks.
  - test_bucketize_kernel_matches_key_ownership (new) gives the
    bucketize the keys next to 0, 2**31, 2**32 and 2**63 and 4096
    random keys of the dtype, one key per sample, at 1, 2, 3, 5, 6, 7,
    8, 12, 16, 100 and 255 ranks, for int64 and int32 keys and both
    rules. Each key's rank has to equal key_ownership.owning_shard's for
    the key widened to int64, and the rank from this file's own
    reference. Kernel2 has to write each key, unchanged and in its own
    dtype, where kernel1 counted it.
  - test_bucketize_kernel_continuous_keeps_key_width (new): continuous
    reads a key in its own width, and its rewrite of an int32 key stays
    an int32.
  - The reference reads a key as an unsigned 64-bit number under both
    rules, as the rules do. numpy's % on a negative key gives the
    remainder of the signed value, which is another number.
- test_embedding_dump_load.py: --key-dtype int32 draws int32 keys,
  negative ones included but not -4 to -1, which are the hash table's
  reserved keys as int64. --batch-size lets 7 ranks feed equal shares,
  and a batch size that is not a multiple of the world size raises.
- test_embedding_dump_load.sh: int32 keys dumped and loaded under
  hash_roundrobin at 8 and at 7 ranks, and under roundrobin at 7 ranks.
  The loaded model has to hold every key its rank owns and return the
  rows the dumped model had.

On this commit, with the bucketize of d0dbc08 (Eos, H100):
- test_hash_roundrobin_kuairand.py: 16 failed, 78 passed. All 16 are
  int32 cases: matches_cpu_reference at 3 and 7 ranks, for both
  features, and matches_key_ownership under hash_roundrobin at 2, 3, 5,
  6, 7, 8, 12, 16, 100 and 255 ranks and under roundrobin at 7 and 100
  ranks. Under hash_roundrobin at 8 ranks, for example, 1786 of 4110
  int32 keys get another rank from the bucketize than from
  key_ownership. Every int64 case and every continuous case passes.
- The int32 dump/load cases: the three dumps pass, and the three loads
  fail on every rank with "Key <k> must exist in table of rank <r>".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
What goes wrong: with int32 KJTs, a key that a checkpoint load or a
delta replay puts on one rank is looked up on another rank, and nothing
raises. After a load the model misses those keys and returns fresh rows
for them.

Why: a table stores an int32 key widened to int64 with its sign, and a
checkpoint or a delta holds that int64 key. key_ownership places each
key by it, and that is all a loader has: nothing records that the input
is int32. The bucketize reads an int32 key in 32 bits:

- roundrobin: rank (uint32)key % W, where key_ownership gives
  (uint64)key % W. The two differ for a negative key when 2**32 and
  2**64 leave different remainders modulo W, as at W = 7 or 100.
- hash_roundrobin: the hash of the zero-extended 32-bit key, cut to its
  low 32 bits, modulo W, where key_ownership hashes the sign-extended
  key and takes the whole hash modulo W. The two differ for about
  (W - 1)/W of the negative keys at any W above 1, and for most keys
  when W is not a power of two.

The fix: both bucketize kernels take the rank of a roundrobin or
hash_roundrobin key from one helper, cyclic_bucket. It widens the key to
64 bits with its sign and works in 64-bit arithmetic, which is exactly
key_ownership's rule. Kernel1 counts the lengths per rank and kernel2
writes the keys, both with this rank. The key written stays the input
key, in its own dtype. int64 keys keep their ranks bit for bit.
continuous keeps its rule: key_ownership has none for it, and its
rewrite of an int32 key stays an int32.

The other places that compute a rank from a key agree already:
key_ownership.owning_shard and murmur3_fmix64 widen a key with its sign,
and the checkpoint load, the admission counter load, replay and the twin
module all go through owned_key_mask. The comments and docs that state
the rules say how an int32 key is read: DistType in utils.h,
key_ownership.py, DynamicEmb_APIs.md and replay_increment_design.md.

Evidence, on Eos H100, this commit against the one before it:
- test_hash_roundrobin_kuairand.py: 94 passed (before: 16 failed, all
  int32, and 78 passed).
- The int32 dump/load cases of test_embedding_dump_load.sh: 6 of 6 runs
  pass (before: the 3 loads fail on every rank).
- The same before and after: test_twin_module.sh 513 passed;
  test_sequence_embedding.sh 18 runs and test_pooled_embedding.sh 11
  runs, all passing; test_table_row_wise.sh 26 runs, all passing;
  test_incremental_dump.sh 189 passed.
- test_embedding_dump_load.sh, run with the one-GPU invocations eight at
  a time: all 228 invocations pass (before: 225, the 3 int32 loads
  fail). The other 222, all with int64 keys, pass on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Fixes int32 routing under roundrobin and hash_roundrobin so lookups choose the same rank as checkpoint load and incremental replay.

  • Int32 lookups go to the rank that stores their int64 key.

No actionable issues were found. CUDA tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["int32 or int64 input key"] --> B["cyclic_bucket: signed int64, then uint64"]
  B --> C["Optional murmur3_fmix64"]
  C --> D["Remainder by shard count"]
  E["Checkpoint or delta int64 key"] --> F["owning_shard"]
  F --> D
  D --> G["Same destination rank"]
Loading

Reviews (1) · Last reviewed commit: "fix(dynamicemb): bucketize int32 keys by..." · Reviewed by Greptile

@jiashuy

jiashuy commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

closed as merged in #544

@jiashuy jiashuy closed this Nov 11, 2026
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.

2 participants