ggml-cuda : use int64 for norm forward dst offset (match rms_norm_back)#24214
Closed
palios-taey wants to merge 1 commit into
Closed
ggml-cuda : use int64 for norm forward dst offset (match rms_norm_back)#24214palios-taey wants to merge 1 commit into
palios-taey wants to merge 1 commit into
Conversation
The forward norm kernels computed ((sample*nchannels+channel)*nrows+row)*ncols in 32-bit int, overflowing for tensors with >INT_MAX elements. rms_norm_back_f32 already uses int64_t for this; promote the forward offset to match. Signed-off-by: Jesse LaRose <jesse@taey.ai>
|
Hi @palios-taey, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Author
|
Going to close this one. On a closer look, the forward |
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.
The forward norm kernels (
norm_f32,rms_norm_f32,l2_norm_f32) compute the destination offset in 32-bitint:nrows/nchannelscome fromgridDim, and all factors areint, so for a tensor with more thanINT_MAXelements the product overflows and the kernel writes out of bounds. The matching backward kernelrms_norm_back_f32already guards this withint64_t:dst += int64_t(row)*ncols;This promotes the three forward offsets to
int64_tthe same way, by casting the first factor:dst += ((int64_t(sample)*nchannels + channel)*nrows + row)*ncols;The source-pointer arithmetic already uses
int64_tstrides, so only the destination offset needed it. No behavior change for normal sizes; this just makes the forward path consistent with the backward kernel and removes the latent overflow on very large tensors.AI usage disclosure: AI-assisted finding the overflow (fuzzing the cuda norm ops under compute-sanitizer) and drafting the fix. Reviewed it, own it.