Skip to content

ggml : fix dimension and stride truncation in ggml_permute - #29227

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
leejet:fix/ggml-permute-overflow
Sep 21, 2026
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
leejet:fix/ggml-permute-overflow

Conversation

@leejet

@leejet leejet commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Overview

Preserve tensor dimensions and byte strides in ggml_permute using int64_t and size_t, avoiding truncation through int.

Additional information

ggml_permute() copies tensor dimensions (int64_t) and byte strides (size_t) through temporary int arrays. Values exceeding INT32_MAX are truncated before being assigned back to the output tensor.

For example, an F32 tensor shaped [1536, 2048, 288, 1] has:

      nb[3] = 1536 * 2048 * 288 * 4 = 3,623,878,656 bytes

This exceeds INT32_MAX (2,147,483,647). On the affected platform, conversion to int produces -671088640. Converting that negative value back to 64-bit size_t produces an enormous, invalid stride.

Requirements

@leejet
leejet requested a review from ggerganov as a code owner September 21, 2026 14:09
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 21, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

Hi @leejet, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 8 open PRs.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ggerganov
ggerganov merged commit c21284c into ggml-org:master Sep 21, 2026
1 check passed
@BrewTestBot BrewTestBot mentioned this pull request Sep 23, 2026
1 task done
LadislavSopko pushed a commit to 0ics-srls/llama.cpp that referenced this pull request Oct 5, 2026
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
nicheng251 added a commit to nicheng251/bonsai-turboquant-llama.cpp that referenced this pull request Oct 23, 2026
Port five small upstream fixes that apply to code this fork ships:

- fattn-vec: sync the warp at the end of the VKQ loop (ggml-org#30573). The next
  iteration's KQ write reused the shared buffer while other lanes were
  still reading it.
- cpy: the transposed fast path requires a contiguous destination (ggml-org#27663).
  It wrote to a non-contiguous dst as if it were dense.
- llama-kv-cache: only upload k_rot when the tensor has a buffer (ggml-org#27967).
  An unquantized K cache has no k_rot buffer and context shift crashed.
- ggml_permute: keep dims and strides 64-bit (ggml-org#29227). The int temporaries
  truncated large tensors.
- convert: run contiguous conversions four elements per thread (ggml-org#29155).

Verified: FLASH_ATTN_EXT turbo 25/25, 27B Bonsai PTQ1_0 model smoke with
q8_0 K + turbo3 V (prefill 547 tok/s, decode 31.2 tok/s at 2K; 30.0 at 17.4K).

The stock q8_0/q8_0 long-sweep crash is not caused by the WAR hazard: it
still aborts after 361 cases with this fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants