Skip to content

ggml-openvino: reconvert decoder when a one-token graph is reused with more tokens - #465

Open
osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-single-token-decoder-reuse
Open

osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-single-token-decoder-reuse

Conversation

@osabnis

@osabnis osabnis commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Overview

GLM-4.7-Flash with -fa off fails on GPU when a multi-token prompt follows a one-token decode. This occurs with llama-bench -d 400, where the warm-up performs a one-token decode before the 400-token depth prompt.

The failure occurs because the decoder cache key does not include tensor shapes. Consequently, a decoder converted from the one-token graph is reused for the 400-token graph.

The dynamic dimensions in the converted model were derived from the one-token graph, where Vcur = reshape_3d(kv_cmpr, 512, 1, n_tokens) cannot distinguish between dimensions 1 and 2. When the model is reused for the multi-token graph, this results in incompatible shapes during the K/V cache concatenation:

Concat Kcur-0:
[1,1,400,512] and [1,400,1,64]

This change ensures that a decoder converted from a one-token graph is not reused for graphs with multiple tokens.

Changes

  • Add GgmlOvDecoder::can_run_tokens() to check whether a converted decoder can run a graph with the requested number of tokens.
  • Restrict decoders converted from one-token graphs to running one-token graphs only.
  • Update the dynamic-path decoder cache-hit check to use can_run_tokens() alongside has_same_graph_io().
  • When a cached decoder cannot handle the requested token count, convert the graph again. The newly converted decoder can then handle subsequent decode steps.

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
Build Result
a97d80a6a Fails during the depth prompt with Concat ... Shape inference input shapes {[1,1,400,512],[1,400,1,64]}
a97d80a6a + this change Depth prompt completes; the first decode step still requires L4
a97d80a6a + all 8 of our PRs, including L4 and this change Passes: tg128 @ d400 = 49.39 t/s

The extra conversion happens only when the first graph has a single token. Perplexity and llama-cli start with the prompt, so they do not take this path.

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-single-token-decoder-reuse branch from b1ae567 to 554566f 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