Guard KJT-pool update against corrupt A2A lengths (#4327)#4327
Open
hammad45 wants to merge 1 commit into
Open
Conversation
Contributor
|
@hammad45 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107405007. |
Summary: Row-wise `ShardedKeyedJaggedTensorPool.update()` can silently poison `_key_lengths` at small world sizes: the post-all-to-all lengths from `JaggedTensorAllToAll` are written verbatim into `_key_lengths` (`object_pool_lookups.py`), and a corrupted / desynced all-to-all yields out-of-range (negative or ~±2^31) lengths that only crash much later in the training-forward `lookup()` as a negative dimension in `jagged_index_select_2d_forward_v2`. This is hard to debug because the object-pool `JaggedTensorAllToAll` has none of the int32-overflow guards that the embedding `KJTAllToAll` / `FusedKJTAllToAll` paths already have. See T273509522 (and the 2022 twin T118141711). This diff adds detection + fast-fail: - `_assert_valid_key_lengths()` in `object_pool_lookups.py`, called in all three KJT-pool `update()` methods before writing `_key_lengths`. Always-on, eager-only (mirrors the existing `_update_preproc` max-length assert); turns silent corruption into a clear error at the write site. - `_check_int_overflow` guards in `JaggedTensorAllToAll` on the lengths/value split sizes and received-lengths min/max, mirroring the embedding all-to-all paths. No-op unless `TORCHREC_OVERFLOW_DEBUG=1`, so the default path is unchanged (the min/max device sync is extra-gated behind the env var). This is detection/hardening, not the root-cause fix: with `TORCHREC_OVERFLOW_DEBUG=1` the 2x8 repro can now pinpoint the exact overflowing/mismatched split, after which that split/cumsum can be made int64-safe. Differential Revision: D107405007
7e4eecf to
c69a036
Compare
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.
Summary:
Row-wise
ShardedKeyedJaggedTensorPool.update()can silently poison_key_lengthsat small world sizes: the post-all-to-all lengths fromJaggedTensorAllToAllare written verbatim into_key_lengths(object_pool_lookups.py), and a corrupted / desynced all-to-all yields out-of-range (negative or ~±2^31) lengths that only crash much later in the training-forwardlookup()as a negative dimension injagged_index_select_2d_forward_v2. This is hard to debug because the object-poolJaggedTensorAllToAllhas none of the int32-overflow guards that the embeddingKJTAllToAll/FusedKJTAllToAllpaths already have. See T273509522 (and the 2022 twin T118141711).This diff adds detection + fast-fail:
_assert_valid_key_lengths()inobject_pool_lookups.py, called in all three KJT-poolupdate()methods before writing_key_lengths. Always-on, eager-only (mirrors the existing_update_preprocmax-length assert); turns silent corruption into a clear error at the write site._check_int_overflowguards inJaggedTensorAllToAllon the lengths/value split sizes and received-lengths min/max, mirroring the embedding all-to-all paths. No-op unlessTORCHREC_OVERFLOW_DEBUG=1, so the default path is unchanged (the min/max device sync is extra-gated behind the env var).This is detection/hardening, not the root-cause fix: with
TORCHREC_OVERFLOW_DEBUG=1the 2x8 repro can now pinpoint the exact overflowing/mismatched split, after which that split/cumsum can be made int64-safe.Differential Revision: D107405007