Skip to content

ggml-openvino: swap the dynamic dim in TRANSPOSE also when both dims have the same size - #464

Open
osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-transpose-dim-swap
Open

osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-transpose-dim-swap

Conversation

@osabnis

@osabnis osabnis commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Overview

GLM-4.7-Flash with -fa off fails on GPU during the first decode step after a 400-token prompt.

compute_node_dynamic_dims() currently handles TRANSPOSE using the same rule as RESHAPE. When the source and destination shapes are equal, this preserves the source's dynamic dimension instead of moving it to the transposed axis.

This affects MLA's compressed KV cache view [512, n_kv]. When n_kv = 512, the transpose does not change the tensor shape, so the KV dynamic dimension remains on the wrong axis. As a result, V retains a fixed length of 512 while K and the attention mask are padded to 768, causing a MatMul dimension mismatch.

Changes

  • Add a dedicated TRANSPOSE case in compute_node_dynamic_dims().
  • Swap dimensions 0 and 1, following the existing PERMUTE rule, instead of applying the RESHAPE dynamic-dimension handling.

Results

Tested with GLM-4.7-Flash Q4_K_M using:

llama-bench -fa 0 -b 1024 -ub 1024 -p 0 -n 128 -d 400 --no-warmup
Build Result
a97d80a6a Fails with Incompatible MatMul matrix dimension. First input dimension=768 ... second input dimension=512
a97d80a6a + this change Passes: tg128 @ d400 = 61.27 t/s

Additional validation

  • Perplexity testing does not exercise this issue because it does not perform single-token decode.
  • With -fa off -ub 1024, perplexity results across 4 chunks are identical before and after the change (KLD 0.070493).
  • Without --no-warmup, the benchmark fails earlier due to a separate issue addressed by L12.

Requirements

  • I have read and agree with the contributing guidelines.
  • AI usage disclosure: YES - AI assistance was used for analysis and running tests.

@osabnis
osabnis force-pushed the ov-transpose-dim-swap branch from e2c1260 to cdf6172 Compare November 28, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant