Fix overflow of padding/unpadding kernel#2548
Merged
Merged
Conversation
Contributor
Greptile SummaryFixed critical integer overflow bug in FP8 padding/unpadding CUDA kernels that caused illegal memory access and NaN values when processing large tensors.
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CPU as CPU Host
participant Kernel as CUDA Kernel
participant Memory as GPU Memory
CPU->>CPU: Calculate tensor dimensions
Note over CPU: num_rows, row_length (int)
CPU->>Kernel: Launch multi_padding_kernel/multi_unpadding_kernel
Kernel->>Kernel: Calculate tile position
Note over Kernel: tile_row, tile_col
loop For each iteration
loop For each vector element
Kernel->>Kernel: Calculate row index (int)
Kernel->>Kernel: Cast to size_t: row_offset = (size_t)row * row_length
Note over Kernel: Prevents int overflow for large tensors
Kernel->>Memory: Read input[row_offset + col + j2]
Memory-->>Kernel: Return data
Kernel->>Kernel: Process data
Kernel->>Memory: Write output[row_offset + col + j2]
end
end
Kernel-->>CPU: Complete execution
|
Contributor
Greptile found no issues!From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
Collaborator
|
Please sign-off the commit to pass the DCO check. Thanks. |
Signed-off-by: fuyue.lj <fuyue.lj@antgroup.com>
f6c4bd1 to
6be7eb6
Compare
Collaborator
|
/te-ci pytorch |
Member
|
/te-ci L0 L1 |
13 tasks
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
This PR fixes a NaN issue in the fp8 padding/unpadding kernel when handling a huge shape input in Fp8Unpadding/Fp8Padding forward. Since the data type of row and row_length is int, if the value of row*row_length is bigger than max value of int, these overlow can result in an illegal memory access on cuda or forward loss/grad norm NaN
eventually.e.g:
RuntimeError: Rank 62, device 6, iteration -1: Unexpected result nan (message='found NaN in local forward loss calculation').
CUDA Error: an illegal memory access was encountered.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: