Skip to content

ggml-openvino : fix 2D/3D view input shape inference - #303

Draft
mostafafaheem wants to merge 15 commits into
ravi9:dev_backend_openvinofrom
mostafafaheem:unsqueeze_before_view
Draft

ggml-openvino : fix 2D/3D view input shape inference#303
mostafafaheem wants to merge 15 commits into
ravi9:dev_backend_openvinofrom
mostafafaheem:unsqueeze_before_view

Conversation

@mostafafaheem

Copy link
Copy Markdown

Overview

  • Some weight tensors have 2D/3D shapes which would be incompatible with the 4D slices emitted in the process_view_input_new util. This PR introduces an Unsqueeze to 4D in order to avoid this issue.

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, AI told me how to use Unsqueeze and I used tab autocomplete for the 2nd if block

mostafafaheem and others added 15 commits August 25, 2026 22:17
ci:ggml-ov: Skip recurrent state rollback tests
ggml-openvino : add env-var gated op support debugging
OpenVINO backend: Support Whisper.cpp
Static shapes:
- get_graph_input_shape() left the s_copy / s_copy-leaf inputs dynamic
  ([1,1,1,-1]) even in static mode, which propagated a dynamic slot dim through
  GET_ROWS into the conv/GDN state, the state reshapes and the GDN output.
- With -np 1 the s_copy defrag remainder gathers zero rows; short-circuit that
  CPY to the untouched cache instead of emitting a degenerate Slice/Concat, and
  skip binding its zero-byte ggml tensor as an output (the dynamic path already
  did the latter, the static path wrote the full cache over a 0-byte buffer).

Token-count independence:
- In static mode the compiled model's token count is the prefill chunk size or
  1, not the captured cgraph's. Offsets derived from the captured count were
  therefore wrong. Anchor the GDN state slice at the end of the packed
  [attn | state] output and drop the rs_src_begin runtime inputs, and make
  VIEWs over the GDN output / conv_input pass through so the consumer does the
  slicing.
- CONT could not identify its token axis when the graph was captured with a
  single token (every trailing dim has the same stride and size 1) and baked
  the captured shape into the prefill model.

Chunked prefill:
- The last chunk is padded with fabricated tokens. Attention masks them, but
  the recurrent path folded them into cache_r/cache_s permanently. Add a
  chunk_valid_len runtime input, use it to zero g and beta for padded steps
  (making the recurrence an exact identity) and to end the conv snapshot window
  at the last valid token, and disable the recurrent-cache reset after the
  first chunk so earlier chunks are not wiped.
- get_is_prefill() and the chunk loop bound read inp_pos->ne[0] directly, but
  IMROPE stacks 4 position planes, so every decode step was run through the
  padded prefill model and the loop ran extra out-of-bounds chunks.

cache_rs_reset_idx/len now stay runtime Parameters in static mode, since
can_reuse_statically() does not invalidate the cached model on ComputeParams
changes. Add GGML_OPENVINO_FORCE_STATIC to exercise the static path on CPU.
@mostafafaheem

mostafafaheem commented Aug 27, 2026

Copy link
Copy Markdown
Author

@cavusmustafa @wine99 @zhaixuejun1993 Interested to know what you think about this.

Side note: I was tempted to do some more changes in this PR that I found already were done in #240. It would be nice if that PR was merged after rebasing and resolving conflicts. I'd be happy to take that on if you want.

@mostafafaheem
mostafafaheem marked this pull request as draft August 27, 2026 19:16
@mostafafaheem

Copy link
Copy Markdown
Author

Converted to draft until end-to-end execution on Gemma 4 MMProj (model where this issue was encoutered) is correct.

@wine99
wine99 force-pushed the dev_backend_openvino branch from 01d5a57 to 40d3fdd Compare August 28, 2026 01:36
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.

3 participants