dense_to_jagged_forward: realize total_L SymInt before empty#5873
Open
haoyuz wants to merge 1 commit into
Open
dense_to_jagged_forward: realize total_L SymInt before empty#5873haoyuz wants to merge 1 commit into
haoyuz wants to merge 1 commit into
Conversation
Summary: X-link: facebookresearch/FBGEMM#2793 CONTEXT: On AMD MI350X (HIP), MAST job `fire-fandw06-f1096341099` (Stories LSR train_eval) crashed inside `fbgemm::dense_to_jagged` during the forward pass of `UhmEventTokenizer.get_position_encoding`. Two related symptoms appeared across ranks: - `RuntimeError: ...RegisterCUDA_0.cpp:7563: SymIntArrayRef expected to contain only concrete integers` (asIntArrayRefSlow check fired) - `RuntimeError: Trying to create tensor with negative dimension -1409625905161306112: [-1409625905161306112, 8]` (heap SymNode pointer reinterpreted as int64 in `at::detail::empty_generic`) `dense_to_jagged_forward.cu` and the CPU variant forward an `std::optional<at::SymInt> total_L` straight into `at::empty_symint({total_L, D}, ...)`. The aten `empty.memory_format` CUDA/HIP wrapper at `RegisterCUDA_0.cpp` calls `C10_AS_INTARRAYREF_SLOW` on the size array, which `TORCH_CHECK`s that no `SymInt` in the array is `is_heap_allocated()`. Any heap-allocated `SymInt` arriving here (e.g. an unbacked SymInt produced inside a `torch.compile` region in production) trips that check, or - depending on how the dispatcher walked the array - leaks the `SymNode` pointer through as a raw `int64_t` dimension. WHAT: Realize `total_L` to a concrete `int64_t` via `guard_int(__FILE__, __LINE__)` before constructing the output tensor, and switch the allocation from `at::empty_symint` / `at::zeros_symint` (SymInt-shape) to `at::empty` / `at::zeros` (`int64_t` shape). For heap SymInts with a hint or a runtime guard `guard_int` resolves cleanly to the concrete value; for truly unbacked SymInts with no value the kernel now produces a clean `"Could not extract specialized integer from data-dependent expression"` error instead of the low-level memory crash. Same fix applied to both the CUDA/HIP kernel (`src/jagged_tensor_ops/dense_to_jagged_forward.cu`) and the CPU kernel (`src/jagged_tensor_ops/jagged_tensor_ops_cpu.cpp`). Adds a regression test `test_dense_to_jagged_heap_symint_total_L` that constructs an unbacked, heap-allocated SymInt via `ShapeEnv.create_unbacked_symint()` and calls `torch.ops.fbgemm.dense_to_jagged` directly. Pre-fix the test fails with the `SymIntArrayRef` crash; post-fix it passes (asserting the clean `guard_int` error path). Differential Revision: D108236923
Contributor
|
@haoyuz has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108236923. |
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:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2793
CONTEXT: On AMD MI350X (HIP), MAST job
fire-fandw06-f1096341099(Stories LSRtrain_eval) crashed inside
fbgemm::dense_to_jaggedduring the forward passof
UhmEventTokenizer.get_position_encoding. Two related symptoms appearedacross ranks:
RuntimeError: ...RegisterCUDA_0.cpp:7563: SymIntArrayRef expected to contain only concrete integers(asIntArrayRefSlow check fired)RuntimeError: Trying to create tensor with negative dimension -1409625905161306112: [-1409625905161306112, 8](heap SymNode pointerreinterpreted as int64 in
at::detail::empty_generic)dense_to_jagged_forward.cuand the CPU variant forward anstd::optional<at::SymInt> total_Lstraight intoat::empty_symint({total_L, D}, ...). The atenempty.memory_formatCUDA/HIPwrapper at
RegisterCUDA_0.cppcallsC10_AS_INTARRAYREF_SLOWon the sizearray, which
TORCH_CHECKs that noSymIntin the array isis_heap_allocated(). Any heap-allocatedSymIntarriving here (e.g. anunbacked SymInt produced inside a
torch.compileregion in production)trips that check, or - depending on how the dispatcher walked the array -
leaks the
SymNodepointer through as a rawint64_tdimension.WHAT: Realize
total_Lto a concreteint64_tviaguard_int(__FILE__, __LINE__)before constructing the output tensor, and switch the allocationfrom
at::empty_symint/at::zeros_symint(SymInt-shape) toat::empty/at::zeros(int64_tshape). For heap SymInts with a hint or a runtimeguard
guard_intresolves cleanly to the concrete value; for truly unbackedSymInts with no value the kernel now produces a clean
"Could not extract specialized integer from data-dependent expression"error instead of the low-level memory crash.
Same fix applied to both the CUDA/HIP kernel
(
src/jagged_tensor_ops/dense_to_jagged_forward.cu) and the CPU kernel(
src/jagged_tensor_ops/jagged_tensor_ops_cpu.cpp).Adds a regression test
test_dense_to_jagged_heap_symint_total_Lthatconstructs an unbacked, heap-allocated SymInt via
ShapeEnv.create_unbacked_symint()and callstorch.ops.fbgemm.dense_to_jaggeddirectly. Pre-fix the test fails with theSymIntArrayRefcrash; post-fix it passes (asserting the cleanguard_interror path).
Differential Revision: D108236923