Repository navigation
[FIX] DynamicEmb: the cache raises on the keys its insert refuses, flagged by the kernel; pins add up across streams - #557
Merged
shijieliu merged 5 commits intoNov 16, 2026
Conversation
Contributor
[Medium impact] The changes affect cache prefetch and slot pinning within DynamicEmb training workflows. Release the failed batch's cache-hit pins before merging. Findings
SummaryThe PR detects refused cache inserts before writing values back, makes pin updates atomic across CUDA streams, and removes the old capacity estimate.
Reviews (8) · Last reviewed commit: "refactor(dynamicemb): the insert writes ..." · Reviewed by Greptile |
shijieliu
force-pushed
the
fix/cache-refused-and-atomic-pins-20261115
branch
from
November 16, 2026 01:36
65d6403 to
8c1ebef
Compare
shijieliu
force-pushed
the
fix/cache-refused-and-atomic-pins-20261115
branch
from
November 16, 2026 01:56
8c1ebef to
971e3b2
Compare
shijieliu
force-pushed
the
fix/cache-refused-and-atomic-pins-20261115
branch
from
November 16, 2026 02:23
971e3b2 to
b4f55a2
Compare
update_counter_with_layout_kernel added its delta with a plain +=, on the assumption that no two threads touch one counter. Within one launch that holds (the slots come from unique keys), but launches on different streams overlap: under TorchRec's prefetch pipeline the prefetch of batch i+1 pins its keys on the prefetch stream while the backward of batch i releases its own on the default stream, with nothing ordering the two, and a key in both batches could lose the pin (it can then be evicted while in use) or the release (it can then never be evicted). The add is atomic now. test_pin_counter_concurrency.py pins and releases the same slots on two unordered streams and checks that every counter ends where it started. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: aleliu <[email protected]>
…he prefetch raises on them The cache's insert refuses a key when the key's bucket and its table's overflow area hold nothing it may evict: keys pinned by batches in flight, or keys placed by the same insert. A refused key comes back among the evicted ones with a negative slot, so load_from_flat leaves its row of the evicted values unwritten; _prefetch_cache_path then wrote every evicted key back, overwriting the refused key's value in the storage with that row, and left the key's slot at -1, so the forward read a row nothing wrote. The insert kernel now counts the keys it refuses when asked (InsertKernelTraits::ReportRefused: a variant of the kernel of its own, so an insert that is not asked pays nothing), table_insert_and_evict takes the counter (`refused`), and the cache's insert_and_evict(report_refused=True) returns the count, read in the same copy as the number of evicted keys: no read is added. The prefetch raises right after the insert if a key was refused, before anything is written back: every key of a batch has to be in the cache when its forward reads it. test_cache_refused_insert.py inserts more new keys than a one-bucket cache and its overflow area hold: the kernel's count is the number of evicted entries with a negative index, the prefetch raises, and every key's storage row keeps its value (unwritten memory is filled with NaN). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: aleliu <[email protected]>
…e insert's own count replaces The prefetch counted the keys of the batches in flight against the capacity of the whole cache, to raise before the cache could fail to place a key. It was a guess at what the insert does: one number for all the tables, overflow areas included, while buckets and overflow areas belong to one table each; and a batch was given back at the end of its forward, although its keys stay pinned until its backward. The insert now reports the keys it really refuses and the prefetch raises on them, so the check and its count go: _prefetch_outstanding_keys, dynamicemb_prefetch's outstanding_keys_ref, and PrefetchState's num_prefetched_keys and outstanding_keys_ref. test_cache_refused_insert.py now goes through the module's own prefetch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: aleliu <[email protected]>
…y, read after num_evicted The count of refused keys went to the host in the same copy as the number of evicted keys, which took a concatenation on the device and a larger copy. The kernel now writes a flag into pinned host memory, through its device mapping: a plain store, every refusing thread writing the same 1, since an atomic on host memory is not one on every platform. The read of num_evicted, which waits for the insert, makes it visible, and the host reads it without a copy of its own; that read is the one main makes already. The number of refused keys, which only the error message needs, is counted from the evicted keys' negative indices when the flag is set. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: aleliu <[email protected]>
…d host address The insert took the device pointer of the pinned `refused` flag from cudaHostGetDevicePointer. With unified addressing, which every supported platform has, pinned host memory is mapped at its host address, so that call only returned data_ptr(); the op already checks that the tensor is pinned. It now passes get_pointer<int64_t>(refused), as for its other optional tensors. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: aleliu <[email protected]>
shijieliu
force-pushed
the
fix/cache-refused-and-atomic-pins-20261115
branch
from
November 16, 2026 08:41
755a7e7 to
4027804
Compare
Collaborator
Author
|
/build |
Collaborator
|
✅ Pipeline #82548374 -- success
Result: 20/20 jobs passed |
This was referenced Nov 17, 2026
jiashuy
added a commit
to jiashuy/recsys-examples
that referenced
this pull request
Nov 19, 2026
…out tests Found while running the tests on EOS: - A forward on a table with a cache pins its keys until its backward, and since NVIDIA#557 a cache raises when a batch finds only pinned ones. insert_keys ran graph-building forwards without a backward, so the half of a 97 %-full shard a cache holds was pinned full after a few chunks. It now runs them under torch.no_grad(), where the forward releases its pins itself. - The uneven-fold growth test inserts a thousand keys a call. A growth is sized for the keys a call brings, so chunks of 16 384 jumped the table most of the way at once and it never stopped between P/2 and P buckets, with or without the rule against that: switching the rule off left the test green. With small chunks it fails without the rule. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Merged
3 tasks done
shijieliu
pushed a commit
that referenced
this pull request
Nov 19, 2026
…ant global bucket layout (#566) * [FEA](DynamicEmb) Add the hash_bucket dist_type with a fan-out-invariant global bucket layout A key's home bucket is derived from the whole table's capacity instead of the shard's, so the keys that share a bucket do not depend on the fan-out and a checkpoint reloads at another world size without a bucket overflowing. See corelib/dynamicemb/docs/global_bucket_layout_design.md. Rebased onto main (hierarchical dist, int32-as-int64 keys, checkpoint_io split); hash_bucket is refused by the hierarchical dist. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Update the dist_type mismatch and owns_key tests for hash_bucket test_multi_table_load_dist_type_mismatch now expects the warn-and-repartition behaviour, and owns_key takes num_embeddings optionally (required only for hash_bucket). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) Document loading a checkpoint across dist_type Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Skip the hash_bucket dump/load runs on the hierarchical output dist The hierarchical dist refuses a hash_bucket table, so the hier_load_dump group (DYNAMICEMB_TEST_OUTPUT_DIST=hierarchical) must not run that section of test_embedding_dump_load.sh. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) State that a hash_bucket table does not grow, and drop the checkpoint's name from the design doc DynamicEmb_APIs.md: a hash_bucket table is allocated at max_capacity up front, init_capacity is raised to it, and expanding it in place raises; a table of another size is a different layout, loaded through the migration path. global_bucket_layout_design.md: describe the measured checkpoint as a real production one, without naming it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [REF](DynamicEmb) Share one home_bucket_of between the table kernels and the bucketizer LinearBucketTable::home_bucket and the bucketizer's BucketizeFunctor each wrote the global-bucket arithmetic by hand; both now call the free function home_bucket_of (types.cuh). The hash_bucket route reads its key through stored_key() like the other dist_types. home_bucket's comment now states that *bucket_id is written only when the table has buckets. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [REF](DynamicEmb) Write each output of home_bucket once Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Derive the hash_bucket route's shard capacity the way the host rule does, and refuse a plan made for another fan-out The route took its shard capacity from the table's max_capacity while the host rule (checkpoint load, replay) recomputed it from global_capacity, bucket_capacity and the shard count; a plan made for one fan-out and run at another made them disagree silently. routing_param_tensors now derives it with hashed_shard_capacity and raises when it differs from max_capacity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Refuse block_bucketize_row_pos for a feature whose dist_type is not continuous With positions the kernel places keys by row range and never reads the feature's dist_type, so a roundrobin, hash_roundrobin or hash_bucket key was routed by a rule its table does not follow, silently. The distributors pass no positions, so only a caller that asks for them is affected (and pays one host sync). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Let the twin module read each table's own global_capacity and bucket_capacity The twin filtered keys by the hash_bucket rule with a global_capacity it re-derived from the default bucket capacity, so a caller passing another bucket_capacity in dynamicemb_options_kwargs got the keys of a different layout on each rank, silently. It now reads the options the planner gave the table, from the new BatchedDynamicEmbeddingTablesV2.dynamicemb_options property. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Warn that hash_bucket with MAX_BUCKET_CAPACITY is not fan-out invariant With one bucket per shard the global capacity is shards x shard rows, so it changes with the fan-out and a reload at another world size may lose rows; the planner said so only in a comment. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Name the evict cubin's entry points for the EvictParams ABI so a stale fatbin fails to load EvictParams gained a trailing table_global_capacities, but a cubin built against the old layout still loads: it ignores the new field and places a hash_bucket table's keys by the old rule. The entry points now end in _abi<DYN_EMB_EVICT_ABI>; an image of another layout lacks them and load_from_image raises, naming the fix (rebuild the extension and the fatbins together). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Run test_global_bucket_layout.py and test_lookup_meta.py in the fwd_bwd group Neither was registered in unit_test.sh, so no group ran them: the lossless-reload and routing checks of the hash_bucket layout never ran in CI. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Reload hash_bucket checkpoints losslessly under the LruLfu policy too The compound (TIMESTAMP, LFU) strategy inserts and evicts in the LruLfu cubin, which has its own copy of the home-bucket arithmetic and takes table_global_capacities through EvictParams. The fold and the training-survivors tests ran on the AoT kernel only; a cubin that ignored the field would not have been caught. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Give the hash_bucket dump/load tests ordinary buckets create_model gave every table one bucket per shard (MAX_BUCKET_CAPACITY), whose global capacity changes with the fan-out, so the hash_bucket runs of test_embedding_dump_load.sh never exercised the fan-out-invariant layout nor the reload without re-partitioning. hash_bucket tables now use the default bucket capacity; owns_key derives the global capacity the way the planner does. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) Say that a HYBRID hash_bucket table is accepted but not lossless across fan-outs The API doc listed HYBRID tiers, MAX_BUCKET_CAPACITY and NO_EVICTION tables as "excluded", which reads as refused; the code accepts them, routes their keys by the global rule, and only withholds the fan-out guarantee. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Round-trip a HYBRID hash_bucket table at the same fan-out A HYBRID table is accepted under hash_bucket but no test built one. HybridStorage.load reads the key -> rank rule from its host tier's options, since the HBM tier's copy rescaled bucket_capacity; the round trip checks every shard gets exactly its keys back. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FEA](DynamicEmb) Let the hierarchical dist place keys by the hash_bucket rule The op's bucketize computed an owner from the key and world_size alone, which is why it refused hash_bucket. hash_bucket keeps the key and needs two numbers per feature, the rows of its table and of one shard; they now travel with dist_types (OwnerRules, Config::global_capacities / shard_capacities, HierDist.setup) and owner_of gains the rule: (murmur3_fmix64(key) & INT64_MAX) % global_capacity / shard_capacity, the key read as the int64 it is. Config::validate refuses a hash_bucket feature without positive capacities, with capacities that name more ranks than the sharding has, or whose table's features differ. The input distributor passes the capacities it validated. Tests: the bucketize hook against DynamicEmb's own bucketize for hash_bucket (int64 and int32 keys, the edges, all three rules in one sharding), the configuration refusals, two model-level cases, and test_embedding_dump_load.sh now runs hash_bucket in the hier group. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Keep three hash_bucket cases in the hier bucketize test The two edge-key cases ran the same arithmetic as the random negative-key case on more values, for every world size and sort path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Keep one hash_bucket case in the hier model test The mixed case (hash_bucket and roundrobin tables) covers the pure one and a rule dispatch besides; each case builds a model on 8 GPUs. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FEA](DynamicEmb) Let a hash_bucket table start below max_capacity and grow The planner raised init_capacity to max_capacity, create_table_state refused a smaller one and _expand_tables_impl refused to grow, on the ground that the global bucket map is only realised with max_capacity / bucket_capacity buckets. The map does not depend on the table's size, though: keys reach a rank by it (g // P, from global_capacity), and the table already folds it into the buckets it has (home_bucket_of: g % num_buckets). More buckets split the old ones, so growing keeps every key on its rank and the re-insert only moves it within the rank, as for roundrobin; the expansion already passes the global capacities on. At num_buckets == P the fold is the identity, the layout the lossless reload promises. Tests: the planner keeps a small init_capacity; a table starting at 1/32 grows, keeps and finds its keys; a checkpoint of grown tables reloads losslessly at another fan-out. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FIX](DynamicEmb) Do not stop a growing hash_bucket table between P/2 and P buckets A table with a global capacity folds the whole table's bucket map into the buckets it has (g % num_buckets). Where num_buckets does not divide the shard's P, the first P mod num_buckets buckets hold one global bucket more; between P/2 and P that is two against one, and at load factor 0.5 the doubled buckets at the front are full and evict. get_expand_info now grows such a table straight to max_capacity once its next size would pass half of it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) The doubled buckets of an uneven fold are a run from r*P mod num_buckets, not the first ones Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [REF](DynamicEmb) Wrap the C++ lines of the hash_bucket change to the file's 80 columns No clang-format here, so by hand: the over-long declarations and comments, the arguments of the bucketize launches that sat under the wrong column, and a comment in jit_link.h that had run into the next one. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [REF](DynamicEmb) Decide a key's owner through OwnershipRule where the four numbers meet The replay filter, the twin, the checkpoint loaders and ScoredHashTable.load each passed (rank, world_size, dist_type, global_capacity=, bucket_capacity=) to owned_key_mask by hand, and the twin once re-derived two of them wrongly. They now build an OwnershipRule (from the table's options where there is one) and ask it for a mask; owned_keys becomes OwnershipRule.keep. The functional API is unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) The per-rank sizing is unchanged for every dist_type; dump a new shard count into a new directory Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [REF](DynamicEmb) Keep bucketize_keys' signature as it was The change was a reformat with nothing to do with hash_bucket. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Say why the key-skew test reaches for trapezoid, and fail on a missing name plainly Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [FEA](DynamicEmb) Refuse hash_bucket with NO_EVICTION; let the benchmark take hash_bucket A NO_EVICTION table never evicts, so the layout buys it nothing, and the rank of a key under hash_bucket follows from num_embeddings, which such a table only starts from (it grows without bound): a small value leaves ranks without keys and changing it moves every key. DynamicEmbTableOptions now raises for the combination. The benchmark's --dist_type takes hash_bucket and its owner function passes the table's capacities. Three texts that still named only roundrobin and hash_roundrobin (the sharding's error message, output_dist's doc, the replay doc) name hash_bucket too. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) A load sizes a hash_bucket table by its row count, which does not guarantee the keys fit The load grows a table by total rows over capacity, not by bucket occupancy, so a checkpoint built key by key into global buckets that fold into one local bucket of a table that has not grown to max_capacity can still lose rows. Hashed keys do not come like that; the text said the load expands the table so the keys fit, which was too much. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [DOC](DynamicEmb) A hash_bucket table is allocated at init_capacity, like any other The planner row of the guide still said init_capacity is raised to max_capacity for hash_bucket; since the growth change it is kept (aligned, clamped to max_capacity). The row now says what a model allocates at startup and what the upper limit is. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Fix the insertion helpers of the global bucket layout tests Found while running the tests on EOS: - A forward on a table with a cache pins its keys until its backward, and since #557 a cache raises when a batch finds only pinned ones. insert_keys ran graph-building forwards without a backward, so the half of a 97 %-full shard a cache holds was pinned full after a few chunks. It now runs them under torch.no_grad(), where the forward releases its pins itself. - The uneven-fold growth test inserts a thousand keys a call. A growth is sized for the keys a call brings, so chunks of 16 384 jumped the table most of the way at once and it never stopped between P/2 and P buckets, with or without the rule against that: switching the rule off left the test green. With small chunks it fails without the rule. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Load a hash_bucket checkpoint into an inference embedding collection The collection reads the dist_type and the hash_bucket layout from the checkpoint's meta and takes every shard file. The test writes a hash_bucket checkpoint by the host rule, split over 1, 2 and 8 shard files, loads it and checks that every key comes back with its own row. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * [TEST](DynamicEmb) Run the twin module test on a hash_bucket table too The twin seeds its torchrec reference with the rows each rank's table holds, so it has to decide a key's owner as the table does. Until now only roundrobin was run: a wrong hash_bucket rule, or the wrong global_capacity / bucket_capacity behind it, went unseen. The body of test_twin_module is now a helper that takes the dist_type, and a hash_bucket test runs it over two table sizes that do not divide evenly over the ranks, pooled and sequence. With the twin's owner rule replaced by key % world_size the test fails on 8 ranks. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes of the cache's prefetch path, and the removal of a check the first one makes redundant.
1. A key the cache's insert refuses is written back as garbage
The cache's insert refuses a key when the key's bucket and its table's overflow area hold nothing it may evict: keys pinned by batches in flight, or keys placed by the same insert. A refused key comes back among the evicted ones, with a negative slot (
-(pos + 1))._prefetch_cache_paththenload_from_flat, which skips negative slots: the refused key's row ofevicted_valuesis never written (torch.empty);_write_back_evicted): the refused key is in the storage, so its value there is overwritten with that unwritten memory;The cache size and the overflow areas make this rare, but its effect is silent.
Fix. The insert kernel flags a key it refuses when asked:
InsertKernelTraits::ReportRefusedselects a variant of the kernel of its own, so an insert that is not asked pays nothing. The flag sits in pinned host memory, which the kernel writes at its host address, mapped there by unified addressing (a plain store, every refusing thread writing the same 1, since an atomic on host memory is not one on every platform).table_insert_and_evicttakes it (refused), and the cache'sinsert_and_evict(..., report_refused=True)reads it oncenum_evictedis on the host: that read, which main makes already, waits for the insert, so no read is added. The number of refused keys, which only the error needs, is counted from the evicted keys' negative indices when the flag is set. If a key was refused, the prefetch raises right after the insert, before anything is written back:RuntimeError("The cache could not place N keys of this batch ..."), since every key of a batch has to be in the cache when its forward reads it. Otherwise it runs exactly as before.The prefetch's outstanding-keys check goes with it (third commit). It counted the keys of the batches in flight against the capacity of the whole cache, to raise before the insert could fail to place a key, and was a guess at what the insert does: one number for all the tables, overflow areas included, while buckets and overflow areas belong to one table each; and a batch was given back at the end of its forward, though its keys stay pinned until its backward. The insert's own count replaces it:
_prefetch_outstanding_keys,dynamicemb_prefetch'soutstanding_keys_refandPrefetchState'snum_prefetched_keys/outstanding_keys_refare gone.2. The reference counter's update is not atomic
update_counter_with_layout_kernel(the cache's per-slot reference counter:increment_counter/decrement_counter) added its delta with a plaincounter[flat] += delta, on the assumption that no two threads touch one counter at once. Within one launch that holds (the slots come from unique keys), but two launches on streams that nothing orders can overlap on a slot, and then one of the two updates is lost: a lost pin lets the slot be evicted while a batch in flight still reads it, a lost release keeps the slot pinned for good.Whether two such launches overlap depends on the training pipeline:
PrefetchTrainPipelineSparseDist(DynamicEmb's benchmark with--pipeline prefetch,test_hier_pipeline.py) issues forward(i), then the prefetch of batch i+1 on the prefetch stream, then backward(i) on the default stream, and nothing orders the prefetch's pins against the backward's releases: a key in batches i and i+1 can get both at once.JaggedMegatronPrefetchTrainPipelineSparseDist, HSTU and SID-GR) makes the default stream wait for the prefetch stream before the backward, so backward(i) releases after prefetch(i+1) pins. The prefetch stream does not wait for the default stream, though: prefetch(i+1) can still run beside what the default stream was given earlier, the backward of batch i-1 included, when the GPU runs a step behind the host.The test below shows the lost updates with two unordered streams; they have not been observed in a training run.
Fix. The add is
atomicAdd, so the counter no longer depends on how a pipeline orders its streams. It is also faster: anatomicAddwhose result is not used is a reduction done in L2, where+=loads the counter and stores it back.Tests
All registered in
unit_test.sh(fwd_bwd group).test/unit_tests/test_cache_refused_insert.py: a one-bucket cache with its 3-bucket overflow area (4096 slots) and 6000 new keys, unwritten memory filled with NaN. The reported number of refused keys equals the evicted entries with a negative index (1904), and an insert not asked for it returns what it did before. The module's prefetch raises, and every key's storage row keeps its initial value (on main the refused keys' rows are overwritten). A batch that fits is not refused.test/unit_tests/test_pin_counter_concurrency.py: two unordered streams pin and release the same 64K slots 1000 times each (both streams are stalled first so that their kernels run side by side; the kernel is loaded before, since a lazy module load waits for the device); every counter must end where it started, from 0 and from 1. On main it fails 3 runs of 3 (58560 to 65536 of the 65536 counters off); here it passes 3 of 3.Validated on Eos (8 x H100, ci-image 26.07). Every file of the fwd_bwd (31), load_dump (5) and hier (3) groups of
unit_test.shpassed, run one by one on the branch as it was at 971e3b2 (the refused keys counted on the device, the outstanding-keys check still there): among themtest_batched_dynamic_embedding_tables_v2.py391 passed / 4 skipped,test_alignment.sh1440,test_twin_module.sh81,table_operation/test_table_operation.sh204,erase_async180,per_key_score76,test_embedding_dump_load.shandtest_incremental_dump.shin full, andtest_hier_pipeline.sh(TorchRec's prefetch pipeline). The final head, rebuilt, passedtest_cache_refused_insert.py,test_pin_counter_concurrency.py,table_operation(204),test_no_grad_slot_lifetime.py(46), the v2 suite (391 / 4 skipped) andtest_hier_pipeline.sh. isort, black, autoflake and codespell are clean; mypy reports nothing new.Note
#545 (sync-free lookup) has both bugs too: its C++ cache path overwrote the storage rows of 1904 of 1904 refused keys in the same test, and its counter kernel is the same one. Both changes go to #545 as well, the refused count read there once it has reached the host, without a sync. With the atomic counter, the README's large-batch benchmark (8 GPUs, about 10M keys pinned and released per step) went from 35.46 to 35.06 ms a step on #545's tree.
🤖 Generated with Claude Code