Repository navigation
FIX](DynamicEmb) Release slot pins after no-grad training forwards - #547
Merged
Merged
Conversation
Signed-off-by: lidongdong.2024 <[email protected]>
…d forward The backward and the no-grad forward both undo the ref-counter pins that prefetch took. Put the choice of counter owner (cache or storage, by the batch's storage_mode) in one function so the two paths cannot disagree. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Jiashu Yao <[email protected]>
…tches for slot pins Run the slot-pin lifetime tests on every storage layout (HBM, cache, hybrid, host-only), with and without a frequency admission that rejects a key on its first sight (slot -1). Add a case with two batches in flight, one under no_grad and one with grad, in both orders: releasing the no-grad batch must leave the other batch's pins until its backward. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Jiashu Yao <[email protected]>
…grad forward releases its pins A later batch's prefetch may expand the table before an earlier batch's no-grad forward runs. That forward released its pins at the slots its prefetch found, which a rehash had moved: other keys' counters went below 0 and its own new slots stayed pinned. Only backward refreshed the slots (NVIDIA#529). Move that refresh into refresh_slots_after_rehash, which updates the slots and the rehash count on the PrefetchState (or the ctx that took it over), and call it from both the backward and the no-grad forward. release_slot_pins only decrements. Add a test that expands the tables between two prefetches. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Jiashu Yao <[email protected]>
Contributor
The PR appears safe to merge; no actionable issues were found.
SummaryReleases slots held by training forwards that have no autograd graph.
No actionable issues were found. Tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Prefetch pins slots] --> B[Forward copies embeddings]
B --> C{Output requires grad?}
C -->|No| D[Refresh slots after table growth]
C -->|Yes| E[Backward updates embeddings]
E --> F[Refresh slots after table growth]
D --> G[Release this batch's pins]
F --> G
Reviews (2) · Last reviewed commit: "[FIX](DynamicEmb) Refresh a batch's slot..." · Reviewed by Greptile |
shijieliu
approved these changes
Nov 11, 2026
3 tasks done
4 tasks done
shijieliu
added a commit
to shijieliu/recsys-examples
that referenced
this pull request
Nov 12, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Supersedes #541 (its commit is kept, authored by @lidongdongbuaa ).
A training-mode forward under
torch.no_grad()never runs backward, so the ref-counter pins that prefetch took on its slots were never released and eventually filled the cache/bucket.BatchedDynamicEmbeddingTablesV2.forwardwhen the output has no autograd graph (release_slot_pins, shared with backward).refresh_slots_after_rehash, shared with backward; it replaces_slots_after_rehashfrom fix(dynamicemb): keep prefetched keys' ref counts through a rehash #529). Without it a no-grad forward released the stale slots: other keys' counters went below 0 and its own new slots stayed pinned.test_no_grad_slot_lifetime.py, 46 cases): HBM / cache / hybrid / host-only layouts, with and without frequency admission, two batches in flight (grad and no-grad, both orders), and an expansion between two prefetches. On Eos H100 they pass with the fix; without it the no-grad cases on HBM/cache fail (pins left) and the rehash case fails with a counter below 0.Original fix by lidongdong.2024 (commit 4bc4f25).
Checklist