Skip to content

[FEA] DynamicEmb: hierarchical dist for row-wise sequence sharding - #528

Merged
shijieliu merged 80 commits into
NVIDIA:mainfrom
shijieliu:fea-hier-output-dist-lite
Nov 12, 2026
Merged

shijieliu merged 80 commits into
NVIDIA:mainfrom
shijieliu:fea-hier-output-dist-lite

Conversation

@shijieliu

@shijieliu shijieliu commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Merges on its own, on the current NGC 26.07 image: no longer stacked on #549. It takes one change of #549, the DEMB_ARCHS default with sm_103 (GB300), and not #549's image bump.

What

DynamicEmbTableOptions(output_dist="hierarchical") (or "auto") gives a row-wise sharded EmbeddingCollection of DynamicEmb tables (sequence lookups) its own input and output dist. It keeps TorchRec's sharding and awaitable interfaces. A training call on it deduplicates the sharding's keys (index dedup) whatever the sharder's use_index_dedup, and gives the results of TorchRec's dists under the same flag: the same forward rows, LFU counts and admission, and each key's gradient from the same terms (with bf16 or fp16 rows, a node's sum of a key's gradient rows, and without the flag a GPU's, is rounded once more; design doc, section 18); without the flag, the sharding warns so once, at its first input_dist(). Tables that clip gradients need the sharder's use_index_dedup=True, and the dist does not carry a score per key (PRECISE_CUSTOMIZED): such shardings raise ValueError under "hierarchical" and take TorchRec's dists with a warning under "auto". A training call that needs more than the op's capacities raises RuntimeError on every rank, naming the capacity to raise. Eval forwards, and shardings with a GPU before sm_80, take TorchRec's dists.

  • Inside a node, keys and rows move over NVLink. A node is NCCL's LSA team: a machine on Eos; with multi-node NVLink (GB200 and GB300 NVL72), the job's GPUs of the rack when the job runs inside one rack (across racks, what NCCL gives: design doc, section 4.2). Between nodes, the GPU sends them over InfiniBand itself (NCCL ≥ 2.30.7, GIN), always on its own rail.
  • Node dedup: a key asked of another node first goes over NVLink to the GPU of its node on the owner's rail (the proxy). The proxy sends each (table, key) once over InfiniBand, and the row comes back once: the op takes the rules roundrobin and hash_roundrobin, which keep the key, so a table's key has one owner. As each GPU sends each (table, key) once (index dedup), a key has at most one occurrence per GPU of the node at its proxy: one row each in the backward, which the proxy sums in a fixed order.
  • The proxy's rows are a ring (proxy_rows, 512 MiB at most by default, DYNAMICEMB_HIER_PROXY_MB). A call's rows pass through it as a stream of chunks of one owner node's keys, which every step takes in order: the owners put them, the requesters pull and push them, the proxy sums them. In each round of its stream a proxy takes the owner nodes in turn from the node after its own, so the proxies of a rail send to and receive from different nodes at a time (as DeepEP turns its RDMA peers). A chunk moves about 512 KiB over InfiniBand by default (DYNAMICEMB_HIER_PAYLOAD_KB) and holds at most 2 MiB of ring rows: a key counts max(its rows, 4) rows, so a chunk of cold keys stops at its payload and a chunk of hot keys at its ring rows.
  • Output dist: one kernel forward and one kernel backward. They only move rows. Each is built once for each GIN backend (proxy, GDAKI, GPI) and once for one node; of these builds only the proxy backend's backward kernel spills, on sm_80 to sm_90: 28 to 36 bytes (on sm_90 it used 127 of its 128 registers before the many-features commits). When a call has heavy rows (index dedup's rows of more than 64 original rows), two short kernels add up their gradients before the backward kernel. The issuers look ahead over a few chunks and make one fence per pass, as DeepEP does. The lookup writes its rows straight into the output dist's window, each lookup group's rows in a slice of their own in the order the rail puts them (its node's keys, then each other node's), where a per-call row map says: a chunk crosses InfiniBand in one put per lookup group it spans, whatever the number of features.
  • Input dist: seven comm kernels move data and wait for peers, and across nodes one kernel makes a requester's tables from its node peers' windows (design doc, section 10.2). The planner does every other step, in ordinary kernels of its own and CUB's radix sorts and scans. The bucketize is a counting sort by owner; node dedup at the proxy is a hash insert on index dedup's chained insert, with no sort. The host sizes every step from what it knows (the call's keys, the capacities, the topology); the counts only the device holds (valid keys, node-unique keys, chunks) stay on the device, where the proxy's node dedup, rows and chunk layout read them to bound their loops. With the benchmark's configuration an input dist runs 25 kernels and memory operations on one node and 51 on 2 nodes, index dedup included. input_dist() queues the whole input dist of a call, and the second wait copies the call's status to the host: one host sync per call.
  • Many features: what a call exchanges and lays out grows with the features once, not with the features times the nodes. A rank's count message to a rail peer is a header the same to all (needs, chunks and keys per node and lookup group) and the peer's own keys per feature; its row of the node's offsets holds its own node's offsets only; the node layout is closed-form, on a grid when it is large; the owner's tables come from scans a tile at a time.
  • The C++ side is ops only: the op queues each step on the caller's current stream and has no stream, event or thread of its own. It takes and gives tensors and plain values: input_dist(...) returns the owner's KJT, lookup_rows, the call's status and the output dist's two plans as lists of tensors; output_dist_fwd and output_dist_bwd run one kernel each. One static operator per sharding (HierOutputDist) makes its buffers once, at the capacities lookup_keys and remote_keys.
  • Every buffer owns its layout, in the style of DeepEP's layout classes; kernels take plain parameters. No static limit on the nodes, the GPUs per node or the features of a sharding.
  • The C++ is in src/hier_output_dist/ (common/, input_dist/, output_dist/).

Design: corelib/dynamicemb/docs/hier_output_dist.md. Benchmark: corelib/dynamicemb/benchmark/README.md, section 3.

Results

Final benchmark: TorchRec's dists against the hierarchical dist

The final runs compare TorchRec's dists (--output_dist torchrec) with the hierarchical dist (--output_dist hierarchical) in the plain loop, with power-law keys (--key_dist pow-law --alpha 1.05), 8 tables of 4,000,000 rows, dim 128, fp32, SGD and index dedup. The step is iter_ms_mean. After the first call and a barrier, 20 warmup iterations and 20 timed ones run back to back, with no sync of the benchmark's between them (the dists and the lookup keep their own). A CUDA event before the first timed iteration and one after the last give the time of the 20 on the GPU, its idle gaps included; the step is that over 20, the mean over ranks. Each point ran in rounds, the two dists in turn at each point, TorchRec's first in some rounds and the hierarchical dist first in others: three rounds on Eos, in one allocation, and five on GB300, rounds 1 to 3 in one allocation and rounds 4 and 5 in a second on the same four trays, added after rounds 1 to 3 showed stalls at 16 GPUs (see the GB300 note below). The tables give the median of the rounds. The points are F features (8 tables of F/8 features each, --features_per_table) by a number of samples per GPU (--local_batch_size), with 1 to N keys per sample and feature, drawn uniformly (--max_seq_len N --seq_len_dist uniform):

case F samples per GPU keys per sample and feature keys per GPU and iteration
1 8 8,192 / 16,384 / 32,768 1-4 164K / 328K / 655K
2 1,024 / 2,048 / 4,096 128 1-4 328K / 655K / 1.31M
3 8 128 1-1,024 / 1-2,048 / 1-4,096 / 1-8,192 525K / 1.05M / 2.10M / 4.19M
COMMON="--num_tables 8 --num_embeddings 4000000 --use_index_dedup --num_iterations 20 --warmup 20 \
        --pipeline none --profile_iterations 0 --key_dist pow-law --alpha 1.05 --json_out results.jsonl"
for DIST in torchrec hierarchical; do   # here one dist after the other; the runs took both in turn at each point
  for B in 8192 16384 32768; do      # case 1
    $LAUNCH $BENCH $COMMON --output_dist $DIST --features_per_table 1 --local_batch_size $B \
      --max_seq_len 4 --seq_len_dist uniform
  done
  for P in 128 256 512; do           # case 2
    $LAUNCH $BENCH $COMMON --output_dist $DIST --features_per_table $P --local_batch_size 128 \
      --max_seq_len 4 --seq_len_dist uniform
  done
  for N in 1024 2048 4096 8192; do   # case 3
    $LAUNCH $BENCH $COMMON --output_dist $DIST --features_per_table 1 --local_batch_size 128 \
      --max_seq_len $N --seq_len_dist uniform
  done
done

On Eos (H100 nodes of 8 GPUs: NVLink inside a node, a 400 Gb/s IB NIC per GPU between nodes; the hierarchical dist's node is a machine), on 1, 2 and 4 nodes. TorchRec's step / the hierarchical dist's step, in ms, and the hierarchical dist against TorchRec's:

F × samples per GPU (keys per sample and feature) keys per GPU 8 GPUs 16 GPUs 32 GPUs
8 × 8k (1-4) 164K 3.04 / 1.36 (-55%) 4.07 / 1.99 (-51%) 5.38 / 2.31 (-57%)
8 × 16k (1-4) 328K 3.68 / 1.53 (-58%) 5.71 / 2.54 (-56%) 8.05 / 3.04 (-62%)
8 × 32k (1-4) 655K 5.26 / 1.95 (-63%) 8.94 / 3.40 (-62%) 13.38 / 4.31 (-68%)
1k × 128 (1-4) 328K 4.75 / 1.62 (-66%) 7.59 / 2.68 (-65%) 11.75 / 3.30 (-72%)
2k × 128 (1-4) 655K 7.40 / 2.17 (-71%) 12.71 / 3.64 (-71%) 20.64 / 4.58 (-78%)
4k × 128 (1-4) 1.31M 12.55 / 3.33 (-73%) 22.55 / 5.62 (-75%) 37.81 / 7.20 (-81%)
8 × 128 (1-1k) 525K 3.96 / 1.77 (-55%) 5.87 / 3.07 (-48%) 7.37 / 3.79 (-49%)
8 × 128 (1-2k) 1.05M 5.74 / 2.53 (-56%) 8.83 / 4.47 (-49%) 11.36 / 5.75 (-49%)
8 × 128 (1-4k) 2.10M 9.09 / 4.00 (-56%) 14.54 / 6.99 (-52%) 18.40 / 9.23 (-50%)
8 × 128 (1-8k) 4.19M 15.40 / 6.76 (-56%) 24.60 / 11.29 (-54%) 31.25 / 14.94 (-52%)

On GB300 (NVL72 trays of 4 GPUs), on 1, 2 and 4 trays of one rack: one NVLink domain, so one node of 4, 8 and 16 GPUs for the hierarchical dist. Each rank runs pinned to cores of its GPU's CPU (below):

F × samples per GPU (keys per sample and feature) keys per GPU 4 GPUs 8 GPUs 16 GPUs
8 × 8k (1-4) 164K 3.80 / 1.78 (-53%) 3.89 / 1.78 (-54%) 4.08 / 1.77 (-56%)
8 × 16k (1-4) 328K 3.80 / 1.70 (-55%) 3.84 / 1.75 (-55%) 4.31 / 1.73 (-60%)
8 × 32k (1-4) 655K 4.23 / 1.84 (-56%) 4.69 / 1.88 (-60%) 5.82 / 1.92 (-67%)
1k × 128 (1-4) 328K 4.41 / 1.82 (-59%) 4.95 / 1.81 (-63%) 6.20 / 1.82 (-71%)
2k × 128 (1-4) 655K 5.38 / 1.99 (-63%) 6.79 / 2.03 (-70%) 9.65 / 2.09 (-78%)
4k × 128 (1-4) 1.31M 8.21 / 2.63 (-68%) 11.04 / 2.72 (-75%) 16.88 / 3.06† (-82%†)
8 × 128 (1-1k) 525K 3.82 / 1.72 (-55%) 3.84 / 1.77 (-54%) 4.89† / 1.82 (-63%†)
8 × 128 (1-2k) 1.05M 4.76 / 2.18 (-54%) 4.85 / 2.24 (-54%) 4.94 / 2.30 (-54%)
8 × 128 (1-4k) 2.10M 6.70 / 3.04 (-55%) 6.70 / 3.16 (-53%) 6.85 / 3.24 (-53%)
8 × 128 (1-8k) 4.19M 10.24 / 4.88 (-52%) 10.30 / 5.02 (-51%) 11.23 / 5.13 (-54%)
  • --check passed at every scale (8 × 128, 1 to 1,024 keys per sample and feature): over 4 steps of SGD, the hierarchical dist's outputs equal TorchRec's bit for bit (fp32, power-of-two GPU counts).
  • Eos: over the 60 combinations of point, scale and dist, the slowest of the three rounds was 0.6% above the fastest at the median, and more than 5% above it at 4 of them (at most 16%: the first round of the hierarchical dist at 8 × 128 (1-1k) on 8 GPUs).
  • GB300 runs pinned. nvidia-smi topo -m puts GPUs 0 and 1 on cores 0-71 and GPUs 2 and 3 on cores 72-143; local ranks 0 to 3 ran on cores 8-39, 40-71, 80-111 and 112-143 (taskset -c <cores> in front of python in each task), the first 8 cores of each CPU left to the system. Unpinned, a rank's main Python thread sometimes waited 1 to 4 ms for a CPU after it was woken (in the longest cases behind another rank's thread on its core), and every rank waited for it in the call's collective kernels: with the benchmark's earlier timing, on four trays of another rack, the hierarchical dist's 16-GPU steps unpinned were 1.3 to 3.1 times its pinned ones, and at 8 × 16k and 1k × 128 about as long as TorchRec's. There, pinning also shortened TorchRec's 16-GPU steps (unpinned 1.03 to 1.34 times pinned) but lengthened its 4-GPU steps by 2% to 13% (cause unknown). Pinned, a rank still stalls at times, for tens of ms, at random (cause unknown), and every rank waits for it. At 4 and 8 GPUs the five rounds of a point spread by at most 3% and 5%; at 16 GPUs 10 of the 20 points and dists had a round more than 10% above their fastest, and at two of them the median of the five is itself a slow round, marked † in the table: the hierarchical dist at 4k × 128 (3.06 ms; its two fastest rounds 2.78 and 2.80 ms, about 83% shorter than TorchRec's 16.88 ms) and TorchRec's dists at 8 × 128 (1-1k) (4.89 ms; their two fastest rounds 4.05 and 4.10 ms, against which the hierarchical dist's 1.82 ms is about 55% shorter).
  • Rank 0 of one more run per point and dist was captured with nsys (the run's options plus --nvtx), at 8 × 32k, 4k × 128 and 8 × 128 (1-8k), on 32 Eos GPUs and 16 GB300 GPUs. Each capture holds the 20 warmup and the 20 timed iterations, with no sync of the benchmark's between them, and the timed iterations' span on the GPU (from their first kernel's start to their last one's end, idle time included) over 20 is that run's step. Against the tables' medians, the captured runs' steps were 0% to 4% longer on Eos. On GB300 the hierarchical dist's were 1% to 5% longer (at 4k × 128, whose median is a slow round, 4% shorter than it and 5% longer than its two fastest rounds), and TorchRec's dists' 4% to 14% longer: at 8 × 32k every iteration about 10% longer (about 0.6 ms, as at that point on Eos; likely nsys tracing the input dist's many CUDA calls), at 8 × 128 (1-8k) some iterations up to 16.5 ms against a median step of 11.2 ms.

Output dist kernels at large batch (Eos)

The large batch (README section 3: one table of 268M rows, bf16, 16,384 samples per GPU of 1 to 1,536 keys, the default ring and payload), the output dist's kernels and the bandwidth they reach on the link that bounds them:

nodes link GB per GPU and call forward backward
1 NVLink 2.76 8.3 ms, 331.6 GB/s (100% of 330) 7.9 ms, 348.1 GB/s (99% of 352)
2 IB 1.34 28.3 ms, 47.5 GB/s (95% of 50) 32.2 ms, 41.8 GB/s (84% of 50)
4 IB 2.02 41.9 ms, 48.1 GB/s (96% of 50) 41.8 ms, 48.2 GB/s (96% of 50)

On 2 nodes the ring's laps cost the backward: a ring that holds the stream in one lap gives 28.5 ms (94%). Measured on 45101458; not timed again on the later commits.

HSTU end-to-end (Eos, 2 nodes)

The HSTU E2E benchmark (examples/hstu/training/benchmark/E2E_BENCHMARK.md, 2 nodes) has the hierarchical dist as experiment 6, on top of exp5 (CUTLASS attention, shuffler, caching, hash_roundrobin, prefetch pipeline). In one batch of exp0-exp6, exp6 gives 353.3 TFLOPS/GPU on average over iterations 199-999, against 349.5 for exp5 (+1.1%), and 357.1 against 355.9 at the best interval. With the many-features commits, one more batch of exp5 and exp6 on other nodes gives 351.8 against 344.1 (+2.2%). The doc also profiles exp5 and exp6, and exp4 (no pipeline) with and without the dist: nsys on all 16 ranks, MEM_DEBUG, and repeated runs with Python's garbage collections logged.

  • Host: 15.6 blocking host syncs per step instead of 27.1 (16.0 instead of 23.6 without a pipeline). The steady step is 0.4% (prefetch) and 0.6% (no pipeline) shorter.
  • Most of the gain in the average is cheaper garbage-collection stalls. The ranks' gen-2 collections start at 3 moments instead of 8-10, so their pauses overlap. This comes from each rank's Python allocations, not from the dist's communication.
  • Load balance does not change on 2 nodes. The ranks differ by 6.3-6.6 ms per step in attention, and the owners' DynamicEmb kernels take 0.16-0.25 ms per step. Node dedup removes 5.3% of an owner's rows.
  • Memory: +1.5 GiB per GPU at the default capacity (2,097,152 keys). With a capacity sized for the workload (131,072 keys), exp6 uses 84 MiB less than TorchRec's dists.

Commits

The first 28 commits build the dist; each message says what it changes and what it measured. Then:

  • names: a chunk's sizes in rows, spans and rounds; offsets tables named *_offsets; names that say what they hold; the option and knobs (output_dist="hierarchical", DYNAMICEMB_HIER_*, HierDist). No compiled code changes.
  • a merge of NVIDIA main (fix(dynamicemb): index reference counters across logical tables #514, [FEA](DynamicEmb) intput per key score by PRECISE_CUSTOMIZED score strategy #530, [FEA](DynamicEmb) async erase by score #532, [FEA] Layerwise Design #498): per-key scores never reach the dist; frequency counters are decided per sharding; a rank with no keys for a sharding that counts frequencies sends empty weights, so the ranks' all2alls match (main does the same since fix(dynamicemb): send frequency weights for an empty input under index dedup #527).
  • the review: index dedup's MurmurHash3_32 stays in unique_op.cu; gin_rail_congestion.cu goes; MAX_OUTPUT_DIST_CAPACITY comes from C++ in every build; --host_stages runs again; the README's large-batch results; the HSTU end-to-end test; the HSTU E2E benchmark's new item.
  • a cleanup of dead code and stale text: outputs and gradients are the same bit for bit before and after it, on 1, 2 and 4 nodes, also with a 32 MiB ring.
  • many features (three commits): one put per chunk and lookup group, with the lookup's row map and count messages of one round; then the node exchange's compact rows and closed-form layout, and scans a tile at a time; then the design doc and the benchmark README at many features. Outputs and gradients are the same bit for bit before and after them.
  • a merge of NVIDIA main (feat(dynamicemb): erase_by_score for lru_lfu tables, per named table #536, fix(dynamicemb): keep each table's local_hbm_for_values budget in fused groups #534, fix(dynamicemb): keep prefetched keys' ref counts through a rehash #529, fix(dynamicemb): send frequency weights for an empty input under index dedup #527, fix(dynamicemb): wait for queued GPU work before freeing VMMTensor memory #526): fix(dynamicemb): send frequency weights for an empty input under index dedup #527 had made this branch's change for an empty input, and the merge keeps one copy of it. Git's merge moved this branch's PrefetchState.record_stream out of its class without a conflict, next to fix(dynamicemb): keep prefetched keys' ref counts through a rehash #529's new _slots_after_rehash; the merge puts it back. No code of the dist changes.
  • the benchmark README: three rounds of alternating order at many features.
  • the input dist's fusions (ten commits; each of the eight that change kernels says what it does to launches or allocations): the bucketize as a counting sort by owner; the proxy's node dedup, rows and chunks bounded by the counts the device holds, with no host sync; its push order on 32-bit keys; the count messages from offsets the call already has; a requester's tables in one kernel, which reads the node peers' windows; the chunk layout on a grid; the proxy's scans as cub::DeviceScan with CCCL iterators over sizes the host knows, with no count tables (two earlier commits of the round had scanned the live counts with kernels of their own); the planner tests under compute-sanitizer, and a fix to a test's sizes. Outputs and gradients are the same bit for bit before and after them.
  • the existing tests on the dist: DYNAMICEMB_TEST_OUTPUT_DIST=hierarchical runs DynamicEmb's existing tests of sharded EmbeddingCollections again on the dist, their configurations unchanged, and asserts the path each sharding took; test/unit_test.sh runs them so when the build has the dist.
  • the dist deduplicates a sharding's keys itself: before, "hierarchical" raised ValueError for a sharder without use_index_dedup=True and "auto" took TorchRec's dists. Now a training call on the dist deduplicates the keys whatever the flag, with TorchRec's results under the same flag: the same forward rows, LFU counts and admission, and each key's gradient from the same terms (16-bit gradient rows round a GPU's sum of a key once more). Tables that clip gradients still need the flag.
  • the benchmark README: the input dist before and after the fusions, and two of its notes corrected.
  • a warning when the dist deduplicates a sharding's keys itself: once per sharding and rank, at its first input_dist(), when the sharder's use_index_dedup is False. The HSTU training scripts, which turn the dist's fallback warnings into errors, now match only those, which end with "using TorchRec's dists".
  • the benchmark README: multi-hot runs at many features.
  • the benchmark times the embedding alone: two pre-drawn batches called in turn, pre-drawn output gradients and no loss (an autograd function hands each feature's rows its gradient), so that its step is the EC's forward and backward. --check uses the same gradients, per element.
  • the benchmark README: the many-features and multi-hot points with that loop.
  • the dist's node is NCCL's LSA team: dynamicemb.shard.node_size(pg) reads it once per group of ranks, from a short-lived NCCL communicator of the group; the ranks check that they read the same size and that it divides their number, and else warn and take TorchRec's dists. LOCAL_WORLD_SIZE stays the host's, for TorchRec's planner. On GB300, 2 and 4 trays of a rack are one node of 8 and 16 GPUs.
  • the benchmark: --nvtx (NVTX ranges of the iterations and their stages, between cudaProfilerStart and cudaProfilerStop, so that a capture holds them alone) and --nvtx_ops (a range per PyTorch op).
  • the benchmark's EC returns one JaggedTensor over all features: TorchRec's per-feature construct_jagged_tensors (about 4 ms of host time per step at 1,024 features on GB300, the same for every dist, and a cat of the features' gradients in the backward) gives way to one that keeps the rows whole; index dedup's expansion stays, as the installed TorchRec does it.
  • the benchmark turns Python's garbage collector off in the timed iterations: with the per-feature output, every 20-iteration run of the hierarchical dist at 1,024 features on GB300 stalled at the same two timed calls, 80 to 140 ms each (full collections, logged with gc.callbacks), and the ranks' collective kernels waited for the rank that paused.
  • the benchmark times its iterations with CUDA events: after the first call and a barrier, 20 warmup iterations and 20 timed ones run back to back, with nothing of the benchmark's between them that syncs the host with the GPU (the dists and the lookup keep their own syncs), and an event before the first timed iteration and one after the last give the step (iter_ms_mean, the mean over ranks); Python's garbage collector is off from the barrier to the end of the timed iterations. Before, rank 0's host clock timed iterations that started right after a sync, a collection and a barrier, and on 2 and 4 Eos nodes a rank was 1 to 5 ms late at the first timed calls in most runs. The per-call events (each call's input dist and output dist, each iteration's forward and backward) add host work to every call and now come with --call_events. Under --nvtx the run adds only NVTX ranges and cudaProfilerStart/cudaProfilerStop around the warmup and the timed iterations (no event, barrier or sync in or between them), so a capture holds those iterations as the benchmark runs them; nsys's own tracing can still lengthen a captured step (Results).
  • the benchmark README, the design doc and this description: the final results (power-law keys, the CUDA-event timing; Eos on 8, 16 and 32 GPUs; GB300 on 4, 8 and 16 GPUs, pinned), in place of the many-features and multi-hot tables, their notes, and the paragraph on the input dist before and after the fusions.
  • a merge of NVIDIA main up to 476cdc01 ([FIX](DynamicEmb) Treat int32 keys as the int64 keys a table stores, under every dist_type and index dedup #544 and FIX](DynamicEmb) Release slot pins after no-grad training forwards #547 in DynamicEmb; fix(hstu): fix FBGEMM so Hopper DSL is paged-only #535, fix(flexkv): set kv_dim instead of assigning ModelConfig.use_mla #537, [FEA] AI-Search-Plugin: drop-in components for search-agent RL post-training on slime and verl #539 and Add Feature-Extractor-Plugin: Spark expression fusion (batch) and Flink GPU operators (streaming) #540 outside it). [FIX](DynamicEmb) Treat int32 keys as the int64 keys a table stores, under every dist_type and index dedup #544 deduplicates int32 keys as int64 in _dedup_indices and returns them in the input's dtype, as this branch did: the merge keeps main's widening (indices_64bit) and drops this branch's copy; the rest of _dedup_indices stays this branch's. FIX](DynamicEmb) Release slot pins after no-grad training forwards #547's library change (a no-grad training forward releases its slot pins) merges without conflicts. Its no-grad forward in test_sequence_embedding_fw.py conflicted with this branch's check_path, which the merge moves into the no_grad block, so with DYNAMICEMB_TEST_OUTPUT_DIST=hierarchical that test now runs no-grad training forwards on the dist.
  • int32 keys: since [FIX](DynamicEmb) Treat int32 keys as the int64 keys a table stores, under every dist_type and index dedup #544, DynamicEmb's bucketize places an int32 key as the int64 key of its value, as key_ownership already did, while the op reads a key in its own width. So the sharding gives the op int32 keys as int64 (hier_forward), and a key gets the same owner on the dist as on TorchRec's path and in a checkpoint load or a delta replay. No C++ changes. The docs no longer ask a node's GPUs to give the dist keys of one dtype.
  • GPUs of sm_80 and newer: DynamicEmb builds for DEMB_ARCHS, by default sm_75, sm_80, sm_90, sm_100, sm_103 (since the last commit, below) and sm_120 (the CI's TORCH_CUDA_ARCH_LIST does not reach its -gencode flags), and __reduce_max_sync and __reduce_add_sync in input_dist/proxy.cu are sm_80 instructions, so a default build stopped there, as the CI's did (the Eos and GB300 runs built with DEMB_ARCHS=90 and 103). The sm_75 build now has a trap in place of the two, and a sharding with a GPU before sm_80 on any rank takes TorchRec's dists, with a warning on every rank at its first input_dist() (node_size). The code for sm_80 and newer does not change.
  • NCCL 2.31 and TorchRec 1.9, of [BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's NGC 26.09 image: NCCL 2.31 removed ncclDevComm::ginConnectionsRailed, and gin_railed reads ginConnectionStride > 1 from 2.31 on (NCCL's own compat mapping) and the flag before, so the dist builds against both. TorchRec 1.9 passes use_sorted_select to construct_jagged_tensors, which the EC benchmark's flat output now takes.
  • DynamicEmb built for sm_103 (GB300) by default, [BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's change without its image bump: DEMB_ARCHS defaults to 75;80;90;100;103;120, less the architectures nvcc --list-gpu-code does not list (sm_103 needs CUDA 12.9 or newer; the NGC 26.07 image's CUDA 13.3 has it). The README says how DEMB_ARCHS works.
  • the dist's tests as CI jobs of their own. DynamicEmb's CI scripts on the current image (Eos, with the CI's NCCL_P2P_DISABLE=1; Tests, below) stopped in test_hier_dist.sh at 6 GPUs: NCCL's LSA team there was 2 ranks of the host, so three of the dist's nodes on one host would exchange keys and rows over GIN, where ncclDevCommCreate failed, and every sharding took TorchRec's dists. A run where NCCL splits a host between nodes (hier_switch.splits_host) now skips the dist's tests with a line, and check_path passes a fallback there. test/unit_test.sh's hier suites and reruns move to two groups, fwd_bwd_hier and load_dump_hier, which distributed-recommender!141 makes CI jobs of their own: the CI gives a job two hours, which fwd_bwd and load_dump already take most of (design doc, section 18).
  • a revert of that commit (9c67e22d; the tree is 3c543b01's again). The dist is tested by hand on Eos, on one node and across nodes, with NCCL's P2P on. The CI runs its single-node tests in test/unit_test.sh's groups, as before, and distributed-recommender!141 is closed.

Changes to DynamicEmb's lookup and tables

  • BatchedDynamicEmbeddingTablesV2.output_alloc says where the sequence output goes: the output dist's window, and optionally each key's row there (a row map). load_from_flat_table_kernel* and scatter_fused take out_row, and reduce_grads takes grad_rows: the backward reads key i's gradient at its row, and the sort by the inverse index, so the sums, stay the same. Without a row map nothing changes.
  • A sequence lookup whose keys were all admitted loads each key's row straight into the output (load_from_flat_by): one kernel in place of a load and a gather.
  • The counters of found and inserted keys take the slots of missing keys (−1) as they are, since the counter kernel skips them. Three boolean compactions and their host syncs go.
  • PrefetchState.record_stream marks a prefetched batch's tensors (the unique scores included) as used on the stream of its forward and backward. Without it, a prefetch pipeline whose host runs steps ahead hits an illegal memory access.
  • The lookup's prefetch passes index dedup's frequency counters, so LFU scores and admission counts under a prefetch pipeline match the plain loop, on TorchRec's dists too. BatchedDynamicEmbedding.prefetch, which nothing calls after the merge, goes.
  • BatchedDynamicEmbeddingTablesV2 takes a keyword-only admission_counts_occurrences (default True, today's behaviour). With False, a table that admits but does not evict by LFU counts each key once per call rather than its occurrences; the sharding sets it from the sharder's use_index_dedup, so that admission on the dist matches TorchRec's dists without index dedup.

The ref counts of prefetched keys through a rehash are kept by #529, on main and merged here.

int32 keys and #544

#524 and #525 were closed, and #544 put their changes on main. This branch merges it.

Tests

On 3c543b01, DynamicEmb's CI scripts ran on Eos as ci/dynamicemb_test.sh runs them. The image was the CI's current devel image (devel_latest, NGC 26.07: torch 2.13, CUDA 13.3, NCCL 2.30.7, TorchRec 1.8.0). DynamicEmb was built with its default DEMB_ARCHS: SASS for sm_75, 80, 90, 100, 103 and 120, and the eviction fatbins for the same, LTO-IR included. Each group ran on one node of 8 H100s with NCCL_P2P_DISABLE=1. In fwd_bwd, every file before the hier suites passed. test_hier_dist.sh passed at 2 and 4 GPUs and stopped at 6, which the last commit handles (Commits). In load_dump, every file passed. Its rerun of test_embedding_admission.sh on the dist then failed at 8 GPUs: NCCL split the host into 2 nodes of 4 there too, and the last commit handles that the same way. So under the CI's NCCL_P2P_DISABLE=1, the dist runs on an H100 host only at 2 and 4 GPUs. On f4b2ab68, this head, the GitLab CI pipeline below is running. The runs below this paragraph are of the commits before the merge of main up to 476cdc01 (#544, #547).

On 9c67e22d, this head, by hand on Eos with NCCL's P2P on (the CI's current devel image, the build above), everything passed:

  • One node of 8 H100s: test_hier_dist.sh 1,047 checks (at 2, 4, 6 and 8 GPUs, each one node of the dist), test_hier_overflow.sh 222 and test_hier_pipeline.sh 47. Then the eight files test/unit_test.sh runs again on the dist, each with its group: test_sequence_embedding.sh, test_twin_module.sh, erase_async/test_erase_async.sh, per_key_score/test_per_key_score.sh, test_lfu_scores.sh, admission/test_embedding_admission.sh, test_embedding_dump_load.sh and incremental_dump/test_incremental_dump.sh.
  • Across nodes, 8 ranks a node: test_hier_dist.py on 2 nodes, 138 checks, again with a 1 MiB proxy ring, and on 4 nodes, 138. test_hier_overflow.py on 2 nodes, 79. test_hier_pipeline.py on 2 nodes, 45.
  • In the CI, the two-node JET job of distributed-recommender!143 passed on main (d53b9c8c, this PR merged): pipeline 81592418, 400 checks.

On 8d4a1c54 to 9bcd233c (the library and its tests are those of 8d4a1c54, the node-size commit; the later commits change only the benchmark, its README and the design doc's results):

  • GB300 (oci-jhb: NVL72 trays of 4 GB300 GPUs, NCCL 2.30.7, CUDA 13.3, TorchRec 1.8.0), the dist's node from NCCL's LSA team: test_hier_dist.py 137 on 2 trays (one node of 8 GPUs) and on 4 trays (one node of 16 GPUs), with the node-size checks; its proxy-ring case runs only across nodes, which Eos's 138 include. The benchmark's --check (power-law keys, 1 to 1,024 keys per sample and feature) passes on 4, 8 and 16 GPUs.
  • Eos: test_hier_dist.py 138 on 2 nodes; the benchmark's --check (the same) passes on 1, 2 and 4 nodes.

On the round's code before the warning (78c3b6bc), on Eos:

  • one GPU: test_hier_bucketize.py 325 and test_hier_dedup.py 168. One node: test_hier_dist.sh 1,037 (now also the models without index dedup), test_hier_overflow.sh 222, test_hier_pipeline.sh 47, the HSTU end-to-end test 13. 2 nodes: test_hier_dist.py 137 (also with a 1 MiB ring), test_hier_overflow.py 79, test_hier_pipeline.py 45, the HSTU end-to-end test 13. 4 nodes: test_hier_dist.py 137.
  • DynamicEmb's existing tests with the switch on (DYNAMICEMB_TEST_OUTPUT_DIST=hierarchical, with PYHKV_DEBUG_STRICT=1), one node, pass: sequence embedding, twin module (also on 2 nodes of 4 GPUs), LFU scores, admission, async erase, incremental dump and dump/load. About 210 of their runs or cases take the dist and assert that their sharding took it: 2 sequence-embedding launches, 24 twin cases, 28 LFU launches, 34 admission cases, 110 dump/load launches, 4 erase models and 8 incremental-dump tests. A sharding given "auto" (one GPU, plain tables in the sharding, rows that are not a multiple of 16 bytes, scores per key) must fall back; pooled collections and the files' unsharded tests ignore the switch. The edited files pass with the switch off too.
  • with the warning (8de84a9d): test_hier_dist.sh 1,037 on one node and test_hier_dist.py 137 on 2 nodes, whose checks now include it: a sharding on the dist without the sharder's index dedup warns exactly once, under "hierarchical" and "auto", and no other case warns. test_embedding_dump_load.sh with the switch off: its 110 launches pass.
  • the benchmark's new loop (e8de8429): --check (TorchRec's dists against the hierarchical dist, 4 steps, outputs, gradients and tables) passes with --pipeline none, sparse_dist and prefetch, with and without --use_index_dedup, fp32 and bf16 output, on one node, at 1,024 features, and on 2 nodes; --kernel_times, --host_stages and --nic_counters run.

On the input dist's fusions (a3d8d1d5, before the commits on the tests and the dedup):

  • one GPU: test_hier_bucketize.py (325 cases) and test_hier_dedup.py (151 proxy cases; its requester cases then stopped on a test bug, an AttributeError that 994cdefc fixes, which also stopped test_hier_dist.sh before its test_hier_dist.py runs; with the fix, 168 pass on the final tree, whose C++ is the same): the planner's steps against reference implementations, now with the counting sort and its fallback, the live counts (at 0, at the capacity, at 20 times the need), 32- and 64-bit push keys, the requester kernel (a proxy with no chunks or with max_chunks, 72 GPUs per node, 40 nodes), the chunk layout on 1 to 600 CTAs and rings of several laps, and CUB's tile edges. Under compute-sanitizer, on short sets of both files: racecheck and initcheck of the bucketize, memcheck, initcheck and racecheck of the proxy and of the chunk layout: no error or hazard (the bucketize's racecheck and the proxy's memcheck stopped at their time limits, after 83 and 5 cases).
  • one node: test_hier_overflow.sh 222, test_hier_pipeline.sh 47, the HSTU end-to-end test 13.
  • 2 nodes: test_hier_dist.py 125 (also with a 1 MiB ring), test_hier_overflow.py 79, test_hier_pipeline.py 45, the HSTU end-to-end test 13; 4 nodes: test_hier_dist.py 125.
  • bitwise: the forward outputs and the lookup's gradients are the same as before the fusions on 1, 2 and 4 nodes, also with a 32 MiB ring, and at 1,024 features on 1 and 2 nodes (where two runs before the fusions agree too).

Earlier rounds, all on Eos. On the many-features commits, before the merge of main up to d03198c3 (the 2-node runs and the bitwise checks before their last formatting, comment and import-order edits and a fix to a unit-test hook's copies, none of which changes code those runs use):

  • one GPU: test_hier_bucketize.py (241 cases) and test_hier_dedup.py (73): the planner's steps against reference implementations, now with the row map, the group runs, the group shifts and several lookup groups, and the node layout on one CTA and on a grid.
  • one node: test_hier_dist.sh 798 (outputs, gradients and tables against TorchRec's dists, over shapes, owner rules, weights, capacities, per-key scores refused), test_hier_overflow.sh 222, test_hier_pipeline.sh 47 (TorchRec's own pipelines, without Megatron).
  • 2 nodes: test_hier_dist.py 122 (also with a 1 MiB ring, so streams wrap it; two cases again with the node exchange's grids), test_hier_overflow.py 79, test_hier_pipeline.py 45; 4 nodes: test_hier_dist.py 122 (also with a 1 MiB ring).
  • bitwise: the forward outputs and the lookup's gradients (in KJT order) are the same as before the many-features commits on 1, 2 and 4 nodes, also with a 32 MiB ring; the first of them alone too.
  • examples/hstu/test/test_hierarchical_dist.py: the HSTU ranking model on the hierarchical dist against TorchRec's dists under the example's JaggedMegatron pipelines, 13 cases on one node and on 2 nodes.
  • main's tests that touch the sharding and the lookup pass: per-key scores (76), LFU scores, table operations (204), async erase (144), sequence embedding, admission (13), and frequency counting, int64 weights, test_unique_op.py, row indexing without eviction and table rows (95); and a build without NCCL ≥ 2.30.7 imports and falls back to TorchRec's dists (test_hier_pipeline.py on 1 and 8 GPUs).

On the merge of main up to d03198c3 (#536, #534, #529, #527 and #526): every file of test/unit_test.sh passes on one node (both groups, each .sh file with its DYNAMICEMB_TEST_GROUP), and so does the HSTU end-to-end test on one node and on 2; on 2 nodes test_hier_dist.py 122, test_hier_overflow.py 79 and test_hier_pipeline.py 45, on 4 nodes test_hier_dist.py 122. The first round of these tests found the misplaced record_stream.

CI

  • Pipeline #81428478 (e2da9a1e, 2026-11-12 00:44 UTC): the x86 and arm64 builds stopped at input_dist/proxy.cu for sm_75, which lacks __reduce_max_sync and __reduce_add_sync (the sm_80 commit above), so the tests did not run. pre_check failed too, as it may (allow_failure): its hooks flag files this PR does not change, and black flags test_erase_distributed.py in main's lines.
  • Pipeline #81453924 (a3dbdca9, 2026-11-12 03:05 UTC): cancelled in its devel builds, which had the NVE 26.05 C++20 failure of [BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's first pipeline.
  • Pipeline #81489761 (63c2ec30, 2026-11-12 06:14 UTC): cancelled, with [BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's second pipeline (NVE 26.05's bit_ops.hpp, line 142).
  • Pipeline #81512767 (a93932c3, 2026-11-12 07:46 UTC): cancelled when this PR left [BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's stack.
  • Pipeline #81527525 (3c543b01, 2026-11-12 08:46 UTC), on the current images (devel_latest, NGC 26.07). The x86 and arm64 builds, build_whl, L20_unit_test_1gpu, unit_test_4gpu, the three inference jobs and the JET preparations passed. unit_test_tp_4gpu failed as it has on main since October: an empty evaluation batch at hstu/modules/tp_layer_norm.py:131 with kuairand_1k_ranking_tp2.gin, also in pipelines 74381692 and 79130132. pre_check failed too, as it may. The two DynamicEmb jobs were cancelled for the next pipeline, and unit_test_1gpu_a100 and unit_test_1gpu_h100 are running.
  • Eos, by hand (2026-11-12 08:46 UTC), on 3c543b01: fwd_bwd stopped in test_hier_dist.sh at 6 GPUs. load_dump passed every file, then stopped in the 8-GPU rerun of test_embedding_admission.sh on the dist, where NCCL split the host (Tests, above). The CI's current devel image (devel_latest, amd64 sha256:1ed8e0ef, NGC 26.07), DynamicEmb built with its default DEMB_ARCHS (sm_103 included), then bash test/unit_test.sh fwd_bwd and load_dump on one node of 8 H100s each, with NCCL_P2P_DISABLE=1, as ci/dynamicemb_test.sh runs them.
  • Pipeline #81551453 (f4b2ab68, 2026-11-12 10:14 UTC), on the branch of distributed-recommender!141, which adds the fwd_bwd_hier and load_dump_hier jobs: cancelled. The arm64 build and the JET preparations passed. The x86 build compiled, then its image push to the registry timed out. Its retry hung for an hour in the CI's own git fetch, on the same machine, genoa-cl-01.
  • Pipeline #81573693 (f4b2ab68, 2026-11-12 11:53 UTC): running, on the same branch, with CI_SLURM_EXCLUDE=genoa-cl-01,lego-cg1-qs-99. That keeps it off genoa-cl-01 and off an arm64 machine whose builds fail to start ([BUILD] NGC PyTorch 26.09 base image, and DynamicEmb for GB300 (sm_103) #549's pipelines). It was cancelled when 9c67e22d reverted the commit it tested.
  • Pipeline #81577072 (9c67e22d, 2026-11-12 12:05 UTC), on github_ci, with the same CI_SLURM_EXCLUDE: cancelled for the next one.
  • Pipeline #81578901 (9c67e22d, 2026-11-12 12:15 UTC): running, on the branch of distributed-recommender!143, with the same CI_SLURM_EXCLUDE. That branch adds a JET job that runs the dist across two Eos nodes, 16 ranks, with NCCL's P2P on: test_hier_dist.py (again with a 1 MiB proxy ring), test_hier_overflow.py and test_hier_pipeline.py. Under the CI's NCCL_P2P_DISABLE=1, its single-node DynamicEmb jobs are expected to stop where the Eos run with that setting stopped (Tests, above).

🤖 Generated with Claude Code

A new way to move keys and embedding rows for a row-wise sharded
EmbeddingCollection of DynamicEmb tables (HBM only, sequence lookups):
DynamicEmbTableOptions(output_dist="fused") with output_dist_capacity, or
output_dist="auto". It takes the place of TorchRec's input and output dists
and keeps TorchRec's sharding and awaitable interfaces (TorchRec 1.2 to 1.8).
Inside a node, data moves over NVLink. Between nodes, the GPU sends it over
InfiniBand itself (NCCL 2.30.7 GIN), always on its own rail.

- One static operator per sharding, HierOutputDist (src/hier_output_dist,
  dynamicemb/shard/hier_output_dist.py). It makes its buffers once, at the
  capacities lookup_keys and remote_keys. A call that does not fit takes
  TorchRec's dists, on every rank alike, with a warning that names the
  capacity to raise.
- Input dist: a key asked of another node goes over NVLink to the GPU of its
  node on the owner's rail (the proxy). The proxy sends each (owner node,
  table, key) of its node once over InfiniBand (node dedup). Seven comm
  kernels move the data and wait for peers. Every other step is ATen or CUB,
  called from C++ (the planner, src/hier_output_dist/plan). One host sync
  per call.
- Lookup: DynamicEmb's lookup writes its rows straight into the output
  dist's window, in the output dist's order.
- Output dist: one kernel forward and one kernel backward. They only move
  rows.
- Memory: apart from small tables, no buffer grows with the number of GPUs.
  The proxy's row buffer has a fixed cap (DYNAMICEMB_GIN_PROXY_MB); a call
  whose rows do not fit moves them in rounds.
- TorchRec's dists stay in use where this one does not run: a build against
  NCCL older than 2.30.7 (setup.py leaves the operator out; "fused" raises,
  "auto" uses TorchRec's dists), a sharding on one rank or with a table that
  is not a DynamicEmb table, eval forwards, and calls that do not fit.
- Trace: a build with DYNAMICEMB_HIER_TRACE=1 records the out kernels'
  timelines and the input dist's step times. Other builds compile it away.

Changes to DynamicEmb's lookup and tables:
- BatchedDynamicEmbeddingTablesV2.output_alloc says where the sequence
  output goes.
- A sequence lookup whose keys were all admitted loads each key's row
  straight into the output (load_from_flat_by): one kernel in place of a
  load and a gather.
- The counters of found and inserted keys take the slots of missing keys
  (-1) as they are, since the kernel skips them: no compaction and no host
  sync.
- PrefetchState.record_stream marks a prefetched batch's tensors as used on
  the stream of its forward and backward.

Tests (test/unit_tests/test_hier_*; test/unit_test.sh runs the one-node
scripts): outputs, gradients and tables against TorchRec's dists, the
fallback per call, and TorchRec's training pipelines.

Docs: docs/hier_output_dist.md (design), benchmark/README.md section 3 (how
to run the benchmark and what it measures), DynamicEmb_APIs.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
shijieliu and others added 27 commits November 1, 2026 07:00
… features

The dist has no static limit on the nodes, the GPUs per node or the
features of a sharding.

- The kernels keep no table sized by the ranks or the features. They read
  the call's small tables (Meta) and the requester's block starts from global
  memory, and reach a node peer's regions through its LSA pointer when they
  need them. The one per-peer array in shared memory is the backward's
  half_seen, sized at launch by local_size.
- A GIN warp's lane l serves the rail peers on nodes l, l + 32, ...: the
  forward's relay and owner issuer, the backward's proxy issuer and landing
  watcher, the credits, the rail comm kernels and teardown. The warps poll
  the peers in turn and wait for no single one; what a warp keeps of a peer
  between polls is in that peer's words in ctrl (put_at, relay_want). Node
  barriers and flags loop over the node's GPUs.
- The proxy's sort keys take their widths from the sizes: the tables are
  numbered densely, the identity tag is (owner node, table), the
  representative feature comes from an (identity, feature) key, and each
  field of the push key is as wide as its largest value. remote_cells is
  int32.

No table grows with nodes² × features or GPUs² × features:

- node_count_exchange sums the node's count vectors as it reads them: over
  the node, over the ranks before this one, and each requester's counts for
  this rank. That is all the node layout needs.
- A count message is a common part and a part for the receiver's node, sent
  in two puts. As owner, a rank sends each rail proxy where its node's cells
  start in its KJT (cell_stage into the proxy's rail_cells) in
  rail_key_exchange, beside the key records.
- One step (put_lists) makes both put lists, in one tensor: a node's keys
  cut at its IB chunks and at its feature cells, in (node, key) order, with
  a table of each (node, round)'s first segment per list. The lists hold at
  most chunks + 2 × nodes × features segments. The out kernels' issuers walk
  them per peer.

The op refuses only what its index types cannot hold: world_size ×
num_features of 2^31 − 1024 or more, or a push key wider than 63 bits.

Tests: test_hier_part1.py (300 features at up to 1024 ranks; node layouts
of 40 and 36 GPUs per node with 70 features, and of 40 nodes);
test_hier_dedup.py (the new exchanges; 70 features over several rounds, 36
nodes, 34 GPUs per node); test_hier_dist.py (80 features). Docs:
docs/hier_output_dist.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every buffer of the hierarchical dist owns its layout and gives its users
addresses by name and index; no other code computes where a buffer or a
word is.

- One NCCL window per op, laid out by WindowLayout as three sections, each
  a layout class built from the op's sizes (Sizes) over a base pointer:
  RowsLayout (lookup_rows, proxy_rows, push_flags), CtrlLayout (every
  control word, the count vectors and the count messages) and KeysLayout
  (node_keys, node_weights, remote_cells, remote_map, the proxy header,
  key_stage, rail_keys, cell_stage, rail_cells). The out kernels' sections
  come first, so their places take the least to compute. The host lays
  out its copy with the same code to size the window and to view its
  buffers as tensors; a kernel lays out its own copy. Kernel arguments
  carry the sizes, the window and ncclDevComm, and no offset table.
- A node peer's copy of a place is NodeWindow::peer(pointer, peer), and a
  GIN put takes pointers into this rank's copy for both of its ends
  (rail_put, RowPut, RailMessage). Node barriers and flags take their
  word's pointer.
- The call's small tables are plan tensors of their own, which the out
  kernels read through OutPlan's typed pointers and accessors (piece,
  push_entry, fwd_puts, bwd_puts, push_starts, round_piece); the plan lets
  go of the forward's own after the forward. A call across nodes makes 18
  small copies fewer.
- ProxyHeader, RemoteMap, CountVector and CountMessage give the word
  numbers of the formats the planner and the kernels share.

The outputs and gradients are bit-equal to the previous commit's.

Tests: test_hier_part1.py, test_hier_dedup.py, test_hier_dist.py,
test_hier_fallback.py and test_hier_pipeline.py unchanged but for the
binding names. Docs: docs/hier_output_dist.md (sections 2, 7, 10, 11, 13,
15 and 20), benchmark/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stream

The op queues each step of a call on the current stream, and has no
stream, event or thread of its own. The caller orders the steps, as
TorchRec's training loop and train pipelines do.

- The first wait queues the rest of the input dist (the comm kernels and
  the planner's steps) on the current stream. The second wait's one host
  sync is the copy of the call's status. It trims index dedup's tables
  with views, so nothing is queued after the sync.
- Removed: the side stream and its events, the pinned status buffer, the
  process-wide event of the last out kernel and its mutex, the first
  wait's wait for the out kernels that the previous first wait found
  issued (it bounded how far the CPU runs ahead; under the train
  pipelines the pipeline bounds it), the guard on the lookup's gradient
  (an atomic count and an event), the CTA budget class and its global
  count of live ops, and the input dist's step times in the trace. An out
  kernel takes min(want, SMs - 34) CTAs. A traced build still traces the
  out kernels.
- The output dist's forward records the plan on its stream, as the
  lookup does the KJT. TorchRec's fused pipeline with
  emb_lookup_stream="new" runs both on that stream, but records the
  sharding context on the default stream only. The output awaitable
  still makes the stream that waits on it wait for the forward kernel,
  as the awaitables of TorchRec's own dists do.
- src/hier_output_dist: 77 files in six folders become 24 in one
  (common.h, window.h, args.cuh, device.cuh, comm_kernels.cuh,
  out_kernels.cuh, forward.cuh, backward.cuh, kernels.h/.cu,
  config.h/.cu, planner.h/.cpp, part_one.cpp, proxy.cpp, sort.cu,
  plan.h/.cu, hier_output_dist.h/.cu, channels.cu, bind.cu, testing.cu).
  The code lines go from 6,793 to 6,011.

The outputs and gradients are bit-equal to the previous commit's.

Tests: test_hier_dist.py, test_hier_pipeline.py and the benchmark drop
the checks and trace rows of what was removed. test_hier_pipeline.py
checks that the status copy is in the second wait, and leaves the bound
on how far the host runs ahead to the pipeline. Docs:
docs/hier_output_dist.md (sections 1, 2, 4 to 7, 10, 11, 13 to 16, 19
and 20), benchmark/README.md, DynamicEmb_APIs.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lders

The steps of a call hand each other plain data: part_one() returns PartOne,
start() returns Pending, and wait() returns InDistResult, the owner's KJT
and the output dist's two plans. The forward kernel reads FwdPlan and the
backward kernel BwdPlan. Each holds only what the input dist made, and a
table both kernels read is the same tensor in both plans.

- Plan is gone, and with it after_start, after_forward and the backward's
  maps. The sharding context carries the result (hier_result) until the
  output dist's forward takes the plans: the forward's plan goes once its
  kernel is queued, and autograd keeps the backward's as saved tensors with
  its counts (BwdPlan.tensors(), counts() and of()), so it goes after the
  last backward and retain_graph still works.
- forward(fwd_plan, lookup_out) and backward(bwd_plan, grad, divide) take
  the lookup's output and the gradient beside the plan. The out kernels take
  FwdArgs and BwdArgs, each over what both take (OutArgs), with its plan as
  the kernel reads it (FwdPlanView, BwdPlanView). A kernel's scratch (the
  ready counts, the heavy rows' sums and counts) comes with its launch.
- src/hier_output_dist: the op's own files (the op, the bindings and the
  test bindings), and the folders common/, input_dist/ and output_dist/.

The outputs and gradients are bit-equal to the previous commit's.

Tests: test_hier_dist.py, test_hier_fallback.py and the benchmark read the
sharding context's hier_result. Docs: docs/hier_output_dist.md (sections
2, 4.2, 7.1, 7.3 to 7.5, 10, 10.2, 10.5, 11.1, 11.2, 16, 19 and 20) and
benchmark/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The planner's steps were chains of ATen ops; each is now one or a few
ordinary kernels. A kernel over items (keys, rows, occurrences) runs a
thread per item, a kernel over a step's small tables runs on one CTA, and
no kernel waits for another CTA. CUB still sorts, and now also scans. On
the benchmark's configuration a call launches, part 1 then the first wait,
11 + 9 kernels and copies on one node (28 + 38 before), and 11 + about 120
across nodes (28 + about 820 before). Its input dist segment takes 0.21 ms
where it took 0.36 on one node, and about 1 ms where it took about 3.5 on
2 and 4 nodes. A step of the plain loop is 2% to 46% shorter, and one of
TrainPipelineSparseDist 1% to 56% (uniform keys, and pow-law keys with
index dedup); both are now 20% to 47% shorter than on TorchRec's dists.

- input_dist/planner.cuh: what the planner's kernels share (their
  launches, searches in sorted tables, the starts of sorted runs, a CTA's
  scans); cub.cu: the radix sorts and the scan (exclusive_ends);
  part_one.cu, planner.cu and proxy.cu: the steps, whose interfaces in
  planner.h are those they had.
- One kernel writes the call's status, and takes the most of the node's
  needs itself (agreed_needs is gone).
- The proxy's reducer list holds 1 + local_size entries for a heavy key.
  With more GPUs per node than kHeavy that can pass its occurrences, so the
  list is now sized for it; it held remote_keys entries and cut off the
  last ones.

Each step's outputs are the same as before wherever they are read, and the
outputs and gradients are bit-equal to the previous commit's.

Tests: test_hier_dedup.py adds a node of 72 GPUs whose proxy has a heavy
key of fewer occurrences than reducer entries. Docs:
docs/hier_output_dist.md (sections 2, 7.3, 10, 13, 19 and 20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each kernel of the op takes the op's window and, when it uses GIN, its
device communicator (ncclWindow_t, ncclDevComm), the op's sizes (Sizes),
its sequence number when it waits for peers, and then its own data, each
as a parameter of its own. No struct inherits another to make one
parameter.

- ChannelStatic, CommArgs, OutArgs and Channel are gone. The comm kernels
  take their tensors as before. The out kernels also take the arrive word
  before them, and their call: FwdArgs or BwdArgs, which hold only the
  call's plan view and tensors (and the backward's gradient scale and
  reducer CTAs), with the kernel's row of the trace.
- Sizes holds how long a kernel waits for a peer (timeout_ns) and gives a
  row in 16-byte vectors (row_vecs). BwdPlanView holds the plan's counts
  (heavy_subs, group_subs).
- NodeBarrier and PeerFlags take the sizes, the node's window, their word
  and the sequence number; TaskQueue its task word; OutTimeline the trace
  row; OutTables the window, the sizes and the plan.
- InChannel and OutChannel keep the window, the communicator and the
  sizes; Python sees none of them.

The outputs and gradients are bit-equal to the previous commit's.

Docs: docs/hier_output_dist.md (sections 7.5, 11.1 and 20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er the capacities raises

The op's interface takes and gives tensors and plain values only, in its
constructor and three calls:

- HierOutputDist(unique_id, rank, world_size, ..., reduce_ctas) takes the
  configuration's fields. One it does not take throws ValueError, before
  any collective.
- input_dist(values, offsets, lengths, batch_size, weights, input_offsets,
  input_batch_size, reverse_indices) queues the whole input dist of a call
  at once (what part 1 and the first wait did), with no host sync. It
  returns the owner's KJT and lookup_rows at the capacity, the call's
  status on the device, and the plans as lists of their tensors.
- output_dist_fwd(fwd_plan, lookup_out) and output_dist_bwd(bwd_plan,
  counts, grad, divide) run one kernel each.

quiesce(), memory(), trace() and trace_launches() stay. The module has
hier_output_dist_unique_id, _unsupported, _invalid and _traced.

- Config, PartOne, Pending, InDistResult and the plans are no longer
  bound; capacities(), gin_railed() (now a warning of the constructor) and
  lookup_rows() go. The plans' tensors() and of() turn them into lists and
  back (FwdPlan's too), and FwdPlan derives its output rows (num_out()).
- The in channel launches its comm kernels from its own functions, on its
  window, device communicator, sizes and sequence number.
- The second wait (HierSharding.finish) copies the status to the host. A
  call that needs more than a capacity raises RuntimeError, on every rank,
  naming the capacity to raise. Such a call no longer falls back to
  TorchRec's dists, and the fallback counters go (HierSharding.fallbacks,
  the benchmark's fallback_calls). Eval forwards still take TorchRec's
  dists.
- The status carries the remote occurrences this rank deduplicated as
  proxy (the benchmark's) in place of the rows sent.
- The ranks compare the op's arguments one by one, so a difference names
  lookup_keys, remote_keys or proxy_bytes in place of the capacities.

The outputs and gradients are bit-equal to the previous commit's.

Tests: test_hier_fallback.py becomes test_hier_overflow.py: each large call
raises on every rank, and the small calls give TorchRec's outputs on the
small calls alone. test_hier_pipeline.py checks that each loop and pipeline
raises, and test_hier_dist.py's no-sync case raises, then takes a call that
fits. Docs: docs/hier_output_dist.md (sections 1, 2, 4.3, 5, 6, 7, 10,
10.5, 11.2, 12.2, 13, 15 to 20) and benchmark/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A proxy's proxy_rows is a ring, and its rows of a call are a stream of
chunks through it. A chunk is consecutive node-unique keys of one owner
node whose rows (key rows, duplicates' slots, heavy partials) fit
chunk_rows: 2 MiB, at most half the ring. The stream takes the owner nodes'
chunks level after level, each right after the one before; a stream that
does not fit the ring takes laps, and no chunk crosses the ring's end.
Every agent takes the chunks in stream order: the owners put them, the
requesters pull and push them, and the reducers sum them chunk after chunk.

Chunks are done with in order: in the forward once every requester of the
node pulled them (per-chunk pulled_rows words at the proxy), in the
backward once the NIC read their sums (GIN put counters, chunk % counters,
counters = min(max_chunks, 64), with at most that many chunks in flight).
A chunk's rows may be written once the first chunk not done with starts at
its end minus the ring or later: the relay grants the owners those rows
(grant = out_seq and a position of the stream), the issuer frees them for
the requesters (slot_free). The ring's first lap is free when every out
kernel starts, so a stream that fits the ring, the case whenever
remote_keys rows fit under the cap, waits for no grant or free.

This replaces the rounds: round pieces and the round table, the halves of
proxy_rows and their parity words, rounds_cap and its limit of 65536
rounds, the 90% fill, the least proxy rows of 20 * 64 * (num_nodes - 1),
and the IB chunks inside pieces. A chunk is the IB put unit now. The
requester's tables are per (proxy, chunk), its task starts per (chunk,
proxy in turn) with no empty slots, the push flags one array per call
tagged with out_seq, and the count message carries each proxy's chunks per
owner node. The least proxy rows are 4 * max_key_rows, whatever the nodes.

A node-unique key is heavy at its proxy with more than heavy_at
occurrences: 64, or local_size * partial_rows when that is more. A heavy
key then never takes more rows than it has occurrences. Before, with more
than 32 GPUs per node for 16-bit rows (64 for fp32), a heavy key of few
occurrences took more rows than them, so a call within remote_keys could
need more rows than the rounds held, and its rows could go past their half
or past proxy_rows. The reducer list now never has more entries than
occurrences. The status no longer carries the rounds.

Index dedup's heavy rows of other nodes copy on from their first original
row at a proxy whose stream wraps its ring, where they did at a proxy of
more than one round.

One CTA makes the stream's chunks: how many each owner node has, the
chunk table and where each chunk lies. Each chunk's pulls are summed as its
keys take their rows. The push key numbers a heavy key among the heavy
keys, so it is narrower. The proxy's push tables come from where each
requester's part of each chunk starts in the sorted push order, which the
pass that finds the heavy groups writes, with no searches; the requester's
tables take a thread per entry, and the owner's slices one CTA. So an input
dist launches as many kernels as with the rounds.

The outputs and gradients are bit-equal to the previous commit's, also
when the streams wrap the ring.

Tests: test_hier_dedup.py checks the chunks, where each lies, the stream's
laps, the flags and the put lists against references, with new cases of
one slot in two laps and of keys at heavy_at and past it on 72 GPUs per
node. test_hier_dist.py checks the least ring, and test_hier_pipeline.py
reads the status without the rounds. The benchmark reports the chunks per
call. Docs: docs/hier_output_dist.md (sections 1, 2, 5, 6, 7, 9, 10, 11,
12, 13, 15, 18).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nder TorchRec's names

What a call fixes before it runs is now a type or a template parameter,
picked once on the host, and the words the kernels pack are structs with
named fields:

* The KJT's keys, offsets and lengths are int32 or int64: the kernels that
  read them take the type as a template parameter (Key, Offset, Length),
  and with_index launches them with the tensor's dtype.
* Each owner rule is a type (CyclicRule, HashedCyclicRule, BlockRule).
  When every feature has one rule, place_keys_kernel takes OneRule<Rule>
  and has no branch; else MixedRules picks a feature's rule at run time.
  with_rules picks one of the two on the host.
* The key records are KeyRecord or WeightedKeyRecord (with_record picks
  one), the reducer list's entries ReducerEntry, remote_map's key rows
  MapKeyRow, what a requester gathers of its proxies GatheredMap and
  GatheredHeader, a chunk's ready word ChunkReady and a cut of the put
  lists CutKey; PushKey makes and reads the push key. Their bytes are the
  same as before.
* Node dedup (kNodeDedup), what peer_gather reads (kFrom), the pass a heavy
  row's sub-task runs in (kLate, kRemote) and whether a push leaves the
  node's own heavy rows to their sub-tasks (kLocal) are template
  parameters. The out kernels are named by an enum class, OutKernel.

The names follow TorchRec's bucketize: a bucket is an owner, and a bucket
feature is (bucket, feature). cell is bucket_feature, row_cell
bucket_feature_of_row, cell_start offset_per_bucket_feature, block_start
offset_per_bucket, remote_cells bucket_feature_of_occ and cell_uniq
uniq_per_bucket_feature. For the owner's KJT: own_cells and own_starts are
own_lengths and own_offsets, cells_in length_per_source_feature,
cell_stage source_offsets, rail_cells owner_offsets, my_cell_starts and
the ctrl words cell_start requester_offsets, and cell_record
record_offsets, now counted in records. Part 1 is the bucketize:
part_one.cu is bucketize.cu, Partition and partition_keys are
BucketizedKeys and bucketize_keys, and test_hier_part1.py is
test_hier_bucketize.py. HierCall.block_start is offset_per_bucket.

The outputs and gradients are bit-equal to the previous commit's at 1, 2
and 4 nodes, also when the streams wrap the ring.

Tests: the tests take the new names (hier_output_dist_bucketize, the
proxy's bucket_feature_of_occ). Docs: docs/hier_output_dist.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… alone

Index dedup leaves each rank each (table, key) of a call once, so a
node-unique key has at most local_size occurrences at its proxy, however
hot it is. The op now takes such keys alone, and the heavy keys of the
proxy go: a key takes a row per occurrence, max_key_rows is local_size.

* Setup: a sharding whose sharder has no use_index_dedup=True raises
  ValueError under "fused" and takes TorchRec's dists with a warning under
  "auto", at its first input_dist(). op.input_dist() takes input_offsets
  and reverse_indices as tensors; input_batch_size is gone (it is
  batch_size).
* Gone with the heavy keys: heavy_at, partial_rows, the partial rows of
  proxy_rows, the requester's heavy groups and their sub-tasks
  (group_subs, the group push tasks of bwd_kernel), the heavy bit of
  remote_map's key rows (MapKeyRow) and of the push key, and ReqEntry's
  heavy and groups fields. The forward has no read-once copy of shared
  sources, and both kernels lose their branches for calls without index
  dedup. Index dedup's own heavy rows (thousands of original rows on one
  rank) keep their sub-tasks.
* Simpler tables: the push key is the occurrence's part, requester *
  (max_chunks + 1) + chunk (PushKey and its 63-bit refusal go); one
  task_starts serves the forward's pulls and the backward's pushes; the
  reducer list is an int32 flag per row of each key (ReducerEntry goes): a
  key's rows are its key row, then its duplicates' slots, which the reducer
  finds from reducer_start (the rows before each key), in the same order as
  before; the duplicates' slots come from the rows' scan (one scan fewer).
* The owner's KJT carries weights exactly when the keys do: the
  occurrence counts sent as weights for LFU tables without input weights
  (out_weights, counts_as_weights and the lookup's per-group weight
  stripping) go, as index dedup gives LFU and admission their frequency
  counters.
* A guard: a proxy that gets one key more than local_size times (keys that
  were not index-deduplicated) gives it local_size rows, so the input dist
  stays in bounds, and reports it as a need (key_rows, beside lookup_keys
  and remote_keys); the call's second wait raises RuntimeError on every
  rank.
* TorchRec's path in DynamicEmb deduplicates int32 keys as int64 too, as
  the hierarchical dist's did: an eval forward of an int32 model on
  TorchRec's dists no longer raises under index dedup.

Under index dedup the outputs and gradients are bit-equal to the previous
commit's at 1, 2 and 4 nodes, uniform and power-law keys, also when the
streams wrap the ring (32 MiB). max_key_rows goes from 64 to 8 at 8 GPUs
per node: a chunk takes more keys, and the ring's least is 4 * local_size
rows.

Tests: test_hier_dedup.py's jobs are index-deduplicated, with keys of
local_size occurrences and calls past it; test_hier_dist.py,
test_hier_overflow.py and test_hier_pipeline.py run under index dedup, and
a model without it is refused ("fused") or falls back ("auto").
Benchmark: --output_dist fused or auto and --check need
--use_index_dedup. Docs: docs/hier_output_dist.md, benchmark/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s pushed rows

A chunk's rows at the proxy are its keys' occurrences, one row each, and
each requester's push tasks write the rows of their occurrences: the
pushes of a chunk fill its end - start rows once. So the proxy counts the
rows pushed into each chunk in one word, and its reducers wait until the
chunk's count reaches its rows, in place of a flag per push task and a
list of the flag of each row.

* The ctrl section gets pushed_rows[max_chunks] (across nodes), beside the
  forward's pulled_rows. The backward's CTA 0 zeroes the call's chunks'
  counts with their ready counters, before this rank publishes its
  out_seq: the node's pushes come after the entry barrier, and the previous
  backward's were all in once its reducers saw their counts.
* A push task adds its rows to its chunk's count at its proxy, one release
  add after the warp's stores (count_pushed_warp). A reducer task waits for
  its chunk's count with an acquire load in lane 0, then sums as before.
* Gone: push_flags (the window's flag words, Sizes::flag_words and its
  int32 refusal); ReqEntry, as a push table entry is its start position
  alone (the proxy header's push tables take half the words); the flag
  numbering of push_tables_kernel and push_positions_kernel; reducer_flags
  and its kernel (the plan's backward tensors lose it); the requester's
  req_of.

The reducers wait for a whole chunk in place of their keys' push tasks;
the issuer waits for the whole chunk's sums anyway. Outputs and gradients
are bit-equal to the previous commit's at 1, 2 and 4 nodes, uniform and
power-law keys, also when the streams wrap the ring (32 MiB).

Against the previous commit (the benchmark's configuration, medians of 4
rounds of alternating order on the same nodes, 8 H100 per node), a step
of the plain loop is 1.9% and 1.5% shorter on 2 nodes (uniform and
pow-law keys), and 1.2% longer and 0.2% shorter on 4 nodes; the backward
kernel moves by -2.9%, +0.7%, +1.5% and -0.9%, the input dist by -10.6%,
-5.1%, +0.9% and -2.1%. On 4 nodes with uniform keys the backward waits
for its reducers (8 CTAs by default), which now start a chunk once all of
its rows are in.

Tests: test_hier_dedup.py checks that each chunk's pushes count its rows
exactly and fill each of its rows once. Docs: docs/hier_output_dist.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rank-level ones

The proxy's node dedup is index dedup over its node's occurrences, and its
keys sorted by bucket feature (owner node, feature) are the bucketize's, a
bucket being an owner node. Its tables now take the requester's names with
a node_ prefix, so each one points at its rank-level twin:

* uniq_off -> node_offset_per_bucket, uniq_out -> node_length_per_bucket,
  uniq_per_bucket_feature -> node_length_per_bucket_feature, and in
  proxy.cu key_offset_per_bucket_feature -> node_offset_per_bucket_feature
  and bucket_feature_of_key -> node_bucket_feature_of_row;
* reducer_start and ProxyChunks::row_ends -> node_exp_off: the rows before
  each node-unique key, as index dedup's exp_off holds the original rows
  before each deduplicated row;
* ProxyKeys::key_value -> node_uniq_keys (node_keys stays the window
  buffer the node pushes its keys into);
* the test binding's key_of_occurrence -> node_reverse_indices.

The out kernels' local node_offset_per_bucket (the requester's
offset_per_bucket of its node's owners) becomes local_offset_per_bucket.
In Python, HierCall.uniq_out becomes node_length_per_bucket (the
benchmark's traffic count reads it). planner.h and docs/hier_output_dist.md
(section 10.4) say how the names pair up.

Names only: outputs and gradients are bit-equal to the previous commit's
at 1 and 2 nodes, with uniform and pow-law keys under index dedup, also
when the streams wrap the ring (32 MiB). test_hier_bucketize.py and
test_hier_dedup.py pass, and so do test_hier_dist.py at 1 and 2 nodes (at
2 also with a 1 MiB ring), test_hier_overflow.py and
test_hier_pipeline.py --megatron at 2 nodes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…data they hold

A table that holds data from another step is now named after that data
where it came from, with a prefix for where it is:

* The requesters push their keys, key_weights and bucket_feature_of_row
  into node_keys, node_key_weights (was node_weights) and
  node_bucket_feature_of_row (was bucket_feature_of_occ); the proxy's
  input (ProxyInput) and the in channel's views of those buffers take the
  same names.
* Node dedup gives node_unique_keys (was node_uniq_keys), node_num_uniques
  (ProxyKeys::num_keys) and node_unique_key_weights (key_weight), after
  index dedup's unique_keys and num_uniques; its sort by owner node gives
  node_bucket_feature_of_unique_row (was node_bucket_feature_of_row), the
  bucket feature of each node-unique key.
* A proxy's chunks per owner node, its bucket: chunk_length_per_bucket
  (chunks_out), chunk_offset_per_bucket (node_chunk_start) and chunk_inv
  (node_chunks: each chunk's place in the stream, in bucket order, as inv
  holds each sorted row's KJT row); stage_offset_per_bucket (stage_slice),
  where each owner node's slice starts in key_stage.
* An owner keeps the proxies' counts as node_length_per_source (uniq_in)
  and node_length_per_source_feature (length_per_source_feature), and a
  requester the proxies' push tables as proxy_push_tables, beside
  proxy_chunks and proxy_ends (the proxy's own push_tables keep their
  name).

In Python, HierCall.uniq_in becomes node_length_per_source.
docs/hier_output_dist.md (section 10.4) lists the names.

Names only: outputs and gradients are bit-equal to the previous commit's
at 1 and 2 nodes, with uniform and pow-law keys under index dedup, also
when the streams wrap the ring (32 MiB). test_hier_bucketize.py and
test_hier_dedup.py pass, and so do test_hier_dist.py at 1 and 2 nodes (at
2 also with a 1 MiB ring), test_hier_overflow.py and
test_hier_pipeline.py --megatron at 2 nodes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nce they are ready

The out kernels' workers took their tasks from one queue in a fixed order:
the forward the rows of the node's owners first, then the rows that cross
nodes, chunk after chunk; the backward the other way round. When a proxy's
stream wraps its ring, a remote task may wait for its chunk (the forward
until it has landed, the backward until its rows of the ring are free).
So the forward's local rows held back the pulls that empty the ring, and
the owners waited for their grants; the backward's local rows waited
behind pushes that wait for the ring.

Now each kernel takes its tasks from two queues (ReadyFirst): the local
tasks and, across nodes, the remote ones. A warp takes the next remote
task when it would not wait (the forward: its chunk has landed; the
backward: a sub-task, or a push whose rows are free), else a local task,
and the remote ones in turn once the local ones are taken. Each queue
keeps its order, so no task waits for a later one of its queue.

benchmark/README.md gets a large-batch workload (25 million keys per GPU,
bf16), whose rows take several laps of the ring.

The order changes no sum: outputs and gradients are bit-equal to the
previous commit's at 1, 2 and 4 nodes, with uniform and power-law keys
under index dedup, also when the streams wrap the ring (32 MiB).
test_hier_bucketize.py and test_hier_dedup.py pass. test_hier_dist.py
passes at 1 and 2 nodes, at 2 nodes also with a 1 MiB ring, and at 4 nodes
with a 1 MiB ring. test_hier_overflow.py and test_hier_pipeline.py
--megatron pass at 2 nodes.

On the large batch at 2 nodes (6 laps of the 512 MiB ring), the forward
kernel takes 3.3% less time and the backward kernel 7.2% less (49.0 and
48.9 ms against 50.7 and 52.7 ms, A/B on the same nodes). At 4 nodes the
NICs move rows nearly all the time, and the times do not change. On the
standard benchmark across nodes, the forward kernel takes 0.4% to 2.6% less
time and the backward kernel up to 1.2% more (the look at the next remote
task before a warp takes one). One node does not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s of their own

Index dedup's heavy rows (more than kHeavy original rows) had their
gradients summed inside the backward kernel: sub-tasks of kHeavy original
rows into fp32 partials, the remote ones first in the queue, the local ones
among the row tasks. Then one warp added a row's partials: the push of the
row, or the last sub-task of the row. For a very hot key (a million
original rows on one GPU, 19,000 partials), that one warp took milliseconds,
and the chunk of the key waited for it.

Now two kernels run before the backward kernel when the call has heavy
rows. bwd_heavy_kernel sums each sub-task's original rows into its
partial. A group of lanes does a sub-task: one lane per 16-byte vector of a
row, at most 32, each with 8 rows in flight. bwd_heavy_sum_kernel adds each
heavy row's partials in sub-task order into its first one. A CTA does a
row, and a thread does a value with 16 partials in flight. The backward
kernel reads that sum, scales it and rounds it once, as before. Each sum
keeps its order, so the gradients do not change. The kernels wait for no
peer and can use all SMs. They use the same partials as before, so they add
no memory. The kernel boundary orders them, so they need no done counters.

The backward kernel loses the sub-tasks, their slots in both queues and the
waits for them. Its spills go down from 202/688 to 174/632 bytes (bf16) and
from 190/680 to 122/376 bytes (fp32) per thread; the new kernels spill
none. The benchmark adds the new kernels to the backward's kernel time, and
the pipeline test lets the backward launch them.

Outputs and gradients are bit-equal to the previous commit's at 1, 2 and 4
nodes, with uniform and power-law keys under index dedup, also when the
streams wrap the ring (32 MiB). test_hier_bucketize.py and
test_hier_dedup.py pass. test_hier_dist.py passes at 1 and 2 nodes, at 2
nodes also with a 1 MiB ring, and at 4 nodes with a 1 MiB ring.
test_hier_overflow.py passes at 2 nodes, and test_hier_pipeline.py
--megatron at 1 and 2 nodes.

The backward's kernels take 23% less time on the large batch with
power-law keys at 4 nodes (22.8 against 29.6 ms), 6.8% less on the
standard benchmark with uniform keys at 4 nodes, and 3% to 5% less with
power-law keys at 2 and 4 nodes. On one node with power-law keys they take
17% more (0.43 against 0.37 ms): there the heavy rows' sums no longer
overlap the pushes over NVLink.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r spills

The out kernels had register spills (ptxas -v, sm_90): 174 / 632 bytes of
spill stores / loads in bwd_kernel (bf16, fp16), 122 / 376 (fp32), and
44 / 56 in fwd_kernel across nodes. With 512 threads for each CTA, a
thread has 128 registers at most.

- The out kernels are built once for each GIN backend (proxy, GDAKI, GPI)
  and once for one node, which uses no GIN. NCCL compiles each GIN call
  for all its backends and selects one at run time; this code used most
  of the registers. gin_context gives a GIN context whose backend is a
  constant, so each build keeps the code of one backend. The communicator
  checks that all its GIN contexts have the same backend (gin_type), and
  the out channel launches the kernels of that backend. On one node, the
  backward kernel is now also built without the code for several nodes,
  as the forward kernel was.
- Across nodes, the pulls of the forward keep 4 vectors of 16 bytes in
  flight per lane (8 before; still 8 on one node). The task loop then has
  the registers of its multi-node paths. NVLink moves the rows as fast
  with 4 vectors in flight as with 8.
- The timeout report of a wait is a separate function (timed_out). When
  it was inline, its printf used registers at each wait.
- As DeepEP does for a QP that one SM uses, the issuers use their rows
  contexts in CTA sharing mode: only the issuer warp of CTA 0 uses these
  QPs. In GPU mode, each put took its QP slots with GPU-scope atomics and
  a GPU-scope acquire fence, which drops the L1 cache of the SM. The
  backward's issuer also polls the credits and the chunks' ready words
  with relaxed loads (the fence before each chunk's puts orders them):
  without spills its loop polls faster, and each acquire load dropped the
  L1 cache of the other warps of CTA 0, which made the backward 7% slower
  at 4 nodes.

ptxas -v now shows 0 bytes of spill stores and loads for each out kernel
of each backend, for sm_75, sm_80, sm_90, sm_100 and sm_120 (CUDA 13.2).
The results are the same bit for bit, with the GDAKI and the proxy
backends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s in turn

A proxy's stream takes its chunks level after level. In a level, the owner
nodes came in node order. The agents of all nodes take their streams in
order at about the same pace, so at a place of a level the proxies of a
rail served the same owner node at the same time. In the backward the NIC
of that node took the puts of several proxies, and in the forward of a
stream that wraps the ring it sent to several proxies, while the other
NICs of the rail were idle (incast). DeepEP turns its RDMA peers against
this: each rank starts from a different peer.

- In a level, the owner nodes now come in turn from the node after the
  proxy's own (node + 1, node + 2, ... mod num_nodes). At a place of a
  level, the proxies of a rail then serve different owner nodes.
- benchmark/gin_rail_congestion.cu measures incast on the rails with GIN
  puts. Each GPU sends a stream of 2 MiB chunks to the GPUs of its rail on
  the other nodes, in node order and in rotated order, with a window of
  chunks in flight. On H100 nodes, node order takes up to 1.32x the
  rotated order's time on 4 nodes and up to 1.66x on 8 nodes (window 2).
  With all chunks in flight it takes 1.00x and 1.02x.

With the benchmark's configuration (--use_index_dedup, uniform and
power-law keys), the backward kernel takes 0.4 to 1.6% less time on 4
nodes and 6.0 to 7.7% less on 8 nodes, and a step 2.7 to 3.1% less on 8
nodes. The forward kernel and a large batch take the same time. The
results are the same bit for bit on 1, 2, 4 and 8 nodes, also with a
32 MiB ring and with the proxy backend (4 nodes). On 8 nodes the bitwise
check takes keys from half of each table: with all keys, a few keys of
full table buckets get zero rows in the first forward, also on TorchRec's
dists, and which keys changes from run to run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ules at run time

The bucketize took the owner rule (dist_type) as a type when all features
had one rule (OneRule), and read each feature's rule at run time when they
did not (MixedRules). To select the kernel, the op copied the rules to the
host when it was built. The rules of a sharding do not change after it is
built, so this selection gained little, and it needed 8 builds of the
kernel.

- The kernel reads the rule of each key's feature at run time, for all
  rules: one build for each key type. A warp's keys are consecutive, so
  all but a few warps take one branch.
- OwnerRules has no host copy of the rules, and the op does not copy them
  to the host.
- bucketize_keys checks that the rules are int32 and int64 on the GPU of
  the keys.

On 4M keys (H100), the kernel takes 0.2 to 2.2 us more for each rule and
key type, and 5.0 us more for int64 keys under hash_roundrobin (44.6 to
49.6 us). The bucketize takes at most about 2% more. In the op (2 nodes),
the median input dist of a call takes the same time. The results are the
same bit for bit on 1, 2 and 8 nodes. The peak memory of the bucketize is
32 bytes per key for all rules; the doc said 25 for one rule and 67 for
three.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e's keys from the gathered offsets

The node phase took five kernels and the bucketize's gather. count_vector
packed each rank's offset_per_bucket_feature into a count vector per GPU
of its node, node_count_exchange gathered the count vectors (the node
barrier), node_layout computed where each key goes, the bucketize gathered
the keys into bucketized order, node_key_push pushed them into their
targets' node_keys, and node_done told the node. On one node, three more
kernels made the owner's KJT offsets, its map (src) and the copy of its
own part.

- node_exchange (1 CTA) stores this rank's offset_per_bucket_feature into
  its row of node_offsets at every GPU of its node, over NVLink, and passes
  the node barrier. Every rank then computes the node layout from
  node_offsets alone (node_layout_of, in the new input_dist/node.cuh).
  There is no count vector.
- node_key_push is the bucketize's gather. It reads each row's key in the
  KJT's order (stored[inv[row]]) and stores it straight to its place,
  destination_base[bucket feature] + row, in its target's node_keys. On
  one node it also writes each row's place in its owner's KJT (src).
- node_done tells the node that the keys are there. It also guards
  node_offsets: a rank stores its next offsets only after every peer told
  it, and a peer tells only after its node_exchange read them.
- Across nodes the node phase takes 3 kernels, on one node 4 (with the
  copy of the own part into the owner's KJT). The window gains
  node_offsets, local_size x (world_size x num_features + 1) words (16 KB
  at 4 nodes of 8 GPUs and 8 features), and the ctrl section loses the
  count vectors.
- The test hooks take the node's offsets (hier_output_dist_node_layout)
  and push into stand-ins for the targets' node_keys
  (hier_output_dist_node_push). hier_output_dist_delay_node_reads makes a
  rank read the node's offsets and keys late (test_hier_pipeline.py's skew
  case).

On one node (8 H100s, the benchmark's 8-table configuration with index
dedup), the input dist takes 41 launches per call instead of 46, and
0.358 ms instead of 0.373 ms. The results are the same bit for bit on 1,
2 and 4 nodes, also with a 32 MiB ring. The next commit updates the doc
for this commit too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… by default

A chunk of a proxy's stream held at most 2 MiB of rows. Smaller chunks
start the stream's pipeline earlier, but chunks of 512 KiB of rows made
the out kernels up to 16% slower (the backward on 4 nodes with a 32 MiB
ring; 11.7% at 2 nodes with power-law keys). Two changes remove that, as
DeepEP does it:

- The issuers of the out kernels.
  - The backward's issuer polls a window of up to 8 chunks (kIssueWindow)
    from the first one not yet put, with relaxed loads, and makes one
    fence.acq_rel.sys per pass instead of one per put.
  - The read check frees the ring (slot_free) once per pass. The relay
    grants each owner node once per pass, and it publishes the chunks'
    landed words with relaxed stores after one fence. The owner's issuer
    reads its grant once per pass.
  - On GDAKI the issuers use the THREAD sharing mode: one lane posts on
    each QP, without atomics or a lock.
- Chunks sized by their IB payload. A node-unique key has a ring row per
  occurrence but sends one row over IB. Each key now weighs max(rows, c),
  with c the ring rows of 2 MiB over the payload's rows (4 at 512 KiB),
  and the levels are cut by weight. A chunk still holds at most 2 MiB of
  ring rows. A chunk of hot keys then moves about what it moved at 2 MiB,
  and a chunk of cold keys 512 KiB.
- Config::chunk_kb (DYNAMICEMB_GIN_CHUNK_KB: 512 by default, at least 64
  and a multiple of 16) sets the payload, and the ranks compare it. A
  value of 2048 or more gives the old chunks.

With the benchmark's configuration (8 H100s per node, index dedup), the
out kernels at 512 KiB take, against 2 MiB before this commit (forward /
backward): +0.2% / +0.5% on 2 nodes with uniform keys and +0.3% / +0.3%
with power-law keys; -0.2% / -2.5% and -1.3% / -5.1% on 4 nodes; 0.0% /
-1.7% with a 32 MiB ring; +0.1% / -0.1% for a large batch with power-law
keys. A step takes the same time or less. The input dist takes 4 to 12%
more than at 2 MiB, because its planner's tables are sized by the most
chunks of a call. The results are the same bit for bit on 2 and 4 nodes,
also with a 32 MiB ring.

The doc now describes this commit and the node phase of the previous one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The continuous rule ("continuous", kBlock) stores a key as its offset in
its owner's block, so equal stored keys of two owners can be different
keys. For this rule alone, node dedup kept the owner node in each key's
identity, and the bucketize kept the stored keys apart from the KJT's.

- Config::validate refuses every rule but roundrobin and hash_roundrobin,
  and a table whose features have different rules. Under
  output_dist="fused" the sharding raises ValueError; under "auto" it
  warns and takes TorchRec's dists. DynamicEmb's other paths keep the
  continuous rule.
- BlockRule and the block sizes are gone. The op takes the rules as host
  codes (dist_types).
- The bucketize keeps no stored keys. The push reads the KJT's keys, and
  widens an int32 key with its sign.
- Node dedup's identity is (table, key). A table has one rule, and both
  rules keep the key, so equal keys of one table have one owner. The GPUs
  of a node must give keys of one dtype in a call (an int32 key and the
  same int64 key can have different owners), as TorchRec's dists need on
  every rank.
- Tests: the refusal and the fallback, a case with a rule per table, and
  a node case with int32 keys.

The results are the same bit for bit on 2 and 4 nodes, also with a
32 MiB ring, and the input dist takes the same time (-0.5% to +0.5%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rail took two rounds and seven launches: count_message,
rail_count_exchange (each rail peer got a common part and the part for
its node), rail_layout, a copy of source_offsets into the window,
rail_key_exchange (each proxy put its key slices to its owners, each owner
put its source_offsets back to its proxies, and every rank waited for its
keys), status_publish and node_status_exchange.

- rail_exchange (1 CTA) puts one message to every rail peer: this rank's
  node-unique keys per (owner node, feature) as proxy, its own part per
  feature as owner, its chunks per owner node and its needs. Every rank
  then computes the whole rail layout from the messages
  (input_dist/rail.cuh). A proxy computes where its keys start in each
  owner's KJT (owner_offsets) with the function the owner uses for its
  source_offsets, so no owner sends them back.
- rail_key_push puts the key slices and does not wait. rail_done waits for
  every rail peer's keys and flushes, just before owner_tables, the first
  reader of rail_keys. So the key round overlaps the planner's steps
  between them.
- node_status_exchange reads the needs and requester_offsets from the
  layout. status_publish and the window's source_offsets and
  owner_offsets are gone.
- A message holds num_nodes x num_features counts. A rank sends 13 KiB per
  call at 8 nodes and 26 features, and 201 KiB at 16 nodes and 100
  features. The doc gives the limits.

With the benchmark's configuration (8 H100s per node, index dedup), the
input dist takes 3 launches fewer per call (126 at 2 nodes), and 0.883 ms
instead of 0.929 ms on 2 nodes (-4.9%), 0.979 ms instead of 1.050 ms on 4
nodes (-6.7%), and 2.5% and 3.4% less with power-law keys. A step takes
0.6 to 2.2% less. The results are the same bit for bit on 2 and 4 nodes,
also with a 32 MiB ring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne kernel after the sort

Index dedup's fan-out tables took ten launches after the sort of the
reverse indices: run_starts for exp_off, heavy_counts_kernel, two CUB
scans that numbered the heavy rows and their sub-tasks in row order,
heavy_rows_kernel and heavy_subs_kernel.

- fanout_runs_kernel makes the tables in one launch, a thread per sorted
  position. The first position of each row's run writes exp_off for the
  row and for the rows without original rows before it. Grid-wide loops
  take the rows before the first run and after the last.
- A run of more than kHeavy (64) positions is a heavy row. Its warp finds
  where the run ends, 32 probes per round: one round for up to 96
  positions, seven for a million. The run's first thread reserves the
  row's slot and its sub-tasks with one 64-bit atomicAdd. The old word's
  high half is the slot and its low half the first sub-task, so
  consecutive slots have consecutive sub-task ranges. The warp writes the
  sub-tasks, 32 at a time.
- The kernel's last CTA out writes count and sets the counter and its
  ticket back to 0. No CTA waits for another. The in channel keeps the two
  words from call to call.
- original_rows_kernel also writes position_of, where the bucketize put
  each row.
- The slots now come in the order the heavy rows reserve them, which can
  change from run to run. No sum depends on that order: a heavy row's
  sub-tasks stay consecutive and in original-row order. The bucketize test
  compares the heavy tables per row, checks that the two words are 0 again
  after each call, and adds a very hot row and rows before the first run.

With the benchmark's configuration (8 H100s per node, index dedup), the
input dist takes 9 launches fewer per call (32 on one node, 117 on 2
nodes), and 0.318 ms instead of 0.358 ms on one node (-11.1%), 0.841 ms
instead of 0.884 ms on 2 nodes (-4.9%), and 13.0% and 5.1% less with
power-law keys. A step takes 0.4 to 4.0% less. The results are the same
bit for bit on 1, 2 and 4 nodes, also with a 32 MiB ring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hift

The node layout's destination_base was no base: bucketized row `row` of
bucket feature b goes to place row + destination_base[b] in its target's
node_keys, and destination_base[b] is where this rank's rows of b start
there less where they start among its own rows (offset_per_bucket_feature
[b]). So it is often negative, and the name read as a block's start.

- It is row_shift now, in the code, the hooks (their output key and
  argument name), the tests and the doc. The comments and the doc say what
  it holds and why one add places a row: the push, the one-node src and
  remote_rows read it per row, and the subtraction happens once per bucket
  feature when the layout is made.
- No value changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h insert

Node dedup at the proxy took 44 launches per call at 2 nodes: three CUB
radix sorts (the occurrences by their 64-bit key, then by table, then the
identities by bucket feature; 32 launches), a scan, run_starts and eight
kernels, all over the remote_keys capacity.

- One insert finds each occurrence's identity (table, key): open
  addressing over at least twice remote_keys slots, a slot claimed with
  atomicCAS. The slot is the high bits of a seeded fmix64 of the key and
  the table: the owner rules fix bits of key % world_size or of
  fmix64(key) % world_size, which a proxy's keys of one owner share.
- On the identity, integer atomics whose results do not depend on their
  order: its representative (the occurrence of the smallest bucket
  feature, then of the smallest index; atomicMin), its occurrences, its
  weights, and a list of its occurrences.
- A scan of the representatives numbers the node-unique keys by owner
  node, then smallest feature, then their representative's occurrence (was:
  key order); one CTA gives each (requester, bucket feature) block its base.
  An occurrence's rank among its key's occurrences, from the list, is the
  same as before, so every sum keeps its order.
- 8 launches with node dedup, 3 without. The step holds about 52 bytes
  per remote_keys entry (64 with weights) where the sorts held about 79
  (99).
- test_hier_dedup.py's reference follows the new numbering. Its two-laps
  cases let requester 0 ask every key, as the keys are now numbered in the
  first requester's order.

With the benchmark's configuration (8 H100s per node, index dedup), the
input dist takes 81 launches per call at 2 nodes instead of 117, and 0.650
ms instead of 0.840 ms at 2 nodes (-22.6%), 0.719 ms instead of 0.935 ms at
4 nodes (-23.1%), and 21.1% and 20.8% less with power-law keys. A step
takes 0.7 to 5.3% less; the output dist's backward kernel takes 0.8 to 1.3%
more. The results are the same bit for bit on 1, 2 and 4 nodes, also with
a 32 MiB ring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s chain insert

Index dedup's segmented_unique_core and the proxy's node dedup each had a
hash insert of their own.

- dedup_chain.cuh (new) holds MurmurHash3_32 and segmented_unique_core's
  lock-free tail-append chain insert, moved verbatim: a bucket's chain of
  input indices, a claim at the tail with atomicCAS, a loser walking on from
  the winner's node. segmented_unique_core calls it. Its SASS is
  bit-identical on sm_75, sm_80, sm_89 and sm_90; on sm_100 and sm_120 the
  walk loop has one register move fewer.
- The proxy's insert calls it too, in place of its open addressing: one
  shared space of at least 2 x remote_keys buckets and (table, key)
  equality. The bucket is still the high bits of its seeded hash, and an
  identity is the chain node that claimed it.

With the benchmark's configuration (8 H100s per node, index dedup) the
input dist takes 81 launches per call as before, and 0.2 to 0.8% less time
at 2 and 4 nodes (the insert kernel 18.7 us instead of 20.2 at 2 nodes).
test_unique_op.py passes, and the results are the same bit for bit on 1, 2
and 4 nodes, also with a 32 MiB ring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the requesters in turn

Since the hash dedup the proxy numbered the node-unique keys of an (owner
node, feature) requester after requester, each requester's in its order.
With uniform keys most keys have one occurrence, so a chunk's pushes came
from about 3 of a node's 8 requesters, one of them about half; the output
dist's backward kernel, whose chunks complete when all their pushes are
in, took 0.8 to 1.3% more than under key order.

- Under node dedup the requesters now take turns inside each (owner node,
  feature): the k-th key of every requester comes before the (k+1)-th of
  any. u = the bucket feature's first key + sum over r' of
  min(k, reps(r', b)) + #{r' < r : reps(r', b) > k}, O(local_size) per
  occurrence; the base table goes. On hier_sim's model of the benchmark a
  chunk draws from all 8 requesters again, the largest share 13% (was 51%).
- The ranks, and so every sum's order, do not change. Without node dedup
  the keys keep their numbering: there turns would let a key's rows reach
  the owner in an order that changes from run to run.

With the benchmark's configuration (8 H100s per node, index dedup) the
backward kernel takes 1.4% less at 2 nodes and 0.8% less at 4 nodes with
uniform keys, and 0.2 to 0.3% less with power-law keys. key_tables takes
16 us instead of 9, so the input dist takes 0.4 to 1.3% more; a step takes
from 0.8% less to 0.4% more. The results are the same bit for bit on 1, 2
and 4 nodes, also with a 32 MiB ring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
shijieliu and others added 11 commits November 11, 2026 00:33
… Systems

- --nvtx: NVTX ranges of each timed iteration ("iteration i", with its
  "forward" and "backward", or the whole progress() under a pipeline)
  and of the benchmark's stage ranges (bench::input_dist and the like),
  in every iteration rather than only while the PyTorch profiler runs;
  and the timed iterations between cudaProfilerStart and
  cudaProfilerStop, so that nsys profile -c cudaProfilerApi
  --capture-range-end=stop captures them alone.
- --nvtx_ops: with --nvtx, also an NVTX range per PyTorch op of the
  timed iterations (emit_nvtx), the backward's autograd nodes included;
  their host time is then in the timings.

Without them nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cudaProfilerStart

Under nsys only the profiled rank's cudaProfilerStart starts a capture, which
takes 1 to 2 s; the other ranks went on into their first timed forward and
waited it out in the dists' kernels, so a profiled run's fwd_ms_mean read 86 to
216 ms. A barrier after cudaProfilerStart lines the ranks up before the timed
iterations: on GB300 the captures with it show the barrier's all-reduce once
before the first timed iteration, and fwd_ms_mean reads 2.7 to 15.5 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…all features

TorchRec's construct_jagged_tensors splits the EC's rows into a JaggedTensor
per feature: a view, a JaggedTensor and a row of lengths per feature, host
work that grows with the features (about 4 ms of the step at 1,024 features on
GB300), the same for every dist, and in the backward a cat of the features'
gradients. The benchmark now replaces it with one that keeps the rows whole, in
the input's order; TorchRec's expansion of index dedup (an index_select by the
reverse indices) stays. The injected gradient goes to the rows in one autograd
edge. --check compares the one output. The README's many-features tables were
measured before and hold that work; it now also says to capture a run's own
options (above all its iterations and warmup) to read its numbers in nsys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as the installed TorchRec does

TorchRec 1.6 and earlier cast index dedup's reverse indices to int32 before
their index_select; from 1.7 on (the image's 1.8.0) they take them as they are.
The flat output cast them always, a kernel TorchRec 1.8 does not run (well
under 1% of TorchRec's step). It now reads the cast from the installed
TorchRec's construct_jagged_tensors. The README's stages row says bwd/other is
empty in the benchmark's model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ff in the timed iterations

With TorchRec's per-feature output at 1,024 features, every 20-iteration run
of the hierarchical dist on GB300 stalled at the same two timed calls (16 on
ranks 1-15, 18 on rank 0), 80 to 140 ms each, on four racks. gc.callbacks
logged full (gen-2) collections of that length started inside
construct_jagged_tensors, and with the collector off for the whole process
those two stalls did not occur (26.2 to 9.8 ms per step on the same trays,
smaller stalls included). A collection falls at the same call on every rank
with the same history, and the ranks' collective kernels wait for a rank that
pauses. The benchmark now collects once after the warmup, before the ranks
meet in the barrier (so they start the timed iterations together however
long theirs took), keeps the collector off until the timed iterations end,
and then restores it; --timed_gc on keeps it on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nts after a warmup without syncs

The timed iterations used to follow a device sync, a collection and a
barrier, and rank 0's host clock timed them. On 2 and 4 Eos nodes a rank was
then 1 to 5 ms late at the first timed calls in most runs, which added up to
0.48 ms to the hierarchical dist's step; the runs under --nvtx, with one
more barrier, had none of it.

Now the first call runs alone: it makes the dists' state, and its memory is
measured. The ranks then meet in a barrier, and the warmup (--warmup, 20
iterations) and the timed iterations (--num_iterations, 20) run back to
back. Nothing of the benchmark's between them syncs the host with the GPU,
so the timed iterations follow the warmup without a pause and the ranks
reach them in step. The dists and the lookup keep their own host syncs in
every call.

One CUDA event before the first timed iteration and one after the last time
them. iter_ms_mean is the time between them on the GPU, idle gaps included,
over the timed iterations, the mean over ranks; iter_ms_max and
iter_ms_per_rank give the rest, and iter_ms_host stays.

The per-call events add host work to every call: the input dist's segment,
the hierarchical output dist's launches, and each iteration's forward and
backward. They now come only with --call_events, and with --trace and
--host_stages, which need them.

Under --nvtx the capture holds the warmup and the timed iterations (NVTX
ranges "warmup i" and "iteration i"), and cudaProfilerStart comes before
the barrier. The benchmark then adds only NVTX ranges and the profiler's
start and stop to a captured run; nsys's own tracing can still cost the
host time. Python's garbage collector is off from the barrier to the end of
the timed iterations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The benchmark README's section 3 gives the final comparison of TorchRec's
dists with the hierarchical dist, timed as the benchmark now times: one
CUDA event pair around 20 iterations right after 20 of warmup, with no
sync of the benchmark's between them; the step is iter_ms_mean. The runs
use power-law keys (alpha 1.05) at three kinds of point:
- F = 8 at 8k, 16k and 32k samples per GPU, 1-4 keys per sample and
  feature;
- F = 1k, 2k and 4k at 128 samples, 1-4 keys;
- F = 8 at 128 samples, 1-1k, 2k, 4k and 8k keys.

Each point is the median of 3 rounds on Eos and 5 on GB300. The
hierarchical dist's step is 48% to 81% shorter on Eos (8, 16 and 32 GPUs)
and 51% to 82% shorter on GB300 (4, 8 and 16 GPUs of one NVL72 rack, each
rank pinned to 32 cores of its GPU's CPU). The notes cover:
- the --check runs;
- the rounds' spread on Eos;
- why and how GB300 runs pinned, its remaining stalls at 16 GPUs, and the
  two cells whose median is a slow round;
- how close the nsys captures of the same runs come.

The many-features and multi-hot tables go, with their notes: they were
measured with TorchRec's per-feature output and the earlier timing. The
large batch's kernels stay under a heading of their own, with the commit
they ran on. The NCCL plugin note now names GB300 too.

The design doc's section 1 gives the results. Sections 4.2, 4.5 and 19
give what GB300 showed: the node sizes NCCL gave (8 and 16 GPUs on 2 and 4
trays, with MNNVL), the plugin setting, and the largest node run so far.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge main up to 476cdc0: NVIDIA#544 and NVIDIA#547 in DynamicEmb; NVIDIA#535, NVIDIA#537,
NVIDIA#539 and NVIDIA#540 outside it.

- NVIDIA#544 deduplicates int32 keys as int64 in _dedup_indices and returns
  them in the input's dtype, as this branch did. The merge keeps main's
  widening (indices_64bit) and drops this branch's copy of it, so the
  keys are widened once. It keeps this branch's structure: a sharding on
  the hierarchical dist keeps its unique keys sized on the device, and
  TorchRec's dists slice them to the count. The docstring says both.
- NVIDIA#544 also bucketizes an int32 key as the int64 key of its value. The
  hierarchical dist's own bucketize still reads a key in its own width;
  the next commit gives it int32 keys as int64.
- DynamicEmb_APIs.md: main's paragraph on how the rules read a key, then
  this branch's line that the hierarchical dist takes roundrobin and
  hash_roundrobin only.
- test_sequence_embedding_fw.py and test_twin_module.py: main's int32
  runs (NVIDIA#544) and no-grad forward (NVIDIA#547), with this branch's checks that
  a sharding took the dist it was given (check_path, check_totals).
- NVIDIA#547 (a no-grad training forward releases its slot pins, after
  refreshing its slots past a rehash) merges without conflicts next to
  this branch's row map and load_from_flat_by.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NVIDIA#544 has DynamicEmb's bucketize place an int32 key as the int64 key of
its value, the key a table stores and a checkpoint holds, as
key_ownership already did. The hierarchical dist's bucketize reads a key
in its own width: a negative int32 key as 2^32 + key under roundrobin,
and the low 32 bits of the hash of the zero-extended key under
hash_roundrobin. So after the merge of main an int32 key could get one
owner on the hierarchical dist and another on TorchRec's path and in a
checkpoint load or a delta replay: under hash_roundrobin most keys at a
world size that is not a power of two and most negative keys at any,
under roundrobin negative keys at world sizes such as 7 or 100.

hier_forward now gives the op int32 keys as int64, so the op places
every key by the 64-bit rule, which for int64 keys is the rule it had.
No C++ changes: the op still takes int32 keys and reads them in 32 bits,
which no call through the sharding reaches now. The widened keys are
held with the call's other inputs until the second wait.

- test_hier_bucketize.py gives the bucketize hook the keys as the
  sharding gives them to the op, int32 ones as int64, and compares it as
  before with DynamicEmb's bucketize of the int32 KJT, now NVIDIA#544's.
- The docs and docstrings that stated the 32-bit rule, or that a node's
  GPUs must give the dist keys of one dtype, say what holds now: the
  design doc's sections 4.2, 5.2, 9, 10.1 and 19, DynamicEmb_APIs.md,
  DynamicEmbTableOptions.output_dist, hier_needs and the dist test's
  bucketized_owners. With every key int64 at the op, a node's GPUs may
  give the dist keys of different dtypes; TorchRec's dists still need
  one dtype on every rank.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DynamicEmb builds for DEMB_ARCHS, by default 75;80;90;100;120: setup.py
passes their -gencode flags, so the TORCH_CUDA_ARCH_LIST the CI sets does
not reach them. The proxy's __reduce_max_sync and __reduce_add_sync are
sm_80 instructions, undefined for sm_75, so a default build with NCCL >=
2.30.7 stopped at proxy.cu, as the CI's did (GitLab pipeline 81428478,
train_build_x86 and train_build_arm64; the Eos and GB300 builds used
DEMB_ARCHS=90 and 103). The other 34 compile steps passed, the dist's other
files for all five architectures.

The dist need not run before sm_80. So:
- proxy.cu: warp_max and group_sum take the two instructions on sm_80 and
  newer, so that code does not change; a build for an older GPU compiles
  the kernels with a trap in their place.
- node_size: a rank whose GPU is before compute capability 8.0 refuses in
  the first all-gather, as a build without the dist does. Every rank then
  raises the same RuntimeError before any rank makes the probe's
  communicator, and the sharding takes TorchRec's dists with a warning on
  every rank.
- test_hier_dist.py's node-size checks stand in a 7.5 GPU on rank 0 and on
  the last rank: the same error on every rank, and no rank reads NCCL's
  team.
- The design doc (sections 4.2, 6 and 7.2) and the docstrings of node_size
  and hier_node_size say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… its benchmark runs on TorchRec 1.9

The NGC PyTorch 26.09 image, which the base-image bump moves to, has
NCCL 2.31.2 and TorchRec 1.9 (with FBGEMM 1.9.0 and torch 2.14).

- NCCL 2.31 removed ncclDevComm::ginConnectionsRailed. It now gives
  ginConnectionStride, the stride between the ranks GIN connects (1 when
  it connects every rank), and its own 2.30 compat shim maps a stride
  above 1 to the old flag (v2.31.2-1:src/devcomm/devcomm_v23000.cc:142).
  gin_railed reads the stride from NCCL 2.31 on and the flag before it,
  so the dist builds against both. A probe with every NCCL use of the
  dist compiles against the 2.30.7 and the 2.31.2 headers (nvcc 12.4,
  sm_80 and sm_90).
- TorchRec 1.9's EmbeddingCollectionAwaitable passes use_sorted_select
  to construct_jagged_tensors, which the EC benchmark replaces with its
  flat output. The stand-in now takes the argument; it is False unless
  the EC asks for sorted select, which the benchmark's never does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DEMB_ARCHS, the architectures of DynamicEmb's kernels and of its
eviction fatbins (the SASS one and the LTO-IR one that nvJitLink links
the user's score function into), defaulted to 75;80;90;100;120. GB300
is sm_103: the default build ran its sm_100 code there, and no sm_103
LTO-IR. The default is now 75;80;90;100;103;120, less the architectures
the CUDA compiler cannot build (nvcc --list-gpu-code): sm_103 needs CUDA
12.9 or newer. Without an answer from nvcc it is the old list. An
explicit DEMB_ARCHS skips the query.

The README says how DEMB_ARCHS works (TORCH_CUDA_ARCH_LIST does not
apply to these kernels).

The same change as NVIDIA#549's, without its image bump, so that this
branch builds in the current NGC 26.07 image.

Following NVIDIA#538, which found that the default build omits sm_103.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>
@shijieliu
shijieliu force-pushed the fea-hier-output-dist-lite branch from a93932c to 3c543b0 Compare November 12, 2026 08:46
shijieliu and others added 2 commits November 12, 2026 02:13
…ir own, and skip where NCCL splits a host

DynamicEmb's CI scripts, run on the current image as ci/dynamicemb_test.sh
runs them (Eos, NCCL_P2P_DISABLE=1, which the CI sets): fwd_bwd failed in
test_hier_dist.sh at 6 GPUs. At 2 and 4 ranks NCCL's LSA team was the host,
and every check passed. At 6 it was 2 ranks: three nodes of the dist on one
host, which would exchange keys and rows over GIN. ncclDevCommCreate failed
there ("unhandled system error"), every sharding took TorchRec's dists, and
the no-sync check raised at their own .item() in _dedup_indices.

hier_switch.splits_host says when the dist's node, NCCL's LSA team, splits
the GPUs of a host (LOCAL_WORLD_SIZE) between nodes. test_hier_dist.py,
test_hier_overflow.py and test_hier_pipeline.py skip such a run with a line,
and check_path passes a sharding that falls back there, with a line on
rank 0. One node per host, and GB300's nodes of several trays, run as
before.

The CI gives a job two hours. fwd_bwd took up to 115 minutes there before
this PR. On Eos, its files before the hier suites took 50 minutes, and
test_embedding_dump_load.sh alone 47 of load_dump's. The eight reruns on the
dist repeat files that take most of that time. So unit_test.sh's hier suites
and reruns move to two groups of their own: fwd_bwd_hier (the dist's own
tests, then the fwd_bwd files on the dist) and load_dump_hier (the load_dump
files on the dist), each file with the group it comes from. Each group is to
be a CI job of its own. fwd_bwd and load_dump are main's again. The design
doc's section 18 says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the skip where NCCL splits a host

This reverts commit f4b2ab6. The dist is
tested by hand on Eos, on one node and across nodes, with NCCL's P2P on.
The CI runs its single-node tests in test/unit_test.sh's groups, as
before that commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shijieliu
shijieliu merged commit d53b9c8 into NVIDIA:main Nov 12, 2026
1 check passed
shijieliu added a commit that referenced this pull request Nov 13, 2026
…d and load_dump groups for a hier group (#550)

* [FEA] DynamicEmb: the hierarchical dist's tests leave the CI's fwd_bwd and load_dump groups for a hier group

With #528 on main, the CI's two DynamicEmb jobs ran the hierarchical dist's
tests in their fwd_bwd and load_dump groups. On main's first pipeline
(GitLab 81592418, an A100 node), load_dump hit the jobs' two-hour limit,
and fwd_bwd hung in test_hier_pipeline.py's DDP stress case; that hang is
under investigation.

test/unit_test.sh now runs them in a group of its own, hier: first
test_hier_dist.sh, test_hier_overflow.sh and test_hier_pipeline.sh, then
the eight files that run again on the dist, each with the group it comes
from. fwd_bwd and load_dump hold what they held before #528. The CI runs the
dist's tests on GB300 and Eos with JET (distributed-recommender!143), with
NCCL's P2P on, on one node and across nodes. The design doc's section 18
says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>

* [FEA] DynamicEmb: hier_fwd_bwd and hier_load_dump groups for the existing tests on the dist

test/unit_test.sh's hier group now holds the dist's own tests alone
(test_hier_dist.sh, test_hier_overflow.sh, test_hier_pipeline.sh), which
the CI runs on GB300, on one tray and across trays. The files of fwd_bwd and
load_dump that run again on the dist get groups of their own,
hier_fwd_bwd (five files) and hier_load_dump (three), each file with the
group it comes from. Most of their runs take 8 GPUs on one host, so the CI
runs them on Eos. The groups that rerun files on the dist are now called
ON_HIER_DIST. The design doc's section 18 says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>

* [FEA] DynamicEmb: the CI runs the hier group on Eos too

The CI runs the hierarchical dist's own tests on Eos as well as GB300: on
one node of 8 H100s, so at 6 and 8 GPUs, and across two nodes over
InfiniBand. The design doc and test/unit_test.sh's comment say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>

---------

Signed-off-by: aleliu <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
shijieliu added a commit to shijieliu/recsys-examples that referenced this pull request Nov 16, 2026
Brings in main 4466f9d: NVIDIA#528 (hierarchical dist), NVIDIA#550, NVIDIA#553, NVIDIA#555, NVIDIA#478
(exportable embedding collections with NVE layers), NVIDIA#554 and NVIDIA#556.

Conflicts:
- corelib/dynamicemb/CMakeLists.txt: main (NVIDIA#478) adds the RPATH, NVE_ROOT
  and DYNAMICEMB_PYTHON_MODULE_DIR lines above the C++ standard; kept them,
  with this branch's C++20 (PyTorch 2.14's headers need it).
- corelib/dynamicemb/setup.py: main's file. It already has this branch's
  CUDA_HOME import and sm_103-aware default archs (from NVIDIA#528); the conflict
  was only main's new `import torch` and `Extension` imports.
- corelib/dynamicemb/README.md: main's new inference build section, after
  this branch's FBGEMM 1.9.0 / TorchRec 1.9.2 lines.

docker/Dockerfile merged cleanly: NVIDIA#478's build stage rebuilds the default
NVE from the submodule with the same pip command and settings as the devel
stage, and builds torch_binding_build through the CMakeLists above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>
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