OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GGUF FE] Recurrent-state ops and dynamic-token support (#37023)
Maxim Vafin8c3c354fae02
diff --git a/src/frontends/gguf/docs/debugging_accuracy.md b/src/frontends/gguf/docs/debugging_accuracy.mdnew file mode 100644index 00000000000..1d1811e9889--- /dev/null+++ b/src/frontends/gguf/docs/debugging_accuracy.md@@ -0,0 +1,362 @@+# Debugging Accuracy Issues in the GGUF Frontend / OpenVINO Backend++How to find *why* a GGUF model produces wrong output through the OpenVINO frontend ++`ggml-openvino` backend, versus the reference llama.cpp CPU path.++A field guide, not a spec: the techniques that have paid off and the traps that wasted+time. Read it before reaching for a debugger.++---++## The one rule: always have an authoritative reference++Every accuracy claim is a comparison, and the reference must be **the real llama.cpp CPU+implementation** — never one you derived by hand. A hand-written reference (numpy, a C+++recurrence from the paper) encodes *your* understanding of the op's layout; if that is wrong+the same way the frontend is, the two agree and the bug hides — or, worse, a correct frontend+"fails" against your buggy reference and you chase a phantom.++If you catch yourself typing out an op's math to build an expectation, stop and generate it+from ggml instead (see [The ggml-CPU oracle](#the-ggml-cpu-oracle)).++> Trap: with one head (`H=1`) many layout orders coincide, so a single-head unit test can pass+> against a wrong reference and give false confidence. Test at real dimensions (step 9).++---++## Bisection strategy, coarse to fine++Work from the cheapest, coarsest signal to the finest; each step narrows the search space for+the next. Don't open a debugger until these have cornered the bug.++### 1. Is it an OpenVINO bug at all?++When the output *text* is bad but the graph runs end-to-end, first decide whether OV is even at+fault, by comparing against a genuine ggml-CPU run of the **same model at the same commit**.++> ⚠️ **A build with `-DGGML_OPENVINO=ON` has no CPU backend.** The OV backend registers as a+> ggml *device* (`OPENVINO0`); no CPU device is registered (`llama-cli --list-devices` shows+> only `OPENVINO0`). So every "CPU" knob silently runs OV: `env -u GGML_OPENVINO` and+> `GGML_OPENVINO=""` do nothing (it's a device, not gated by that var), `--device none` runs+> OV, and `GGML_OPENVINO_DEVICE=CPU` runs OV-on-CPU. "I compared CPU vs OV and they matched" is+> really OV vs OV — a conclusion that has wasted days.++The only reliable CPU reference is a second build with OV compiled out, at the same commit:++```+cmake -B build-cpu -DGGML_OPENVINO=OFF -DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF+cmake --build build-cpu --target llama-simple llama-eval-callback -j$(nproc)+```++Compare greedy on **`llama-simple`** (raw completion, no chat template — see the gotcha below):++```+./build-cpu/bin/llama-simple -m <model>.gguf -n 20 "The capital of France is" # true ggml CPU+./build-ov/bin/llama-simple -m <model>.gguf -n 20 "The capital of France is" # OpenVINO+```++- **Both good** → port correct, done.+- **CPU good, OV bad** → a genuine OV bug; localize with the steps below against `build-cpu`.+- **Both bad** → only now may it be a shared llama.cpp/model/template issue; confirm the CPU+ build is genuinely OV-free (`--list-devices`) before believing it.++> **The chat template hides the signal.** `llama-cli`/`llama-completion` apply the model's chat+> template; a thinking model then emits `<think>` and reasons instead of completing, so greedy+> output looks degenerate even when the math is fine. Use `llama-simple` for bisection; reserve+> `llama-cli` for judging end-user quality *after* the math is verified.++### 2. Graph bug or quantization?++Run the **same quantized weights** through the CPU reference and OV, both greedy, and compare+the first token. Reference right + OV wrong on identical weights ⇒ quantization is ruled out,+it's a graph/conversion bug. Don't download a higher-precision model to "check quantization" —+this already answered it for free (and big models often OOM in the frontend; see Gotchas).++### 3. Prefill or decode?++`-n 1` (prefill only) vs `-n 12` (prefill + decode). First token already wrong → the bug is in+the prefill graph; ignore all state/KV/decode machinery. Prefill right, later tokens drift →+suspect stateful bookkeeping, the KV/recurrent-state round-trip, or a decode-only path.++### 4. First-divergence diff (highest-yield localization)++Dump every node's output on both backends and diff in graph order. `llama-eval-callback` fires+per ggml node and prints name, op, shapes and a per-tensor **`sum`** — a cheap, position-stable+fingerprint. Node names repeat across layers/experts, so align the two logs **positionally**,+not by name.++```+./build-cpu/bin/llama-eval-callback -m <model>.gguf -p "The capital of France is" -n 1 > /tmp/cb_ref.log 2>&1+GGML_OPENVINO_DEVICE=CPU GGML_OPENVINO_STATEFUL_EXECUTION=1 \+ ./build-ov/bin/llama-eval-callback -m <model>.gguf -p "The capital of France is" -n 1 > /tmp/cb_ov.log 2>&1++awk '/cb_eval:/{n=$2} /sum = /{print n"\t"$3}' /tmp/cb_ref.log > /tmp/ref_pos.txt+awk '/cb_eval:/{n=$2} /sum = /{print n"\t"$3}' /tmp/cb_ov.log > /tmp/ov_pos.txt+paste /tmp/ov_pos.txt /tmp/ref_pos.txt | awk -F'\t' '{+ d=$2-$4; if(d<0)d=-d; b=($4<0?-$4:$4); if(b<1)b=1; rel=d/b;+ flag=($1!=$3)?" NAME-MISMATCH":(rel>0.001?" <<< DIFF":"");+ printf "%3d %-26s ov=%-12s ref=%-12s%s\n", NR,$1,$2,$4,flag }'+```++Judgement calls, all learned the hard way:++- **The first *visible* divergence is usually not the root cause** — often benign kernel+ rounding (a sub-0.2% matmul diff). Confirm a candidate by *eliminating* it (steps 6–7) and+ seeing the output change; never assume.+- **Only tensors at subgraph boundaries carry real data** (see the trustworthy-tensor rule in+ step 5); interior nodes read `0` or stale, so a zero-vs-nonzero "difference" there is an+ artifact.+- **The callback perturbs OV's graph split** (it forces boundaries) and may crash OV early, but+ the prefix is usually enough to find the *first* divergence. For a full-depth sweep that+ doesn't perturb the split, use `GGML_OPENVINO_DEBUG_OUTPUT` (step 5).+- **Positional alignment holds only until node order/count diverges** between backends. Past the+ first genuine name mismatch, trust only rows where both names still agree.++### 5. Per-layer sweep — element-wise cosine, never Min/Max/Mean++> ⚠️ **A permutation-invariant statistic cannot see a permutation bug.** `sum`, mean, min and+> max are unchanged when a tensor's elements are *reordered*. A whole class of bugs only reorders+> correct values — partial-rotary rope rotating the wrong slice, a head-scramble from a bad+> reshape/transpose, interleaved-vs-split-halves, any layout error on an axis a size-1 dim would+> collapse. A statistic-based per-layer sweep then reports "small diffuse drift, no single broken+> layer" — a false verdict that has sent debugging down a precision rabbit hole for a day.+> **Never conclude "drift" from a permutation-invariant metric.**++`GGML_OPENVINO_DEBUG_OUTPUT=1` prints First/Min/Max/Mean per *subgraph output* at its natural+boundary (no split perturbation, no early crash), covering every layer to `result_output`. But+compute **element-wise cosine** against the reference, not the printed statistics:++```+cos = dot(ov, ref) / (norm(ov) * norm(ref))+```++Cosine is ~1.0 when the buffers agree elementwise and collapses the instant elements are+reordered. Sweep it per layer on full-width, same-named, genuine-boundary tensors. The shape of+the curve *is* the diagnosis:++- **A sharp cliff** at one layer (e.g. 0.999997 → 0.43 between neighbours) = a **localized+ structural bug** there. Align the cliff to what that layer does differently (e.g. "first layer+ downstream of a rope layer") to point at the op.+- **A gentle monotone slope** from ~1.0 = genuine accumulating precision drift — a verdict you+ earn only when cosine *also* shows a smooth slope.++To place both backends at every layer despite OV crashing early under the eval-callback, match+the complete ggml-CPU eval-callback `sum` per layer (÷ element count) against the OV+`DEBUG_OUTPUT` mean for the same layer: a small, one-signed, compounding diff with no single jump+is a mildly biased op applied every layer; a single jump is a localized bug. (To gauge severity,+bias logits with `-l <TOKEN_ID>±N` and bisect N until top-1 flips — a tight reference margin but+a large OV displacement means real distortion, not a rounding-broken tie.)++> **Trustworthy-tensor rule (applies to steps 4, 5, 8).** ggml reuses scratch buffers, so an+> interior tensor promoted to an output can read memory already clobbered by a later op — you get+> plausible garbage. Only **persistent buffers** are safe to compare cross-backend: the+> KV/recurrent-state caches (`cache_k/v/r/s`) and genuine subgraph-boundary outputs. A pure+> `TRANSPOSE` that appears to change its element `sum` is diagnostic *of this artifact*, not of a+> transpose bug. Promote at most **one** interior tensor per run; several at once perturb+> allocation and corrupt each other. Confirming a cache write matches the reference also *bounds*+> the bug: everything feeding it is correct, so the fault is downstream.++### 6. Quant-path isolation — `GGML_OPENVINO_DISABLE_TYPES`++Forcing a *type* to CPU is surgical: it moves only that quant type's tensors to ggml while+leaving graph structure intact (unlike forcing an op, step 7). Two high-value moves:++- Disable **one** suspect type to test whether that quant kernel is the culprit.+- Disable **all** materialized quant types at once+ (`Q4_0,Q4_1,Q4_K,Q5_K,Q8_0,Q6_K,Q5_1,MXFP4`): every weight matmul then runs on ggml with+ bit-identical weights and OV executes only the f32/f16 structural ops. Still wrong ⇒ the bug is+ **structural**, every quant kernel decisively ruled out — a narrowing no single op-force gives.++### 7. Op-family isolation — `GGML_OPENVINO_DISABLE_OPS`++`ggml_backend_openvino_device_supports_op()` decides per op whether OV claims it or ggml's CPU+kernel runs. `GGML_OPENVINO_DISABLE_OPS=SSM_CONV,DIV` forces the listed ops to CPU; binary-search+the suspect set. For a novel arch, start with the arch-specific ops (shared ops are already+exercised by working models).++- **Output correct** → that op (or its glue) was the bug.+- **Output unchanged** → op exonerated.+- **New crash / shape error** → *inconclusive*, not guilt: forcing an op re-splits the graph and+ can surface an unrelated boundary bug. Try another combination, or go to the op-level test.++### 8. Pinpoint a layout / wrong-source bug — full-element dumps, multiset, distribution matching++A cosine cliff (step 5) says *where* the graph scrambles and *that* the bug is a permutation, not+arithmetic. It doesn't say *what* the wrong tensor is a permutation *of* — usually the whole+answer, because a scramble means the op read the **wrong source region** (a neighbouring head,+the sibling half of a joint projection, a strided window read as contiguous).++Dump full element order (not statistics) on both backends:++- OV: `GGML_OPENVINO_DUMP_TENSOR=<name-substr>` → `/tmp/ov_dump_*`, one float per line.+- CPU: `GGML_DUMP_TENSOR=<name-substr>` (ggml eval-callback) → `/tmp/ref_dump_*`.++Then two comparisons in order:++1. **Multiset (sorted) comparison — layout vs math.** Sort both dumps' nonzero values and+ compare. Sorted-match ≈ 1.0 but position-wise cosine low ⇒ the numbers are right, only+ positions wrong: a pure layout/read bug — look at layout, not any kernel's math. Sorted-match+ also low ⇒ the values differ: a real arithmetic bug — back to steps 6–7 and the oracle.+2. **Distribution matching against multiple candidate references — the wrong-source finder.**+ When step 1 says "right numbers, wrong place," the values came from *somewhere*. Dump several+ candidate reference tensors near the suspect (the sibling projection half, the adjacent head,+ the pre-/post-transform version) and compare the OV tensor's distribution (sorted multiset;+ range/mean/std as a quick fingerprint) to each. "OV's X matches the reference's *Y*, not X"+ names the region the op wrongly grabbed. (Obey the trustworthy-tensor rule.)++Then read the offending op's layout directly. Very often it's a `VIEW`/reshape: dump its ggml+geometry (`ne[]`, `nb[]` strides, offset) and the `op_case` the decoder assigned. A view whose+source is strided/gapped (stride ≠ extent, a sub-block of a larger group) but classified as a+*dense contiguous* window is the bug — the contiguous handler slices through the gap and+scrambles elements. Fix the **classification** (a stride/density check that routes the strided+case to a stride-aware handler), not the consumer. `GGML_OPENVINO_DUMP_CGRAPH=1` gives `ne[]`; a+temporary `getenv`-gated `fprintf` at the classification site gives `nb[]`/offset/op_case.++### 9. Reproduce at the op level with a ggml oracle++Once an op is implicated, stop testing through the full model and reproduce it in the frontend's+unit tests (`tests/test_ops.cpp`), which build a one-op `ov::Model` via `SingleOpBuilder` and run+on CPU in milliseconds. This is where the bug is pinned and the regression test lives.++Feed **real model dimensions**, not `1×1×1` — most layout bugs live on an axis a size-1 dim+collapses: multi-head (`H>1`), GQA repeat (`H_v ≠ H_k`), multi-token (`T>1`), batch (`B>1`). Pull+the real shapes from a cgraph dump (`GGML_OPENVINO_DUMP_CGRAPH=1`). A test that passes at `H=1`+proves nothing about a model that uses `H=32`.++---++## The ggml-CPU oracle++For ground-truth op values, build a tiny C program that links `libggml` + `libggml-cpu`, builds a+one-node graph, runs it on CPU, and prints the output — those numbers become the `expected`+array. `tests/gdn_oracle.c` is a worked example; copy its structure.++```+gcc <op>_oracle.c -o <op>_oracle \+ -I <llama.cpp>/ggml/include \+ -L <llama.cpp>/build-ov/bin -lggml -lggml-base -lggml-cpu -lm \+ -Wl,-rpath,<llama.cpp>/build-ov/bin+LD_LIBRARY_PATH=<llama.cpp>/build-ov/bin ./<op>_oracle+```++- **Link against the same `libggml` the backend uses.** A stale tree can assert on a different+ shape than the source you're reading.+- Set `no_alloc = true` when using `ggml_backend_alloc_ctx_tensors`.+- Read the op's shape contract from the **header** (`ggml.h`); don't guess `ne[]` order.+- Fill inputs with distinct, asymmetric values so a transposed/mis-strided axis changes a number.+- If the op has more than one conversion path (e.g. a fused internal op and a decomposed Loop+ fallback), assert **both** against the oracle — matching a shared oracle proves both correct.++---++## Bug archetypes++Concrete structural bugs seen so far, each with the generalizable lesson. When a cosine cliff or+a dynamic-shape crash points near one, check it first.++**A. Geometry read from the tensor instead of the config.** Partial-rotary rope: a head is 256+wide but only the first 64 dims rotate; taking the rotary width from the tensor's last dim (256)+rotates the pass-through tail and corrupts every layer using that op. *Lesson: an op must read+its geometry (rotary width, head count) from the model config, not a tensor dim — the two differ+whenever a dimension is partial. A test at full width can't catch it.*++**B. A shared precomputed table built with the wrong config flag.** A sin/cos table computed once+and shared across layers must be built with the same per-op config its consumers assume; a mode+flag defaulting wrong makes the table's token axis mismatch the data and broadcast-crashes at the+consuming `Multiply`. *Lesson: a shared/precomputed value must be built with the consumer's+config; the symptom is a shape/broadcast mismatch, not a wrong number.*++**C. A dynamic-axis slice with a baked absolute offset.** A tail slice (the last *k* columns of a+window whose length varies prefill vs decode) emitted with an absolute start computed at prefill+over-reads at decode. *Lesson: anchor a slice to the end it's pinned to — negative start, open+end — never to an offset baked at prefill.*++**D. A strided VIEW mis-classified as contiguous.** An interleaved layout+(`[A_h0, B_h0, A_h1, B_h1, …]`) gives a per-`A` view a group stride larger than its extent;+classified as a dense window, the contiguous handler slices through the gap and scrambles heads.+*Lesson: a VIEW's handler must be chosen from its strides (`nb[]`), not its element count — two+views with identical shape and offset but different strides need different handlers.*++> Meta-pattern behind all four: a value *correct for prefill / the common case* (full head, one+> rope mode, prefill length, a contiguous layout) is hard-coded instead of read from the true+> per-op/per-step geometry, so it silently breaks at decode or on a different architecture.++> **After any shared-path fix — especially a VIEW/`op_case` predicate — re-run the other+> supported models and confirm their classification/output is unchanged.** A stride/density guard+> that fixes arch A can reject arch B's legitimately-contiguous view.++---++## Debug env vars++Backend seams live in `ggml/src/ggml-openvino/`. Gate any new debug output on a `getenv` check+and write to `stderr`.++| Env var | Effect |+|---|---|+| `GGML_OPENVINO_DEVICE=CPU` | Run OV on CPU. (Still OV, not ggml — see step 1.) |+| `GGML_OPENVINO_STATEFUL_EXECUTION=1` | Enable the stateful KV/recurrent-state path (real decode flow). |+| `GGML_OPENVINO_DUMP_CGRAPH=1` | Dump each OV subgraph as `cgraph_ov_N.txt` — ops, names, per-tensor `ne[]`. Primary tool for real op dimensions and how the graph split. |+| `GGML_OPENVINO_DUMP_IR=1` | Serialize each compiled subgraph to `model_*.xml`. Unavailable for models with internal (non-serializable) ops. |+| `GGML_OPENVINO_DEBUG_INPUT=1` / `_DEBUG_OUTPUT=1` | Print each bound input / output tensor (name, shape, First/Min/Max/Mean). |+| `GGML_OPENVINO_DUMP_TENSOR=<substr>` | Dump **full element order** of each matching OV output to `/tmp/ov_dump_*` (one float/line) — for the position-wise + multiset compare of step 8; not permutation-invariant. |+| `GGML_DUMP_TENSOR=<substr>` (ggml `common/debug.cpp`) | CPU-reference counterpart: matching tensors from the ggml eval-callback, in element order. |+| `GGML_OPENVINO_DISABLE_OPS=SSM_CONV,DIV` | Force listed ggml ops to CPU (step 7). Re-splits the graph — a new crash is inconclusive. |+| `GGML_OPENVINO_DISABLE_TYPES=Q8_0,Q6_K` | Force listed quant types to CPU without changing graph structure (step 6). |+| `GGML_OPENVINO_FORCE_F32=1` | Pin the plugin to f32 ACCURACY mode to test bf16 rounding accumulation. |+| `GGML_OPENVINO_PROFILING=1` | Per-stage timing (decode/convert/compile/infer). |+| `GGML_OPENVINO_PRINT_CGRAPH_TENSOR_ADDRESS=1` | Tensor address map (trace pointer aliasing between subgraphs). |++The frontend converter carries no env-var debug seams — keep them in the backend. When an op has+two conversion strategies, expose the alternate as an op attribute (e.g. GatedDeltaNet's+`force_ref` selects the serializable Loop path) so a unit test can pick it via `SingleOpBuilder`+without touching process env or the production default.++---++## Gotchas++- **Big models OOM in the frontend, not just in weight RAM.** Quant types in `supported_types`+ are materialized as OV constants *in addition to* ggml's copy, ~doubling peak compile memory.+ Reducing `-c` doesn't help (the blow-up is per-subgraph compilation, not the KV cache). A Q4_K+ model can OOM where the same-arch Q2_K runs (Q2_K isn't in `supported_types`, stays on CPU).+ Exit 137 = OOM-killed.+- **Iterate on a small quant.** BF16 of a 4B model can take ~25 min to load/compile; Q4_K_M loads+ in seconds and reproduces the same *structural* bugs. Reach for higher precision only if step 2+ implicates quantization.+- **Per-subgraph vs shared runtime state.** A model that splits into many subgraphs per token step+ must not share single-value bookkeeping across them (e.g. `stateful_kv_size` belongs on the+ per-subgraph context, not the shared one) — a shared counter advances once per subgraph and+ mis-slices state. Symptom: a ROI error at the *second* decode step, not the first.+- **An old reference build can predate the arch** and segfault on load — then it can't be the+ reference; use a fresh `-DGGML_OPENVINO=OFF` build at the current commit (step 1).+- **Shell:** piped `llama-*` output buffers and never flushes — redirect to a file and grep it.+ `cd` doesn't persist between calls (use absolute paths). `pkill -9 -f llama` between runs so+ stale processes don't starve cores.++---++## Checklist++1. **Is it an OV bug?** `build-cpu` (`-DGGML_OPENVINO=OFF`) vs `build-ov`, greedy, on+ `llama-simple`. CPU good + OV bad = OV bug. Both bad = shared (build/tokenizer/template), stop+ debugging OV.+2. **Graph or quant?** Same weights, CPU ref vs OV. Wrong on OV only → graph bug, not quant.+3. **Prefill or decode?** `-n 1` vs `-n 12`.+4. **First-divergence diff** (`llama-eval-callback`, positional `sum` diff) → first node past+ rounding. Highest-yield step.+5. **Per-layer sweep with element-wise cosine**, never Min/Max/Mean. Cliff = localized structural+ bug; smooth slope = drift. Never conclude "drift" from a permutation-invariant metric.+6. **`DISABLE_TYPES=<all quant>`** → still wrong ⇒ structural (f32) bug, quant ruled out.+7. **`DISABLE_OPS`** to force a suspect op to CPU; binary-search. Correct = culprit; new crash =+ inconclusive (re-split artifact).+8. **Layout pinpoint:** full-element dumps → multiset compare. Sorted-match high + cosine low =+ layout/wrong-source bug; match the distribution against candidate references to name the+ source. For a `VIEW`, inspect `nb[]` + `op_case`, not just `ne[]`.+9. **Op-level test** in `test_ops.cpp` at real dimensions (H, GQA, T, B not collapsed), against a+ **ggml-CPU oracle**, never a hand-derived reference; assert every conversion path; leave it as+ a regression guard.+10. **Cross-arch regression:** after any shared-path fix, re-run the other supported models.++> Only a divergence you can *eliminate* — and thereby fix the output — is the real culprit; the+> first visible one is often benign rounding.diff --git a/src/frontends/gguf/docs/internal_ops.md b/src/frontends/gguf/docs/internal_ops.mdnew file mode 100644index 00000000000..d3a0e82b533--- /dev/null+++ b/src/frontends/gguf/docs/internal_ops.md@@ -0,0 +1,73 @@+# GGUF Frontend — Internal Operations Policy++## Summary++OpenVINO frontends are, as a rule, thin translators: they emit only ops from the+public opsets so that the produced `ov::Model` is portable and serializable to IR.+The GGUF frontend makes a **scoped, deliberate exception**: it is allowed to emit+ops from the shared internal opset (`ov::op::internal`, defined in `core`'s+`dev_api`) when doing so materially simplifies translation or lets the target device+use a fused kernel instead of a hand-built subgraph.++This is a pragmatic tradeoff, not a general license. It applies to the GGUF frontend+only, and only to ops that already ship as part of OpenVINO core (with registered+`type_info`, shape inference, a reference implementation, and plugin support). The+frontend never defines its own operations.++## Why this is acceptable here++Unlike a frontend-private op, a shared `ov::op::internal` op is known to the rest of+the stack:++- It has a registered `type_info`, so plugins link against it, and passes,+ matchers, and `visualize_tree` recognize it.+- Plugins that support it natively keep it (e.g. the fused CPU/GPU+ `GatedDeltaNet` kernels); plugins that do not can decompose it in their own+ pipeline. No mandatory frontend-side decomposition is forced on every consumer.+- Shape inference and a reference `evaluate` already exist and are tested in core,+ so `PartialShape` propagation and CPU fallback work without extra frontend code.++The GGUF frontend is also a `LINKABLE_FRONTEND` consumed directly by the+`llama.cpp` `ggml-openvino` backend and by OpenVINO GenAI, both of which build and+run the model in-process on a device. Neither relies on IR serialization, so the+main cost of internal ops (below) does not affect the primary use cases.++## The cost: models are not IR-serializable++An `ov::op::internal` op is **not** part of any IR serialization opset. A model that+contains one cannot round-trip through `ov::save_model` / the IR frontend, which also+means the following flows do not work for such a model:++- `ov::save_model`, `ovc`, and `benchmark_app -o`+- model caching (`ov::cache_dir`) and offline `compile_model` blob export+- weightless-cache flows++**Important behavioral note:** serialization does not currently fail loudly. An+internal op has no opset `version_id`, so `ov::pass::Serialize` writes it with+`version="experimental"` and `save_model` *succeeds*. The resulting IR is unloadable+and fails only later, at deserialize time, with an opaque "operation is not+registered" error. Do not rely on serialization to reject these models — treat any+model that went through an internal-op translation path as non-serializable by+construction.++If a serializable model is required, use a translation path built only from public+opset ops. Where an internal-op path has a core-op fallback, that fallback is+serializable — see the example below.++## Current internal ops emitted++| Op | GGML op | Path | Fallback |+|---|---|---|---|+| `ov::op::internal::GatedDeltaNet` | `GGML_OP_GATED_DELTA_NET` | `translate_gated_delta_net` (scalar gate) | `translate_gated_delta_net_ref` — a serializable `Loop` scan, used for per-key-dimension gating (`kda`) and as a portable fallback |++See [`src/op/gated_delta_net.cpp`](../src/op/gated_delta_net.cpp).++## Guidance for adding a new internal-op path++1. Only emit ops that already exist in `ov::op::internal` (core `dev_api`) with+ plugin support — do not define new ops in the frontend.+2. Prefer keeping a core-op-only reference path (as `translate_<op>_ref`) so callers+ that need serialization, or devices without native support, have a route.+3. Update the table above and note the non-serializable consequence.+4. Be aware `dev_api` internal ops are marked "under development and subject to+ change"; their inputs/attributes may shift between releases.diff --git a/src/frontends/gguf/docs/supported_models.md b/src/frontends/gguf/docs/supported_models.mdnew file mode 100644index 00000000000..6e9bddc14c3--- /dev/null+++ b/src/frontends/gguf/docs/supported_models.md@@ -0,0 +1,55 @@+# GGUF Frontend — Supported Models++This document lists the model architectures the GGUF frontend can convert and run+end-to-end. An architecture is listed as **Supported** only when at least one *real*+(non-synthetic) model of that architecture has been verified to load, convert, and+produce coherent output through the frontend.++Verification is done by running a real `.gguf` through the OpenVINO backend swap in+`llama.cpp` (`llama-completion`, CPU device, stateful execution) and confirming the+generated text is coherent and matches the pure-ggml CPU reference for the same prompt.++## Supported architectures++Each row was verified with the named real model.++| Architecture | Verified model | Notes |+|---|---|---|+| `llama` | TinyLlama-1.1B-Chat v1.0 (Q4_K_M) | Dense; standard RoPE + GQA. |+| `qwen2` | Qwen2.5-0.5B-Instruct (Q8_0) | Dense. |+| `qwen3` | Qwen3-0.6B (Q8_0) | Dense; QK-norm. |+| `qwen3moe`| Qwen3-0.9B-A0.6B (Q4_K_M), Qwen3-4B (Q4_K_M) | Mixture-of-experts (`mul_mat_id`). |+| `olmoe` | OLMoE-1B-7B-0924-Instruct (Q4_0) | Mixture-of-experts. |+| `gemma3` | gemma-3 family | Mixed sliding-window / global RoPE. |+| `gemma4` | gemma-4-E4B-it (Q4_K_M) | Per-op RoPE (SWA vs global); f16 KV cache. |+| `qwen35` | Qwen3.5-4B (Q4_K_M) | Hybrid GatedDeltaNet + full-attention layers; partial-rotary IMROPE; interleaved Q/gate joint projection; f16 KV cache. |++`llama`, `qwen2`, `qwen3`, `olmoe`, `gemma4`, and `qwen35` were verified with a fresh+end-to-end run of the model named above. `qwen3moe` and `gemma3` were verified in earlier+development on the models named above.++Quantization formats verified in the above runs: `Q2_K`, `Q4_0`, `Q4_K_M`, `Q6_K`,+`Q8_0`. The frontend weight path also handles `Q4_1`, `Q5_0`, `Q5_1` and the F16/F32+paths; these are exercised by the unit tests but have not each been tied to a specific+end-to-end real-model run.++## How verification was performed++```sh+GGML_OPENVINO_DEVICE=CPU GGML_OPENVINO_STATEFUL_EXECUTION=1 \+ llama-completion -m <model>.gguf -p "The capital of France is" -n 12 -no-cnv --no-warmup+```++A run counts as verification only when the output is coherent (e.g. completes+"...is Paris") and consistent with the pure-ggml CPU backend on the same prompt. A model+that loads but emits garbage (e.g. `hunyuan`) is **not** counted as supported.++## Adding a new architecture++Support for a new architecture is a combination of:+1. **Ops** — every ggml op in the model's compute graph must have a frontend translator+ (`src/op/<name>.cpp`) and backend admission.+2. **Weights** — every quantization format used by the model's tensors must be handled by+ the weight path (`src/quant/weights.cpp`).+3. **Real-model verification** — run a real `.gguf` end-to-end as above before adding the+ architecture to the Supported table.diff --git a/src/frontends/gguf/include/openvino/frontend/gguf/decoder.hpp b/src/frontends/gguf/include/openvino/frontend/gguf/decoder.hppindex 54f75c98812..d54fea9eac1 100644--- a/src/frontends/gguf/include/openvino/frontend/gguf/decoder.hpp+++ b/src/frontends/gguf/include/openvino/frontend/gguf/decoder.hpp@@ -35,6 +35,11 @@ struct RopeConfig {// SWA and global layers use different n_dims), so the shared rope_cos/rope_sin table that// TranslateSession::preprocess would otherwise pre-build is skipped.bool per_op = false;+ // When true the model uses interleaved M-RoPE (qwen3.5 / qwen3vl): pos carries 4 mrope sections+ // (4*n_tokens ids) and the sin/cos gather differs. The shared-table builder must know this so it+ // matches the per-op translate_rope path -- otherwise it builds a NEOX table whose token axis is+ // 4x the data's and the rope Multiply fails the eltwise broadcast check.+ bool is_imrope = false;};// Decoder interface consumed by the gguf frontend translators.diff --git a/src/frontends/gguf/src/op/cont.cpp b/src/frontends/gguf/src/op/cont.cppindex 1a167b12b2e..3e252b9a251 100644--- a/src/frontends/gguf/src/op/cont.cpp+++ b/src/frontends/gguf/src/op/cont.cpp@@ -6,7 +6,11 @@#include "op_table.hpp"#include "utils.hpp"+#include <cstdint>#include <memory>+#include <vector>+#include "openvino/op/constant.hpp"+#include "openvino/op/reshape.hpp"namespace ov {namespace frontend {@@ -29,8 +33,29 @@ OutputVector translate_cont(const NodeContext & context) {// The input comes from a TRANSPOSEreturn {context.get_input(0)};} else {- // The input comes from a VIEW- res = process_view_input(context, 0);+ // The input comes from a VIEW. Resolve the view, then reshape to the CONT's own output layout+ // (ggml_cont can merge/split dims, e.g. qwen3-next's a/b: [tok,8,2,1] -> [8*tok,2,1,1]). The+ // decoder supplies the reshape target as "cont_reshape" -- the output dims (OV order) with -1 on+ // the inferred dynamic (token) axis -- so the token count stays dynamic and a 0-token decode step+ // reshapes correctly. When the output is fully static "cont_reshape" carries no -1 (plain reshape).+ // The CONT's input is an already-resolved VIEW node (translate_view emitted its Slice/Reshape),+ // so the view offset/window is already applied -- do NOT re-slice via process_view_input, which+ // would apply the offset a second time (qwen3-next a/b: offset 2 slices axis3 [2,4) -> clamped+ // to length 0). Just reshape the resolved input to the CONT's own layout.+ auto input = context.get_input(0);+ auto tgt = context.get_attribute<std::vector<int64_t>>("cont_reshape", {});+ // No target means pass-through, which is only valid if the shape is already the CONT's own.+ FRONT_END_OP_CONVERSION_CHECK(!tgt.empty() || input.get_partial_shape().compatible(context.get_output_shape()),+ "CONT from a VIEW requires a \"cont_reshape\" target: input ",+ input.get_partial_shape(),+ " != output ",+ context.get_output_shape());+ if (!tgt.empty()) {+ auto tgt_node = ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt);+ res = std::make_shared<ov::op::v1::Reshape>(input, tgt_node, false);+ return rename_outputs_with_suffix({res}, context.get_name());+ }+ res = input;}return rename_outputs_with_suffix({res}, context.get_name());diff --git a/src/frontends/gguf/src/op/cpy.cpp b/src/frontends/gguf/src/op/cpy.cppindex a2fefcfb2a7..d6659d04ca0 100644--- a/src/frontends/gguf/src/op/cpy.cpp+++ b/src/frontends/gguf/src/op/cpy.cpp@@ -6,8 +6,12 @@#include "op_table.hpp"#include "utils.hpp"+#include <cstdint>#include <memory>+#include <vector>+#include "openvino/op/constant.hpp"#include "openvino/op/convert.hpp"+#include "openvino/op/reshape.hpp"namespace ov {namespace frontend {@@ -15,7 +19,57 @@ namespace gguf {namespace op {OutputVector translate_cpy(const NodeContext & context) {- auto res = std::make_shared<ov::op::v0::Convert>(context.get_input(0), context.get_attribute<ov::element::Type>("output_type"));+ ov::Output<ov::Node> res =+ std::make_shared<ov::op::v0::Convert>(context.get_input(0), context.get_attribute<ov::element::Type>("output_type"));++ // A CPY may reinterpret the source layout into its destination's (e.g. qwen3-next's conv-state+ // writeback flattens the contiguous [S, F] conv_state_last into the flat [S*F] recurrent cache+ // row). When the destination (output) shape differs from the source but holds the same number of+ // elements, reshape to the output layout so the model result matches the ggml cache tensor.+ const auto & out_ps = context.get_output_shape();+ const auto & in_ps = res.get_partial_shape();+ if (out_ps.is_static() && in_ps.is_static() && in_ps != out_ps) {+ const auto in_shape = in_ps.to_shape();+ const auto out_shape = out_ps.to_shape();+ int64_t in_elems = 1, out_elems = 1;+ for (auto d : in_shape)+ in_elems *= static_cast<int64_t>(d);+ for (auto d : out_shape)+ out_elems *= static_cast<int64_t>(d);+ // Only reinterpret when the element counts match. A zero-element CPY (empty defrag/no-op+ // writeback, e.g. a decode step's [.,.,0,.] conv-state copy) keeps its own shape -- reshaping+ // it to the non-empty cache layout would be an invalid element-count change.+ if (in_elems == out_elems && in_elems != 0) {+ std::vector<int64_t> tgt(out_shape.begin(), out_shape.end());+ res = std::make_shared<ov::op::v1::Reshape>(+ res, ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt), false);+ }+ } else if (out_ps.is_static() && in_ps.rank().is_static() && in_ps != out_ps) {+ // The input carries a (possibly spurious) dynamic axis but the destination cache row is fully+ // static (qwen3-next conv-state writeback: in [1,1,4096,1..3] -> cache [1,1,1,12288]). Reshape+ // to the static cache layout directly: at runtime the dynamic axis takes the value that makes+ // the element counts match, so a plain static target is valid. Guard on the static-dim product+ // dividing the output (a zero-element or incompatible copy keeps its own shape).+ int64_t in_static = 1;+ bool has_dyn = false;+ for (int64_t i = 0; i < in_ps.rank().get_length(); ++i) {+ if (in_ps[i].is_static()) {+ in_static *= in_ps[i].get_length();+ } else {+ has_dyn = true;+ }+ }+ const auto out_shape = out_ps.to_shape();+ int64_t out_elems = 1;+ for (auto d : out_shape)+ out_elems *= static_cast<int64_t>(d);+ // out_elems != 0: an empty destination must not be reshaped (0 % anything == 0).+ if (has_dyn && in_static != 0 && out_elems != 0 && out_elems % in_static == 0) {+ std::vector<int64_t> tgt(out_shape.begin(), out_shape.end());+ res = std::make_shared<ov::op::v1::Reshape>(+ res, ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt), false);+ }+ }return rename_outputs_with_suffix({res}, context.get_name());}diff --git a/src/frontends/gguf/src/op/cumsum.cpp b/src/frontends/gguf/src/op/cumsum.cppnew file mode 100644index 00000000000..34ed59a23e8--- /dev/null+++ b/src/frontends/gguf/src/op/cumsum.cpp@@ -0,0 +1,35 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <memory>++#include "openvino/op/constant.hpp"+#include "openvino/op/cum_sum.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_CUMSUM computes a prefix sum along ggml dim 0 (the innermost/fastest dimension).+// The frontend works in OV layout (ggml [ne0, ne1, ne2, ne3] -> OV [ne3, ne2, ne1, ne0]), so+// ggml dim 0 is the last OV axis (-1).+OutputVector translate_cumsum(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto x = context.get_input(0);+ auto axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1LL});+ auto res = std::make_shared<ov::op::v0::CumSum>(x, axis);++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/diag.cpp b/src/frontends/gguf/src/op/diag.cppnew file mode 100644index 00000000000..5df9bdaff8f--- /dev/null+++ b/src/frontends/gguf/src/op/diag.cpp@@ -0,0 +1,56 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cstdint>+#include <memory>+#include <vector>++#include "openvino/op/constant.hpp"+#include "openvino/op/multiply.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_DIAG turns a vector into a diagonal matrix: a ggml [ne0, 1, ne2, ne3] input becomes+// [ne0, ne0, ne2, ne3] with output[..., i, j] = input[..., 0, j] when i == j, else 0.+// In OV layout (ggml [ne0, ne1, ne2, ne3] -> OV [ne3, ne2, ne1, ne0]) the input is+// [ne3, ne2, 1, ne0] and the output is [ne3, ne2, ne0, ne0]; the new row axis is OV axis 2.+//+// We multiply the input by a constant [1, 1, n, n] identity matrix: broadcasting spreads the input+// over the new row axis and the identity zeroes off-diagonal entries. This avoids an Equal/Select+// over a folded boolean constant, which the CPU Snippets body-hasher mishandles.+OutputVector translate_diag(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto x = context.get_input(0); // OV shape: [ne3, ne2, 1, ne0]++ auto out_shape = context.get_output_shape().to_shape();+ size_t n = out_shape[3]; // ne0++ // Explicit [1, 1, n, n] identity matrix (1.0 on the diagonal, 0.0 elsewhere).+ std::vector<float> identity(n * n, 0.0f);+ for (size_t i = 0; i < n; ++i) {+ identity[i * n + i] = 1.0f;+ }+ // Build the mask in the node's own type, or an f16 input gets promoted to f32 by the Multiply.+ auto eye = ov::op::v0::Constant::create(context.get_attribute<ov::element::Type>("output_type"),+ ov::Shape{1, 1, n, n},+ identity);++ // Multiply broadcasts the [ne3,ne2,1,ne0] input over the row axis, zeroing off-diagonal entries.+ auto res = std::make_shared<ov::op::v1::Multiply>(x, eye);++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/div.cpp b/src/frontends/gguf/src/op/div.cppnew file mode 100644index 00000000000..c0596c1c40b--- /dev/null+++ b/src/frontends/gguf/src/op/div.cpp@@ -0,0 +1,156 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cstdint>+#include <memory>+#include <vector>++#include "openvino/frontend/exception.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/divide.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/sigmoid.hpp"+#include "openvino/op/tile.hpp"+#include "openvino/op/util/precision_sensitive_attribute.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++namespace {++// Detect silu(x) / x, which simplifies to sigmoid(x). ggml emits this in qwen2moe's shared-expert+// gate; computing it as a literal divide is a 0/0 NaN at x == 0. Rather than probe ggml op_params+// for a SILU tag (which would pull ggml.h into the frontend), we match the numerator's graph shape:+// our silu translator emits Multiply(x, Sigmoid(x)), so numerator == silu(denominator) exactly when+// the Multiply's two inputs are the denominator and Sigmoid(denominator). A structural match here is+// semantically silu(x)/x regardless of how ggml labeled the source op.+bool is_silu_div_pattern(const ov::Output<ov::Node>& numerator, const ov::Output<ov::Node>& denominator) {+ auto mul = std::dynamic_pointer_cast<ov::op::v1::Multiply>(numerator.get_node_shared_ptr());+ if (!mul) {+ return false;+ }+ const auto denom_node = denominator.get_node_shared_ptr();+ const auto in0 = mul->input_value(0).get_node_shared_ptr();+ const auto in1 = mul->input_value(1).get_node_shared_ptr();++ auto sigmoid = std::dynamic_pointer_cast<ov::op::v0::Sigmoid>(in1);+ if (in0 == denom_node && sigmoid && sigmoid->input_value(0).get_node_shared_ptr() == denom_node) {+ return true;+ }+ sigmoid = std::dynamic_pointer_cast<ov::op::v0::Sigmoid>(in0);+ return in1 == denom_node && sigmoid && sigmoid->input_value(0).get_node_shared_ptr() == denom_node;+}++// ggml broadcasts by integer repetition (a [.,n] tensor over a [.,k*n] tensor). OV's NUMPY divide+// broadcast can't express that, so Tile the smaller input up to the target shape first.+ov::Output<ov::Node> repeat_input_to_match(const NodeContext& context,+ const ov::Output<ov::Node>& input,+ const ov::Output<ov::Node>& target,+ size_t input_index) {+ const auto input_shape = context.get_input_shape(input_index);+ const auto target_shape = context.get_input_shape(0);++ if (input_shape == target_shape) {+ return input;+ }++ if (input_shape.rank().is_static() && target_shape.rank().is_static()) {+ const auto rank = static_cast<size_t>(input_shape.rank().get_length());+ std::vector<int64_t> repeats(rank, 1);+ bool needs_repeat = false;++ for (size_t axis = 0; axis < rank; ++axis) {+ if (input_shape[axis].is_dynamic() || target_shape[axis].is_dynamic()) {+ // Only the token axis is dynamic, and ggml never tiles it: both operands carry the+ // same runtime count.+ repeats[axis] = 1;+ continue;+ }++ const int64_t input_dim = input_shape[axis].get_length();+ const int64_t target_dim = target_shape[axis].get_length();++ // An empty axis needs no repetition: repeating 0 elements any number of times still+ // yields 0. This is a real case, not a malformed graph -- an ubatch whose active token+ // count is 0 (the trailing chunk of a chunked prefill) reaches DIV as [.., 0, ..]+ // against a [.., 0, ..] target, where the divisibility test below would reject it.+ if (input_dim == 0 && target_dim == 0) {+ repeats[axis] = 1;+ continue;+ }++ FRONT_END_OP_CONVERSION_CHECK(input_dim > 0 && target_dim > 0 && target_dim % input_dim == 0,+ "DIV input shape ", input_shape, " cannot repeat to match ", target_shape);++ repeats[axis] = target_dim / input_dim;+ needs_repeat = needs_repeat || repeats[axis] != 1;+ }++ if (!needs_repeat) {+ return input;+ }++ auto repeats_node = ov::op::v0::Constant::create(ov::element::i64, {repeats.size()}, repeats);+ return std::make_shared<ov::op::v0::Tile>(input, repeats_node);+ }++ auto input_shape_node = std::make_shared<ov::op::v3::ShapeOf>(input, ov::element::i64);+ auto target_shape_node = std::make_shared<ov::op::v3::ShapeOf>(target, ov::element::i64);+ auto repeats_node = std::make_shared<ov::op::v1::Divide>(target_shape_node, input_shape_node);+ return std::make_shared<ov::op::v0::Tile>(input, repeats_node);+}++} // namespace++OutputVector translate_div(const NodeContext& context) {+ num_inputs_check(context, 2, 2);++ auto input_0 = context.get_input(0);+ auto input_1 = context.get_input(1);++ const auto output_type = context.get_attribute<ov::element::Type>("output_type");++ if (is_silu_div_pattern(input_0, input_1)) {+ ov::Output<ov::Node> res = std::make_shared<ov::op::v0::Sigmoid>(input_1);+ if (res.get_element_type() != output_type) {+ res = std::make_shared<ov::op::v0::Convert>(res, output_type);+ }+ return rename_outputs_with_suffix({res}, context.get_name());+ }++ input_1 = repeat_input_to_match(context, input_1, input_0, 1);++ const bool use_f32_compute = input_0.get_element_type() != ov::element::f32 ||+ input_1.get_element_type() != ov::element::f32 || output_type != ov::element::f32;++ if (use_f32_compute) {+ input_0 = std::make_shared<ov::op::v0::Convert>(input_0, ov::element::f32);+ input_1 = std::make_shared<ov::op::v0::Convert>(input_1, ov::element::f32);+ }++ ov::Output<ov::Node> res = std::make_shared<ov::op::v1::Divide>(input_0, input_1);+ // Keep the divide in FP32: the GPU plugin would otherwise compress it back to FP16 and overflow+ // on small gate values (e.g. silu(x) / x in qwen2moe).+ ov::mark_as_precision_sensitive(res.get_node_shared_ptr()->input(0));+ ov::mark_as_precision_sensitive(res.get_node_shared_ptr()->input(1));+ if (res.get_element_type() != output_type) {+ auto output_convert = std::make_shared<ov::op::v0::Convert>(res, output_type);+ ov::mark_as_precision_sensitive(output_convert->input(0));+ res = output_convert;+ }+ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/fill.cpp b/src/frontends/gguf/src/op/fill.cppnew file mode 100644index 00000000000..f5b64630f3c--- /dev/null+++ b/src/frontends/gguf/src/op/fill.cpp@@ -0,0 +1,45 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cstdint>+#include <memory>+#include <vector>++#include "openvino/op/broadcast.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/shape_of.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_FILL sets every element of a tensor to a constant. The scalar is provided by the decoder+// as the "fill_value" attribute (ggml stores it as a float in op_params[0]). The output has the same+// shape as the (single) input; broadcasting to ShapeOf(input) keeps the input live and works for+// dynamic shapes.+OutputVector translate_fill(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto x = context.get_input(0);+ float fill_value = context.get_attribute<float>("fill_value");++ // ggml FILL keeps the tensor's own type (f32 or f16), so do not hardcode f32 here.+ auto val = ov::op::v0::Constant::create(context.get_attribute<ov::element::Type>("output_type"),+ ov::Shape{},+ {fill_value});+ auto target_shape = std::make_shared<ov::op::v3::ShapeOf>(x, ov::element::i64);+ auto res = std::make_shared<ov::op::v3::Broadcast>(val, target_shape);++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/flash_attn_ext.cpp b/src/frontends/gguf/src/op/flash_attn_ext.cppindex 2cd6d8a60c4..18e32fb039b 100644--- a/src/frontends/gguf/src/op/flash_attn_ext.cpp+++ b/src/frontends/gguf/src/op/flash_attn_ext.cpp@@ -34,8 +34,9 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {float scale = context.get_attribute<float>("scale");- auto q = std::make_shared<ov::op::v0::Convert>(q_f32, ov::element::f16);- auto scale_node = std::make_shared<ov::op::v0::Constant>(ov::element::f16, ov::Shape{}, std::vector<float>{scale});+ const auto sdpa_type = ov::element::f16;+ auto q = std::make_shared<ov::op::v0::Convert>(q_f32, sdpa_type);+ auto scale_node = std::make_shared<ov::op::v0::Constant>(sdpa_type, ov::Shape{}, std::vector<float>{scale});ov::Output<ov::Node> mask_sliced, res;const std::string mask_name = context.get_attribute<bool>("is_swa", false) ? "KQ_mask_swa_sliced" : "KQ_mask_sliced";@@ -49,8 +50,8 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {mask_sliced = std::make_shared<ov::op::v8::Slice>(mask, zero, token_len, one, two);}- if (mask_sliced.get_element_type() != ov::element::f16) {- mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, ov::element::f16);+ if (mask_sliced.get_element_type() != sdpa_type) {+ mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, sdpa_type);}auto tile_kv = [&](int64_t num_heads, int64_t num_heads_kv, int64_t head_size, ov::Output<Node> kv) {diff --git a/src/frontends/gguf/src/op/gated_delta_net.cpp b/src/frontends/gguf/src/op/gated_delta_net.cppindex 1bc89390a88..bb5dc207137 100644--- a/src/frontends/gguf/src/op/gated_delta_net.cpp+++ b/src/frontends/gguf/src/op/gated_delta_net.cpp@@ -10,13 +10,16 @@#include "openvino/op/concat.hpp"#include "openvino/op/constant.hpp"#include "openvino/op/exp.hpp"+#include "openvino/op/gated_delta_net.hpp"#include "openvino/op/gather.hpp"#include "openvino/op/loop.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/reshape.hpp"+#include "openvino/op/shape_of.hpp"#include "openvino/op/squeeze.hpp"#include "openvino/op/subtract.hpp"+#include "openvino/op/tile.hpp"#include "openvino/op/transpose.hpp"#include "openvino/op/unsqueeze.hpp"#include <vector>@@ -30,14 +33,88 @@ namespace frontend {namespace gguf {namespace op {-// GGML_OP_GATED_DELTA_NET (qwen3next linear-attention block). Implemented as a recurrent OV Loop-// scan over the sequence, matching ggml's per-token gated delta update. This is the portable-// reference path; the OV core also ships an ov::op::internal::GatedDeltaNet fused op, but it is-// left for a hardware-side optimization once validated against a model (the frontend stays-// conversion-only and device-agnostic).+static OutputVector translate_gated_delta_net_ref(const NodeContext& context);++// GGML_OP_GATED_DELTA_NET (qwen3next linear-attention block). Emits the internal (non-opset) op+// ov::op::internal::GatedDeltaNet for the device's fused kernel; a model using it is not+// IR-serializable (see docs/internal_ops.md). The fused op only supports scalar gating, so the+// per-key-dimension gating case (kda) uses the serializable Loop reference path below.OutputVector translate_gated_delta_net(const NodeContext& context) {num_inputs_check(context, 6, 6);+ auto v_shape = context.get_input_shape(2).to_shape(); // [B, T, H_v, S_v]+ auto q_shape = context.get_input_shape(0).to_shape(); // [B, T, H_k, S_k]+ auto g_shape = context.get_input_shape(3).to_shape(); // [B, T, H_v, 1 or S_v]++ const int64_t H_v = v_shape[2];+ const int64_t S_v = v_shape[3];+ const int64_t H_k = q_shape[2];+ const bool kda = (g_shape[3] == (size_t)S_v);++ // ggml reserves K * S_v * n_seqs state rows for K per-token snapshots (K = 1 + n_rs_seq, > 1 only+ // for speculative-decode rollback), while both paths here pack exactly one S_v-row block. Reject+ // K > 1 rather than let the snapshot views read the wrong block.+ const int64_t snapshot_slots = context.get_attribute<int64_t>("gdn_state_slots", 1);+ FRONT_END_OP_CONVERSION_CHECK(snapshot_slots == 1,+ "GATED_DELTA_NET supports a single recurrent-state snapshot, got K = ",+ snapshot_slots);++ // kda needs the Loop path; "force_ref" lets tests exercise the Loop path's multi-head packing+ // against the ggml-CPU oracle for the scalar-gate case too.+ if (kda || context.get_attribute<bool>("force_ref", false)) {+ return translate_gated_delta_net_ref(context);+ }++ auto q = context.get_input(0);+ auto k = context.get_input(1);+ auto v = context.get_input(2);+ auto g = context.get_input(3);+ auto beta = context.get_input(4);+ auto state = context.get_input(5);++ // ggml maps GQA heads in tiled order, while the OV op maps repeated heads in grouped order:+ // tile Q/K along the head axis so their head count matches V.+ if (H_v != H_k) {+ const int64_t repeat = H_v / H_k;+ auto repeats = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, 1, repeat, 1});+ q = std::make_shared<ov::op::v0::Tile>(q, repeats);+ k = std::make_shared<ov::op::v0::Tile>(k, repeats);+ }++ // ggml state layout (OV notation) is [B, H_v, value_dim, key_dim]; the op expects+ // [B, H_v, key_dim, value_dim].+ auto state_perm = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{0, 1, 3, 2});+ state = std::make_shared<ov::op::v1::Transpose>(state, state_perm);++ // Gate/beta carry a trailing singleton in the scalar-gate case; the op takes them rank-3.+ auto sq_axis_3 = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});+ g = std::make_shared<ov::op::v0::Squeeze>(g, sq_axis_3);+ beta = std::make_shared<ov::op::v0::Squeeze>(beta, sq_axis_3);++ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q, k, v, state, g, beta);+ auto attn_4d = gdn->output(0);+ auto state_4d = gdn->output(1); // [B, H_v, key_dim, value_dim]++ // Transpose state back to ggml's [B, H_v, value_dim, key_dim] and pack [attn | state] flat,+ // matching the reference path.+ auto state_transposed = std::make_shared<ov::op::v1::Transpose>(state_4d, state_perm);+ auto flat_shape_1d = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ auto attn = std::make_shared<ov::op::v1::Reshape>(attn_4d, flat_shape_1d, false);+ auto new_state = std::make_shared<ov::op::v1::Reshape>(state_transposed, flat_shape_1d, false);+ auto packed = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{attn, new_state}, 0);+ // [1, 1, T*B + S_v*B, S_v*H_v] with the row axis dynamic via -1.+ auto out_shape =+ ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, 1, -1, S_v * H_v});+ auto res = std::make_shared<ov::op::v1::Reshape>(packed, out_shape, false);++ return rename_outputs_with_suffix({res}, context.get_name());+}++// Serializable reference path: a recurrent OV Loop scan over the sequence built from core ops,+// matching ggml's per-token gated delta update. Used for the kda case and as a portable fallback.+static OutputVector translate_gated_delta_net_ref(const NodeContext& context) {+ num_inputs_check(context, 6, 6);+auto q = context.get_input(0);auto k = context.get_input(1);auto v = context.get_input(2);@@ -59,6 +136,11 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {const int64_t rq1 = H_v / H_k; // GQA head repeat factorconst float scale = 1.0f / std::sqrt((float)S_v);+ // T is dynamic at runtime: T-dependent reshapes use -1 and the Loop trip count is read at+ // runtime, so the convert-time T is only used for the static dims (B/H_v/S_v/H_k).+ (void) T;++ auto axis_0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});auto axis_1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});auto axis_2 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});@@ -82,14 +164,15 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {auto perm_5d = ov::op::v0::Constant::create(ov::element::i64, {5}, std::vector<int64_t>{0, 2, 1, 3, 4});auto q_transposed = std::make_shared<ov::op::v1::Transpose>(q_bcast, perm_5d);auto k_transposed = std::make_shared<ov::op::v1::Transpose>(k_bcast, perm_5d);- auto new_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{B, H_v, T, S_v});+ // [B, H_v, T, S_v] with T dynamic (-1).+ auto new_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{B, H_v, -1, S_v});q_bh = std::make_shared<ov::op::v1::Reshape>(q_transposed, new_shape, false);k_bh = std::make_shared<ov::op::v1::Reshape>(k_transposed, new_shape, false);}- // Merge batch and head: [B*H_v, T, last]+ // Merge batch and head: [B*H_v, T, last] with T dynamic (-1).auto merge_bh = [&](ov::Output<ov::Node> x, int64_t last_dim) {- auto shape = ov::op::v0::Constant::create(ov::element::i64, {3}, std::vector<int64_t>{B * H_v, T, last_dim});+ auto shape = ov::op::v0::Constant::create(ov::element::i64, {3}, std::vector<int64_t>{B * H_v, -1, last_dim});return std::make_shared<ov::op::v1::Reshape>(x, shape, false);};auto q_m = merge_bh(q_bh, S_v);@@ -151,7 +234,10 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {ov::OutputVector{body_cond_out, state_updated, attn_out_unsq},ov::ParameterVector{body_iter, body_state, body_q, body_k, body_v, body_g, body_beta});- auto trip_count = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{T});+ // Trip count = runtime token count T, read from q_m's dynamic token axis (axis 1) rather than the+ // convert-time constant, so the same compiled Loop runs any token count.+ auto qm_shape = std::make_shared<ov::op::v3::ShapeOf>(q_m, ov::element::i64);+ auto trip_count = std::make_shared<ov::op::v8::Gather>(qm_shape, axis_1, axis_0);auto exec_cond = ov::op::v0::Constant::create(ov::element::boolean, ov::Shape{1}, std::vector<bool>{true});auto loop = std::make_shared<ov::op::v5::Loop>(trip_count, exec_cond);@@ -167,8 +253,9 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {auto final_state_out = loop->get_iter_value(state_updated, -1);auto attn_concat_out = loop->get_concatenated_slices(attn_out_unsq, 0, 1, 1, -1, 1);- // Pack [attn | state] into ggml's output layout: OV [1, 1, T*B + S_v*B, S_v*H_v].- auto attn_4d_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{B, H_v, T, S_v});+ // Pack [attn | state] into ggml's [1, 1, T*B + S_v*B, S_v*H_v] output; the row axis is dynamic+ // (-1) so the packed height follows the runtime token count.+ auto attn_4d_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{B, H_v, -1, S_v});auto attn_4d = std::make_shared<ov::op::v1::Reshape>(attn_concat_out, attn_4d_shape, false);auto attn_perm = std::make_shared<ov::op::v1::Transpose>(attn_4d, perm_0213);auto flat_shape_1d = ov::op::v0::Constant::create(ov::element::i64, {1}, std::vector<int64_t>{-1});@@ -179,8 +266,9 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {auto state_1d = std::make_shared<ov::op::v1::Reshape>(state_4d, flat_shape_1d, false);auto packed = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{attn_1d, state_1d}, 0);+ // [1, 1, -1, S_v*H_v]: the row axis (T*B + S_v*B) is dynamic via -1.auto out_shape =- ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, 1, T * B + S_v * B, S_v * H_v});+ ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, 1, -1, S_v * H_v});auto res = std::make_shared<ov::op::v1::Reshape>(packed, out_shape, false);return rename_outputs_with_suffix({res}, context.get_name());diff --git a/src/frontends/gguf/src/op/mul_mat_id.cpp b/src/frontends/gguf/src/op/mul_mat_id.cppindex e5584b10af0..e5592be7830 100644--- a/src/frontends/gguf/src/op/mul_mat_id.cpp+++ b/src/frontends/gguf/src/op/mul_mat_id.cpp@@ -41,6 +41,56 @@ ov::Output<ov::Node> slice_axis(const ov::Output<ov::Node>& input, int64_t axis,const_i64({axis}));}+// Lay the 3D activations out as [n_token, n_used, k]: one row per (token, selected expert) pair,+// which is exactly the batch layout of the gathered expert weights, so the MatMul below needs no+// implicit batch broadcasting.+//+// ggml hands us the activations of a MUL_MAT_ID in one of three layouts, all three of which occur in+// a single MoE model:+// [n_token, 1, k] the usual gate/up input -- a singleton expert axis to expand;+// [n_token, n_used, k] the ffn_down input, whose expert axis is already expanded;+// [1, n_token, k] the plain 2D form, with no expert axis at all, so the token count sits one+// axis over. It appears in the last layer, where the activations are first+// gathered down to the ubatch's output rows.+// Only the second may not be reshaped -- it already holds n_token * n_used * k elements, so folding it+// to one row per token would drop data. For the other two the Reshape below is what puts the token+// count in axis 0, and it is a no-op for the first, so the two need no telling apart. The second is+// recognized by its expert axis matching the ids' n_used, which holds on a static (NPU) graph too,+// where no axis is dynamic to give the layout away.+//+// Driving that Reshape from the *ids'* token count is also what makes an empty ubatch work: the+// output-row count is 0 for every non-final chunk of a chunked prefill (only the final chunk produces+// logits), and 0 tokens must stay 0 rows. Broadcasting an empty axis up to n_used is rejected by+// OpenVINO -- and meaningless, as there is nothing to replicate -- whereas here the empty count simply+// flows into the token axis and yields an empty result.+ov::Output<ov::Node> activations_per_expert(const ov::Output<ov::Node>& activations,+ const std::shared_ptr<ov::op::v3::ShapeOf>& activations_shape,+ const ov::Output<ov::Node>& ids,+ const std::shared_ptr<ov::op::v3::ShapeOf>& ids_shape) {+ const auto& acts_ps = activations.get_partial_shape(); // [n_token, 1 | n_used, k], or [1, n_token, k]+ const auto& ids_ps = ids.get_partial_shape(); // [n_token, n_used]+ // The expert-axis match alone is ambiguous: the plain 2D layout [1, n_token, k] also satisfies it+ // when n_token == n_used (the warmup graph). The token axis (1 vs n_token) disambiguates.+ const bool already_per_expert = acts_ps.rank().is_static() && acts_ps.rank().get_length() == 3 &&+ ids_ps.rank().is_static() && ids_ps.rank().get_length() == 2 &&+ acts_ps[1].is_static() && ids_ps[1].is_static() &&+ ids_ps[1].get_length() > 1 && acts_ps[1] == ids_ps[1] &&+ (acts_ps[0].is_dynamic() || ids_ps[0].is_dynamic() || acts_ps[0] == ids_ps[0]);++ ov::Output<ov::Node> rows = activations;+ if (!already_per_expert) {+ rows = std::make_shared<ov::op::v1::Reshape>(+ activations,+ std::make_shared<ov::op::v0::Concat>(ov::OutputVector{get_dimensions(ids_shape, {0}), const_i64({1}),+ get_dimensions(activations_shape, {2})},+ 0),+ false);+ }+ auto target = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{get_dimensions(ids_shape, {0, 1}), get_dimensions(activations_shape, {2})}, 0);+ return std::make_shared<ov::op::v3::Broadcast>(rows, target, ov::op::BroadcastType::BIDIRECTIONAL);+}+// Packed-MXFP4 MoE path: expert weights arrive as raw u8 blocks of shape// [1, n_expert, m, k_blocks, 17] (1 e8m0 scale byte + 16 nibble-packed f4e2m1 quants per 32-block).// The dequant (nibble unpack + LUT + scale) is done on-graph, per selected expert.@@ -113,15 +163,7 @@ ov::Output<ov::Node> translate_mul_mat_id_mxfp4_packed(const NodeContext& contexselected_weights = std::make_shared<ov::op::v1::Reshape>(selected_weights, selected_weights_target_dims, false);auto activations_shape = std::make_shared<ov::op::v3::ShapeOf>(activations, ov::element::i64);- ov::Output<ov::Node> acts_target_dims = std::make_shared<ov::op::v0::Concat>(- ov::OutputVector{- get_dimensions(activations_shape, {0}),- get_dimensions(ids_shape, {1}),- get_dimensions(activations_shape, {2}),- },- 0);- ov::Output<ov::Node> acts_broadcasted =- std::make_shared<ov::op::v3::Broadcast>(activations, acts_target_dims, ov::op::BroadcastType::BIDIRECTIONAL);+ auto acts_broadcasted = activations_per_expert(activations, activations_shape, ids, ids_shape);auto activations_expanded = std::make_shared<ov::op::v0::Unsqueeze>(acts_broadcasted, const_i64({2}));ov::Output<ov::Node> result =@@ -190,15 +232,7 @@ OutputVector translate_mul_mat_id(const NodeContext& context) {auto activations_shape = std::make_shared<ov::op::v3::ShapeOf>(activations, ov::element::i64);auto ids_shape = std::make_shared<ov::op::v3::ShapeOf>(ids, ov::element::i64);- ov::Output<ov::Node> acts_target_dims = std::make_shared<ov::op::v0::Concat>(- ov::OutputVector{- get_dimensions(activations_shape, {0}),- get_dimensions(ids_shape, {1}),- get_dimensions(activations_shape, {2}),- },- 0);- ov::Output<ov::Node> acts_broadcasted =- std::make_shared<ov::op::v3::Broadcast>(activations, acts_target_dims, ov::op::BroadcastType::BIDIRECTIONAL);+ auto acts_broadcasted = activations_per_expert(activations, activations_shape, ids, ids_shape);auto unsqueeze_axes = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});auto activations_expanded = std::make_shared<ov::op::v0::Unsqueeze>(acts_broadcasted, unsqueeze_axes);diff --git a/src/frontends/gguf/src/op/repeat.cpp b/src/frontends/gguf/src/op/repeat.cppindex a395d2b8c9f..96c7c74ddbd 100644--- a/src/frontends/gguf/src/op/repeat.cpp+++ b/src/frontends/gguf/src/op/repeat.cpp@@ -28,38 +28,59 @@ OutputVector translate_repeat(const NodeContext& context) {const auto input_shape = context.get_input_shape(0);const auto output_shape = context.get_output_shape();+ // Preferred path: build static integer repeat factors and let OV shape-inference propagate any+ // dynamic axis. REPEAT never tiles the variable token/sequence axis, so a dynamic dim (present on+ // both input and output at the same position) always has repeat factor 1; only static dims are+ // tiled. This keeps the Tile's repeat vector constant even on the dynamic-token path (the fused+ // qwen3-next conv/delta REPEATs have a dynamic token axis and only one input, so a ShapeOf-based+ // fallback that reads a non-existent src[1] would produce garbage).if (input_shape.rank().is_static() && output_shape.rank().is_static() &&input_shape.rank() == output_shape.rank()) {const auto rank = static_cast<size_t>(input_shape.rank().get_length());std::vector<int64_t> repeats(rank, 1);- bool all_static = true;+ bool resolved = true;for (size_t axis = 0; axis < rank; ++axis) {- if (!input_shape[axis].is_static() || !output_shape[axis].is_static()) {- all_static = false;+ const bool in_dyn = !input_shape[axis].is_static();+ const bool out_dyn = !output_shape[axis].is_static();+ if (out_dyn && !in_dyn && input_shape[axis].get_length() == 1) {+ // A genuine broadcast to a runtime count: the factor is only known at inference time,+ // so a constant 1 would emit a no-op Tile. Use the ShapeOf path instead.+ resolved = false;break;}+ if (in_dyn || out_dyn) {+ // Any other dynamic axis is the token axis, which REPEAT passes through untiled.+ repeats[axis] = 1;+ continue;+ }const int64_t input_dim = input_shape[axis].get_length();const int64_t output_dim = output_shape[axis].get_length();- FRONT_END_OP_CONVERSION_CHECK(input_dim > 0 && output_dim > 0 && output_dim % input_dim == 0,- "REPEAT input shape ", input_shape, " cannot tile to match ", output_shape);+ if (input_dim <= 0 || output_dim <= 0 || output_dim % input_dim != 0) {+ resolved = false;+ break;+ }repeats[axis] = output_dim / input_dim;}- if (all_static) {+ if (resolved) {auto repeats_node = ov::op::v0::Constant::create(ov::element::i64, {repeats.size()}, repeats);ov::Output<ov::Node> res = std::make_shared<ov::op::v0::Tile>(input, repeats_node);return rename_outputs_with_suffix({res}, context.get_name());}}- // Dynamic fallback: tile by the ratio of output to input shape.+ // Dynamic-rank fallback: tile by the ratio of the (statically known) output shape to the runtime+ // input shape. Only reached when the output shape is fully static but ranks/dims did not resolve+ // above; a two-input REPEAT could instead take its target from src[1].auto input_shape_node = std::make_shared<ov::op::v3::ShapeOf>(input, ov::element::i64);std::shared_ptr<ov::Node> target_shape_node;- if (output_shape.rank().is_static() && output_shape.is_static()) {+ if (output_shape.is_static()) {target_shape_node =ov::op::v0::Constant::create(ov::element::i64, {output_shape.to_shape().size()}, output_shape.to_shape());} else {+ FRONT_END_OP_CONVERSION_CHECK(context.get_input_size() > 1,+ "REPEAT with dynamic output shape requires a second (shape) input");target_shape_node = std::make_shared<ov::op::v3::ShapeOf>(context.get_input(1), ov::element::i64);}auto repeats_node = std::make_shared<ov::op::v1::Divide>(target_shape_node, input_shape_node);diff --git a/src/frontends/gguf/src/op/reshape.cpp b/src/frontends/gguf/src/op/reshape.cppindex 5af5beb59b9..b5039fa80b9 100644--- a/src/frontends/gguf/src/op/reshape.cpp+++ b/src/frontends/gguf/src/op/reshape.cpp@@ -30,9 +30,16 @@ OutputVector translate_reshape(const NodeContext & context) {int op_case = context.get_attribute<int>("op_case", 0);FRONT_END_CHECK_IMPLEMENTED(- op_case == 1 || op_case == 2 || op_case == 3 || op_case == 4 || op_case == 5 || op_case == 6,+ op_case == 1 || op_case == 2 || op_case == 3 || op_case == 4 || op_case == 5 || op_case == 6 ||+ op_case == 7 || op_case == 8,"Unsupported RESHAPE case");+ if (op_case == 8) {+ // Identity reshape (ggml src ne == node ne): a no-op. Pass the input through so any dynamic+ // token axis it carries is preserved (a static reshape would bake in the compile-time count).+ return {context.get_input(0)};+ }+auto output_shape = context.get_output_shape().to_shape();std::shared_ptr<ov::Node> new_shape_node;if (op_case == 1) {@@ -58,7 +65,22 @@ OutputVector translate_reshape(const NodeContext & context) {new_shape_node = ov::op::v0::Constant::create(ov::element::i64, {4}, shape_vec);} else if (op_case == 6) {- new_shape_node = ov::op::v0::Constant::create(ov::element::i64, {4}, output_shape);+ // The output layout rearranges dims relative to the input (e.g. qwen3-next q/k_conv_predelta:+ // [128,2,8,T] -> [128,16,T,1]). The decoder supplies the OV-order target with -1 on the dynamic+ // token axis so the stateful model reuses across token counts; fall back to the static output+ // shape when no dynamic axis was inferred.+ auto tgt = context.get_attribute<std::vector<int64_t>>("reshape_target", {});+ if (tgt.empty()) {+ tgt.assign(output_shape.begin(), output_shape.end());+ }+ new_shape_node = ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt);++ } else if (op_case == 7) {+ // General fully-static reshape (no dynamic token axis): reshape straight to the static+ // output shape. Used by qwen3-next's recurrent-state predelta reshape [262144]->[16,128,128].+ new_shape_node = ov::op::v0::Constant::create(+ ov::element::i64, {output_shape.size()},+ std::vector<int64_t>(output_shape.begin(), output_shape.end()));}auto res = std::make_shared<ov::op::v1::Reshape>(context.get_input(0), new_shape_node, false);return rename_outputs_with_suffix({res}, context.get_name());diff --git a/src/frontends/gguf/src/op/rope.cpp b/src/frontends/gguf/src/op/rope.cppindex c3e9f9ea1df..989e84ab012 100644--- a/src/frontends/gguf/src/op/rope.cpp+++ b/src/frontends/gguf/src/op/rope.cpp@@ -158,16 +158,35 @@ OutputVector translate_rope(const NodeContext& context) {res = (n_rot < head_dim) ? std::make_shared<ov::op::v0::Concat>(ov::OutputVector{rotated, pass_through}, -1): rotated;} else if (mode == TYPE_IMROPE) {- // Use output_shape, not data_node->get_shape() which throws on a dynamic dim.- int64_t n_dims = output_shape[3];+ // Partial rotary (ggml n_dims < head_dim): only the first n_rot dims of every head are+ // rotated, the tail is passed through unchanged -- e.g. qwen3.5 has head_dim 256 but+ // rope.dimension_count 64. cos/sin carry width n_rot/2, so the rotated block must be+ // exactly n_rot wide; using the full head here rotates the pass-through tail and corrupts+ // every full-attention layer. (Use output_shape, not data_node->get_shape() which throws+ // on a dynamic dim.)+ const int64_t head_dim = static_cast<int64_t>(output_shape[3]);+ const int64_t n_rot = rope_config.n_dims > 0 ? rope_config.n_dims : head_dim;++ Output<Node> rotary_in = data_node;+ Output<Node> pass_through;+ if (n_rot < head_dim) {+ auto neg_one = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ auto zero = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});+ auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});+ auto n_rot_c = ov::op::v0::Constant::create(ov::element::i64, {1}, {n_rot});+ auto head_c = ov::op::v0::Constant::create(ov::element::i64, {1}, {head_dim});+ rotary_in = std::make_shared<ov::op::v8::Slice>(data_node, zero, n_rot_c, one, neg_one);+ pass_through = std::make_shared<ov::op::v8::Slice>(data_node, n_rot_c, head_c, one, neg_one);+ }+auto cos_sin_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i64,ov::Shape{4},- std::vector<int64_t>{1, -1, 1, (n_dims >> 1)});+ std::vector<int64_t>{1, -1, 1, (n_rot >> 1)});auto cos_reshaped = std::make_shared<ov::op::v1::Reshape>(cos_theta_node, cos_sin_shape, true);auto sin_reshaped = std::make_shared<ov::op::v1::Reshape>(sin_theta_node, cos_sin_shape, true);auto split_axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {3});- auto split_a = std::make_shared<ov::op::v1::Split>(data_node, split_axis, 2);+ auto split_a = std::make_shared<ov::op::v1::Split>(rotary_in, split_axis, 2);auto x0 = split_a->output(0);auto x1 = split_a->output(1);auto mul_a = std::make_shared<ov::op::v1::Multiply>(x0, cos_reshaped);@@ -178,7 +197,9 @@ OutputVector translate_rope(const NodeContext& context) {auto mul_d = std::make_shared<ov::op::v1::Multiply>(x1, cos_reshaped);auto add = std::make_shared<ov::op::v1::Add>(mul_c, mul_d);- res = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{sub, add}, 3);+ Output<Node> rotated = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{sub, add}, 3);+ res = (n_rot < head_dim) ? std::make_shared<ov::op::v0::Concat>(ov::OutputVector{rotated, pass_through}, 3)+ : rotated;}// Fail cleanly on an unmapped mode rather than dereferencing a null res downstream.diff --git a/src/frontends/gguf/src/op/set.cpp b/src/frontends/gguf/src/op/set.cppnew file mode 100644index 00000000000..d38326f8fff--- /dev/null+++ b/src/frontends/gguf/src/op/set.cpp@@ -0,0 +1,72 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cstdint>+#include <memory>++#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/range.hpp"+#include "openvino/op/reduce_prod.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/scatter_update.hpp"+#include "openvino/op/shape_of.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_SET writes src[1] into a contiguous region of src[0] and returns the updated tensor.+// ggml stores the destination byte offset in op_params[3]; the decoder converts it to an element+// count and exposes it as the "set_offset_elems" attribute, so the frontend never touches raw+// strides. Both inputs arrive already resolved (translate_view materialized any views), so we flatten+// dst, scatter the flattened src into [offset, offset + numel(src)), and reshape back to dst's shape.+OutputVector translate_set(const NodeContext& context) {+ num_inputs_check(context, 2, 2);++ ov::Output<ov::Node> dst = context.get_input(0);+ ov::Output<ov::Node> src = context.get_input(1);++ // ScatterUpdate requires data and updates to share an element type, so cast both.+ const auto output_type = context.get_attribute<ov::element::Type>("output_type");+ src = std::make_shared<ov::op::v0::Convert>(src, output_type);+ if (dst.get_element_type() != output_type) {+ dst = std::make_shared<ov::op::v0::Convert>(dst, output_type);+ }++ const int64_t offset_elems = context.get_attribute<int64_t>("set_offset_elems");++ auto dst_flat = std::make_shared<ov::op::v1::Reshape>(+ dst, ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}), false);+ auto src_flat = std::make_shared<ov::op::v1::Reshape>(+ src, ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}), false);++ // Indices [offset, offset + numel(src)) into the flattened destination.+ auto src_shape = std::make_shared<ov::op::v3::ShapeOf>(src_flat, ov::element::i64);+ auto src_len = std::make_shared<ov::op::v1::ReduceProd>(+ src_shape, ov::op::v0::Constant::create(ov::element::i64, {1}, {0}), false);+ auto start = ov::op::v0::Constant::create(ov::element::i64, {}, {offset_elems});+ auto stop = std::make_shared<ov::op::v1::Add>(start, src_len);+ auto step = ov::op::v0::Constant::create(ov::element::i64, {}, {1});+ auto indices = std::make_shared<ov::op::v4::Range>(start, stop, step, ov::element::i64);+ auto axis = ov::op::v0::Constant::create(ov::element::i64, {}, {0});++ auto updated_flat = std::make_shared<ov::op::v3::ScatterUpdate>(dst_flat, indices, src_flat, axis);++ auto dst_shape = std::make_shared<ov::op::v3::ShapeOf>(dst, ov::element::i64);+ auto res = std::make_shared<ov::op::v1::Reshape>(updated_flat, dst_shape, false);++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/sqr.cpp b/src/frontends/gguf/src/op/sqr.cppnew file mode 100644index 00000000000..1c886348335--- /dev/null+++ b/src/frontends/gguf/src/op/sqr.cpp@@ -0,0 +1,41 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <memory>++#include "openvino/op/multiply.hpp"+#include "openvino/op/sqrt.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_SQR: element-wise square (x * x).+OutputVector translate_sqr(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto input = context.get_input(0);+ auto res = std::make_shared<ov::op::v1::Multiply>(input, input);++ return rename_outputs_with_suffix({res}, context.get_name());+}++// GGML_OP_SQRT: element-wise square root.+OutputVector translate_sqrt(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto res = std::make_shared<ov::op::v0::Sqrt>(context.get_input(0));++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/ssm_conv.cpp b/src/frontends/gguf/src/op/ssm_conv.cppindex c39b1706fa1..f559f50769f 100644--- a/src/frontends/gguf/src/op/ssm_conv.cpp+++ b/src/frontends/gguf/src/op/ssm_conv.cpp@@ -30,12 +30,13 @@ OutputVector translate_ssm_conv(const NodeContext& context) {int64_t n_s = sx_shape[1];int64_t d_inner = sx_shape[2];- int64_t ncs = sx_shape[3];int64_t d_conv = c_shape[3];- int64_t n_t = ncs - d_conv + 1;- // [1, n_s, d_inner, ncs] -> [n_s, d_inner, ncs] for 1D GroupConvolution.- auto sx_new_shape = ov::op::v0::Constant::create(ov::element::i64, {3}, std::vector<int64_t>{n_s, d_inner, ncs});+ // The conv-window length ncs (= n_t + d_conv - 1) and the token count n_t are token-dependent: the+ // stateful model is compiled once and reused across token counts, so keep those axes dynamic (-1)+ // rather than baking the convert-time value. n_s/d_inner/d_conv are structurally static.+ // [1, n_s, d_inner, ncs] -> [n_s, d_inner, ncs] (ncs dynamic) for 1D GroupConvolution.+ auto sx_new_shape = ov::op::v0::Constant::create(ov::element::i64, {3}, std::vector<int64_t>{n_s, d_inner, -1});auto sx_reshaped = std::make_shared<ov::op::v1::Reshape>(sx, sx_new_shape, false);// Filter [groups, out/groups, in/groups, kernel] = [d_inner, 1, 1, d_conv].@@ -49,7 +50,8 @@ OutputVector translate_ssm_conv(const NodeContext& context) {auto perm = ov::op::v0::Constant::create(ov::element::i64, {3}, std::vector<int64_t>{0, 2, 1});auto transposed = std::make_shared<ov::op::v1::Transpose>(conv, perm);- auto out_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, n_s, n_t, d_inner});+ // [1, n_s, n_t, d_inner] with the token axis n_t dynamic (-1).+ auto out_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, n_s, -1, d_inner});auto res = std::make_shared<ov::op::v1::Reshape>(transposed, out_shape, false);return rename_outputs_with_suffix({res}, context.get_name());diff --git a/src/frontends/gguf/src/op/tri.cpp b/src/frontends/gguf/src/op/tri.cppnew file mode 100644index 00000000000..d4e14421939--- /dev/null+++ b/src/frontends/gguf/src/op/tri.cpp@@ -0,0 +1,74 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cstdint>+#include <memory>+#include <vector>++#include "openvino/frontend/exception.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/multiply.hpp"++#include "node_context.hpp"+#include "op_table.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace gguf {+namespace op {++// GGML_OP_TRI zeroes out elements outside a triangular region of a square matrix. The region is+// selected by the decoder-provided "tri_type" attribute (ggml_tri_type, mapped to a plain int):+// 0 = UPPER_DIAG : keep where col >= row+// 1 = UPPER : keep where col > row+// 2 = LOWER_DIAG : keep where col <= row+// 3 = LOWER : keep where col < row+//+// In OV layout (ggml [ne0, ne1, ne2, ne3] -> OV [ne3, ne2, ne1, ne0]): ggml dim 0 (ne0, cols) is+// OV axis 3 and ggml dim 1 (ne1, rows) is OV axis 2. The matrix is square so ne0 == ne1.+//+// tri_type and n are both known at conversion time, so we build the exact [1,1,n,n] f32 keep-mask+// (1.0 to keep, 0.0 to zero) as a constant and multiply. This avoids a Range/Compare/Select chain+// over a folded boolean constant.+OutputVector translate_tri(const NodeContext& context) {+ num_inputs_check(context, 1, 1);++ auto x = context.get_input(0); // OV shape: [ne3, ne2, ne1, ne0]++ auto tri_type = context.get_attribute<int>("tri_type");++ auto shape = context.get_input_shape(0).to_shape();+ size_t n = shape[3]; // ne0 == ne1+ FRONT_END_GENERAL_CHECK(shape[2] == n, "translate_tri: expected a square matrix, got ", shape);++ std::vector<float> mask(n * n, 0.0f);+ for (size_t row = 0; row < n; ++row) {+ for (size_t col = 0; col < n; ++col) {+ bool keep = false;+ switch (tri_type) {+ case 0: keep = col >= row; break; // UPPER_DIAG+ case 1: keep = col > row; break; // UPPER+ case 2: keep = col <= row; break; // LOWER_DIAG+ case 3: keep = col < row; break; // LOWER+ default:+ FRONT_END_GENERAL_CHECK(false, "translate_tri: invalid tri_type ", tri_type);+ }+ mask[row * n + col] = keep ? 1.0f : 0.0f;+ }+ }+ // Build the mask in the node's own type, or an f16 input gets promoted to f32 by the Multiply.+ auto keep_mask = ov::op::v0::Constant::create(context.get_attribute<ov::element::Type>("output_type"),+ ov::Shape{1, 1, n, n},+ mask);++ auto res = std::make_shared<ov::op::v1::Multiply>(x, keep_mask);++ return rename_outputs_with_suffix({res}, context.get_name());+}++} // namespace op+} // namespace gguf+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/gguf/src/op/view.cpp b/src/frontends/gguf/src/op/view.cppindex 562a84ce0ee..eabca06f072 100644--- a/src/frontends/gguf/src/op/view.cpp+++ b/src/frontends/gguf/src/op/view.cpp@@ -7,12 +7,50 @@#include "openvino/op/constant.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/slice.hpp"+#include <limits>#include <vector>namespace ov {namespace frontend {namespace gguf {namespace op {+namespace {+// Put the reshape target's single -1 on the axis carrying the runtime token count, recovered by+// element-count conservation: product(tgt) / product(res_ps's static dims). No-op for a static+// res_ps, where the target is already exact and a -1 could land on the wrong axis.+void place_dynamic_token_axis(std::vector<int64_t> & tgt, const ov::PartialShape & res_ps) {+ if (res_ps.rank().is_dynamic()) {+ return;+ }+ int64_t slice_static = 1;+ bool res_has_dyn = false;+ for (int64_t i = 0; i < res_ps.rank().get_length(); ++i) {+ if (res_ps[i].is_static()) {+ slice_static *= res_ps[i].get_length();+ } else {+ res_has_dyn = true;+ }+ }+ if (!res_has_dyn || slice_static == 0) {+ return;+ }+ int64_t out_prod = 1;+ for (auto d : tgt) {+ out_prod *= d;+ }+ if (out_prod % slice_static != 0) {+ return;+ }+ const int64_t token_len = out_prod / slice_static;+ for (auto & d : tgt) {+ if (d == token_len) {+ d = -1;+ break;+ }+ }+}+} // namespace+OutputVector translate_view(const NodeContext & context) {num_inputs_check(context, 1, 1);@@ -22,6 +60,100 @@ OutputVector translate_view(const NodeContext & context) {{process_view_input(context, 0, static_cast<int>(dst_shape[2] * dst_shape[3]))},context.get_name());}+ if (context.get_attribute<int>("op_case", 0) == 5) {+ // qwen3.5 interleaved Q/gate split. The source is a contiguous [F, T] projection whose feature+ // axis packs G groups of `group_stride` elements, and this view selects a `inner_len`-wide+ // sub-block at `inner_off` within every group (e.g. Qcur_full packs [Q(256), gate(256)] per+ // head; the Q view takes inner [0,256), the gate view inner [256,512)). A plain contiguous+ // slice would scramble heads, so restore the source layout, reshape to expose the per-group+ // stride, slice the inner sub-window on the stride axis, then reshape to the view's own layout.+ auto input = context.get_input(0);+ auto iw = context.get_attribute<std::vector<int64_t>>("view_interleaved", {});+ FRONT_END_OP_CONVERSION_CHECK(iw.size() == 4,+ "interleaved view expects {group_count, group_stride, inner_off, inner_len}");+ const int64_t group_count = iw[0];+ const int64_t group_stride = iw[1];+ const int64_t inner_off = iw[2];+ const int64_t inner_len = iw[3];++ // Restore the original ggml (base) shape if the OV input was already reshaped, mirroring+ // op_case 3. The base is [F, T] (ggml) == OV [.., T, F]; we then split F into G x group_stride.+ auto input_ggml_shape = context.get_attribute<ov::Shape>("input_ggml_shape");+ auto input_ov_shape = input.get_partial_shape();+ if (input_ov_shape.rank().is_static() &&+ static_cast<size_t>(input_ov_shape.rank().get_length()) != input_ggml_shape.size()) {+ input = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create(ov::element::i64, {input_ggml_shape.size()}, input_ggml_shape),+ false);+ }++ // Split the feature axis to expose the per-group stride without disturbing the leading dims:+ // [1, 1, T, F] -> [1, 1, T, group_count, group_stride]. special_zero (0 copies the input dim at+ // that position) keeps the leading [1, 1, T] intact -- including the dynamic token axis -- so+ // only the last dim F is factored into the two static group dims.+ auto expose = ov::op::v0::Constant::create(+ ov::element::i64, {5}, std::vector<int64_t>{0, 0, 0, group_count, group_stride});+ auto reshaped = std::make_shared<ov::op::v1::Reshape>(input, expose, /*special_zero=*/true);++ // Slice the inner sub-window [inner_off, inner_off+inner_len) on the group_stride axis (4).+ auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {inner_off});+ auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {inner_off + inner_len});+ auto stride = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});+ auto axis4 = ov::op::v0::Constant::create(ov::element::i64, {1}, {4});+ ov::Output<ov::Node> sliced = std::make_shared<ov::op::v8::Slice>(reshaped, begin, end, stride, axis4);++ // Reshape to the view's own OV layout; -1 lands on the (dynamic) token axis.+ auto tgt = context.get_attribute<std::vector<int64_t>>("view_reshape", {});+ if (!tgt.empty()) {+ place_dynamic_token_axis(tgt, sliced.get_partial_shape());+ auto res = std::make_shared<ov::op::v1::Reshape>(+ sliced, ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt), false);+ return rename_outputs_with_suffix({res}, context.get_name());+ }+ return rename_outputs_with_suffix({sliced}, context.get_name());+ }+ if (context.get_attribute<int>("op_case", 0) == 4) {+ // qwen3-next GDN packed output view. The GATED_DELTA_NET result is [1, 1, T + S_v, S_v*H_v]+ // with the T attention rows stacked on top of the S_v recurrent-state rows (see+ // translate_gated_delta_net). attn_output-0 reads the first T rows; new_state-0 reads the last+ // S_v rows. T (token count) is dynamic, S_v is static, so we slice OV axis 2 with bounds+ // anchored to the static S_v tail (negative indexing), then reshape to the view's own layout.+ auto input = context.get_input(0);+ auto gdn = context.get_attribute<std::vector<int64_t>>("gdn_view", {});+ FRONT_END_OP_CONVERSION_CHECK(gdn.size() == 2, "GDN view expects {part, s_v}");+ const int64_t part = gdn[0]; // 0 = attn (first T rows), 1 = state (last S_v rows)+ const int64_t s_v = gdn[1];++ auto axis2 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});+ auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});+ ov::Output<ov::Node> sliced;+ if (part == 0) {+ // first T rows == everything except the last S_v rows: [0, -S_v)+ auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});+ auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {-s_v});+ sliced = std::make_shared<ov::op::v8::Slice>(input, begin, end, step, axis2);+ } else {+ // last S_v rows: [-S_v, end)+ auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {-s_v});+ auto end = ov::op::v0::Constant::create(ov::element::i64, {1},+ {std::numeric_limits<int64_t>::max()});+ sliced = std::make_shared<ov::op::v8::Slice>(input, begin, end, step, axis2);+ }++ // Reshape the sliced [1,1,rows,S_v*H_v] block to the view's ggml layout (OV order). The attn+ // block keeps the dynamic token axis (-1); the state block is fully static.+ auto tgt = context.get_attribute<std::vector<int64_t>>("view_reshape", {});+ if (!tgt.empty()) {+ if (part == 0) {+ place_dynamic_token_axis(tgt, sliced.get_partial_shape());+ }+ auto res = std::make_shared<ov::op::v1::Reshape>(+ sliced, ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt), false);+ return rename_outputs_with_suffix({res}, context.get_name());+ }+ return rename_outputs_with_suffix({sliced}, context.get_name());+ }if (context.get_attribute<int>("op_case", 0) == 3) {auto input = context.get_input(0);auto input_ov_shape = input.get_partial_shape();@@ -45,7 +177,11 @@ OutputVector translate_view(const NodeContext & context) {if (slice.size() == 3) {const int64_t axis = slice[0], start = slice[1], len = slice[2];auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {start});- auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {start + len});+ // A negative start is an end-anchored TAIL slice (conv_state_last: last d_conv-1 columns+ // of a dynamic-length conv window); its end must run to the axis end, not start+len (which+ // would be <= 0). A non-negative start is an absolute sub-range, ending at start+len.+ const int64_t end_val = start < 0 ? std::numeric_limits<int64_t>::max() : start + len;+ auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {end_val});auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});auto axes = ov::op::v0::Constant::create(ov::element::i64, {1}, {axis});result = std::make_shared<ov::op::v8::Slice>(input, begin, end, step, axes);@@ -59,42 +195,7 @@ OutputVector translate_view(const NodeContext & context) {// token axis -- so the token dim stays dynamic and lands where the consumer expects it.auto tgt = context.get_attribute<std::vector<int64_t>>("view_reshape", {});if (!tgt.empty()) {- // The decoder gives the (static) output layout. The sliced result carries the token- // count on one dynamic axis; keep it dynamic by placing a single -1 on the output axis- // that absorbs it. Determine that axis by conservation of element count: the product of- // the sliced result's static dims must equal the product of the output's non--1 dims,- // so the -1 axis is the one whose value equals (token count) = slice_static_product /- // (output_static_product_without_that_axis). Concretely, if the sliced result has a- // dynamic axis, exactly one output axis must be -1; pick the output axis whose value is- // not needed to match the sliced result's static dims.- const auto& res_ps = result.get_partial_shape();- bool res_has_dyn = res_ps.rank().is_static() && [&] {- for (int64_t i = 0; i < res_ps.rank().get_length(); ++i)- if (res_ps[i].is_dynamic())- return true;- return false;- }();- if (res_has_dyn) {- // product of static dims in the sliced result (excludes the single dynamic axis)- int64_t slice_static = 1;- for (int64_t i = 0; i < res_ps.rank().get_length(); ++i)- if (res_ps[i].is_static())- slice_static *= res_ps[i].get_length();- // product of all output dims- int64_t out_prod = 1;- for (auto d : tgt)- out_prod *= d;- // token count = out_prod / slice_static ; mark the axis holding it as -1- if (slice_static != 0 && out_prod % slice_static == 0) {- int64_t token_len = out_prod / slice_static;- for (auto& d : tgt) {- if (d == token_len) {- d = -1;- break;- }- }- }- }+ place_dynamic_token_axis(tgt, result.get_partial_shape());result = std::make_shared<ov::op::v1::Reshape>(result, ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt), false);}diff --git a/src/frontends/gguf/src/op_table.cpp b/src/frontends/gguf/src/op_table.cppindex ea449add92c..ed2bb8cca5d 100644--- a/src/frontends/gguf/src/op_table.cpp+++ b/src/frontends/gguf/src/op_table.cpp@@ -6,9 +6,12 @@#include "openvino/op/add.hpp"#include "openvino/op/divide.hpp"+#include "openvino/op/exp.hpp"#include "openvino/op/gather.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/multiply.hpp"+#include "openvino/op/negative.hpp"+#include "openvino/op/sigmoid.hpp"#include "openvino/op/softplus.hpp"#include "openvino/op/subtract.hpp"#include "openvino/op/tanh.hpp"@@ -33,7 +36,10 @@ std::unordered_map<std::string, CreatorFunction> get_supported_ops() {{"GGML_OP_CONCAT", op::translate_concat},{"GGML_OP_CONT", op::translate_cont},{"GGML_OP_CPY", op::translate_cpy},- {"GGML_OP_DIV", op::translate_1to1_match_2_inputs<v1::Divide>},+ {"GGML_OP_CUMSUM", op::translate_cumsum},+ {"GGML_OP_DIAG", op::translate_diag},+ {"GGML_OP_DIV", op::translate_div},+ {"GGML_OP_FILL", op::translate_fill},{"GGML_OP_FLASH_ATTN_EXT", op::translate_flash_attn_ext},{"GGML_OP_GATED_DELTA_NET", op::translate_gated_delta_net},{"GGML_OP_GET_ROWS", op::translate_get_rows},@@ -52,14 +58,21 @@ std::unordered_map<std::string, CreatorFunction> get_supported_ops() {{"GGML_OP_RMS_NORM", op::translate_rms_norm},{"GGML_OP_ROPE", op::translate_rope},{"GGML_OP_SCALE", op::translate_scale},+ {"GGML_OP_SET", op::translate_set},{"GGML_OP_SET_ROWS", op::translate_set_rows},{"GGML_OP_SOFT_MAX", op::translate_soft_max},+ {"GGML_OP_SQR", op::translate_sqr},+ {"GGML_OP_SQRT", op::translate_sqrt},{"GGML_OP_SSM_CONV", op::translate_ssm_conv},{"GGML_OP_SUB", op::translate_1to1_match_2_inputs<v1::Subtract>},{"GGML_OP_SUM_ROWS", op::translate_sum_rows},+ {"GGML_OP_TRI", op::translate_tri},{"GGML_OP_TRANSPOSE", op::translate_transpose},{"GGML_OP_VIEW", op::translate_view},+ {"GGML_UNARY_OP_EXP", op::translate_1to1_match_1_input<v0::Exp>},{"GGML_UNARY_OP_GELU", op::translate_unary_gelu},+ {"GGML_UNARY_OP_NEG", op::translate_1to1_match_1_input<v0::Negative>},+ {"GGML_UNARY_OP_SIGMOID", op::translate_1to1_match_1_input<v0::Sigmoid>},{"GGML_UNARY_OP_SILU", op::translate_unary_silu},{"GGML_UNARY_OP_SOFTPLUS", op::translate_1to1_match_1_input<v4::SoftPlus>},{"GGML_UNARY_OP_TANH", op::translate_1to1_match_1_input<v0::Tanh>},diff --git a/src/frontends/gguf/src/op_table.hpp b/src/frontends/gguf/src/op_table.hppindex 9a6b5d26380..a8eb61730e9 100644--- a/src/frontends/gguf/src/op_table.hpp+++ b/src/frontends/gguf/src/op_table.hpp@@ -19,6 +19,10 @@ GGUF_OP_CONVERTER(translate_argsort);GGUF_OP_CONVERTER(translate_clamp);GGUF_OP_CONVERTER(translate_concat);GGUF_OP_CONVERTER(translate_cont);+GGUF_OP_CONVERTER(translate_cumsum);+GGUF_OP_CONVERTER(translate_diag);+GGUF_OP_CONVERTER(translate_div);+GGUF_OP_CONVERTER(translate_fill);GGUF_OP_CONVERTER(translate_gated_delta_net);GGUF_OP_CONVERTER(translate_get_rows);GGUF_OP_CONVERTER(translate_im2col);@@ -34,6 +38,10 @@ GGUF_OP_CONVERTER(translate_reshape);GGUF_OP_CONVERTER(translate_rms_norm);GGUF_OP_CONVERTER(translate_rope);GGUF_OP_CONVERTER(translate_scale);+GGUF_OP_CONVERTER(translate_set);+GGUF_OP_CONVERTER(translate_sqr);+GGUF_OP_CONVERTER(translate_sqrt);+GGUF_OP_CONVERTER(translate_tri);GGUF_OP_CONVERTER(translate_sum_rows);GGUF_OP_CONVERTER(translate_unary_silu);GGUF_OP_CONVERTER(translate_unary_gelu);diff --git a/src/frontends/gguf/src/quant/weights.cpp b/src/frontends/gguf/src/quant/weights.cppindex 613aa7c8a57..256ff316b8d 100644--- a/src/frontends/gguf/src/quant/weights.cpp+++ b/src/frontends/gguf/src/quant/weights.cpp@@ -12,7 +12,6 @@#include <cctype>#include <cmath>-#include <cstdlib>#include <cstring>#include <vector>@@ -392,11 +391,6 @@ std::vector<float> dequant_extracted_to_f32(const std::unordered_map<std::string// Decide whether a weight is requantized to Q8_0_C, mirroring llama.cpp's// ggml_openvino_get_requant_type for the CPU/GPU (non-NPU) path.bool needs_q8_0_c_requant(const std::string& name, gguf_tensor_type qtype) {- // The env var does not change during a conversion; read it once.- static const bool no_requant = std::getenv("GGUF_FE_NO_REQUANT") != nullptr;- if (no_requant) {- return false; // diagnostic: faithful dequant only- }if (name.rfind("token_embd.weight", 0) == 0 || name.rfind("output.weight", 0) == 0) {return true;}@@ -629,7 +623,7 @@ std::shared_ptr<ov::Node> make_weight_node(const ov::Tensor& data,// Non-K requant sources (e.g. an F16 / Q4_0 / Q8_0 token_embd or output): the K-quant fast path// above already handled Q4_K/Q5_K/Q6_K, so here reproduce the backend's channel-wise Q8_0_C by// dequantizing to f32 from the extracted tensors, then re-quantizing.- if (requant) { // computed above; reuse rather than re-running getenv + name scans+ if (requant) {auto f32 = dequant_extracted_to_f32(w, base, rows, cols);return requantize_q8_0_channelwise(f32, rows, cols);}diff --git a/src/frontends/gguf/src/translate_session.cpp b/src/frontends/gguf/src/translate_session.cppindex 1e2c2843fb9..3e37dd6e987 100644--- a/src/frontends/gguf/src/translate_session.cpp+++ b/src/frontends/gguf/src/translate_session.cpp@@ -80,7 +80,7 @@ void add_rope_sin_cos(TensorMap& tensor_map, const RopeConfig& rope_config) {rope_freqs_weight = tensor_map.at("rope_freqs.weight").get_node_shared_ptr();}- auto sin_cos = make_sin_cos(rope_config, inp_pos, rope_freqs_weight);+ auto sin_cos = make_sin_cos(rope_config, inp_pos, rope_freqs_weight, rope_config.is_imrope);auto sin_theta = sin_cos.first;auto cos_theta = sin_cos.second;diff --git a/src/frontends/gguf/src/utils.cpp b/src/frontends/gguf/src/utils.cppindex d7d2e97abf0..e3d61289360 100644--- a/src/frontends/gguf/src/utils.cpp+++ b/src/frontends/gguf/src/utils.cpp@@ -201,15 +201,30 @@ ov::Output<ov::Node> process_view_input(const NodeContext& context, int input_in// If the VIEW also reshape the result, `slice_len` should be providedauto input = context.get_input(input_index);int64_t split_addr = context.get_input_view_element_offset(input_index);- if (slice_len == 0) {- slice_len = static_cast<int>(context.get_input(input_index).get_partial_shape()[3].get_length());- }- int64_t slice_end = split_addr + slice_len;auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {split_addr});- auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {slice_end});auto stride = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});auto axes = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});++ ov::Output<ov::Node> end;+ const auto& dim3 = input.get_partial_shape()[3];+ if (slice_len == 0 && dim3.is_dynamic()) {+ // The view's lowest axis is dynamic (e.g. qwen3-next's s_copy recurrent-state slot reorder,+ // whose active-sequence count is only known at runtime), so its length cannot be read at+ // convert time. Derive the slice end at runtime: end = split_addr + shape_of(input)[3].+ auto shape = std::make_shared<ov::op::v3::ShapeOf>(input, ov::element::i64);+ auto idx = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});+ auto gather_axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});+ auto dim = std::make_shared<ov::op::v8::Gather>(shape, idx, gather_axis);+ auto split = ov::op::v0::Constant::create(ov::element::i64, {1}, {split_addr});+ end = std::make_shared<ov::op::v1::Add>(dim, split);+ } else {+ if (slice_len == 0) {+ slice_len = static_cast<int>(dim3.get_length());+ }+ end = ov::op::v0::Constant::create(ov::element::i64, {1}, {split_addr + slice_len});+ }+auto sliced = std::make_shared<ov::op::v8::Slice>(input, begin, end, stride, axes);return sliced;}diff --git a/src/frontends/gguf/tests/CMakeLists.txt b/src/frontends/gguf/tests/CMakeLists.txtindex 5fcf7885c44..a55c3cee305 100644--- a/src/frontends/gguf/tests/CMakeLists.txt+++ b/src/frontends/gguf/tests/CMakeLists.txt@@ -23,6 +23,10 @@ set(FRONTEND_SRCS"${FE_SRC_DIR}/op/concat.cpp""${FE_SRC_DIR}/op/cont.cpp""${FE_SRC_DIR}/op/cpy.cpp"+ "${FE_SRC_DIR}/op/cumsum.cpp"+ "${FE_SRC_DIR}/op/diag.cpp"+ "${FE_SRC_DIR}/op/div.cpp"+ "${FE_SRC_DIR}/op/fill.cpp""${FE_SRC_DIR}/op/flash_attn_ext.cpp""${FE_SRC_DIR}/op/gated_delta_net.cpp""${FE_SRC_DIR}/op/get_rows.cpp"@@ -40,9 +44,12 @@ set(FRONTEND_SRCS"${FE_SRC_DIR}/op/rms_norm.cpp""${FE_SRC_DIR}/op/rope.cpp""${FE_SRC_DIR}/op/scale.cpp"+ "${FE_SRC_DIR}/op/set.cpp""${FE_SRC_DIR}/op/set_rows.cpp""${FE_SRC_DIR}/op/softmax.cpp"+ "${FE_SRC_DIR}/op/sqr.cpp""${FE_SRC_DIR}/op/ssm_conv.cpp"+ "${FE_SRC_DIR}/op/tri.cpp""${FE_SRC_DIR}/op/sum_rows.cpp""${FE_SRC_DIR}/op/transpose.cpp""${FE_SRC_DIR}/op/unary_gelu.cpp"diff --git a/src/frontends/gguf/tests/gdn_gqa_oracle.c b/src/frontends/gguf/tests/gdn_gqa_oracle.cnew file mode 100644index 00000000000..cb43df73fad--- /dev/null+++ b/src/frontends/gguf/tests/gdn_gqa_oracle.c@@ -0,0 +1,84 @@+// Standalone ggml-CPU oracle for GGML_OP_GATED_DELTA_NET with GQA (H_v != H_k).+// Real qwen3.5 has num_v_heads=32, num_k_heads=16 (ratio 2): every V head pairs with Q/K head+// (v_head % H_k). None of the existing GDN op-tests exercise this (they all use H_k==H_v), so a+// wrong Q/K->V head mapping in the frontend would be invisible to them yet corrupt every real+// token. This oracle uses H_v=4, H_k=2 (ratio 2) with DISTINCT per-head inputs so a mis-pairing+// (e.g. grouped vs interleaved repeat) produces a different output. Authoritative: ggml's own kernel.+#include "ggml.h"+#include "ggml-cpu.h"+#include "ggml-alloc.h"+#include "ggml-backend.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <math.h>++int main(void) {+ const int64_t B = 1, T = 2, H_v = 4, H_k = 2, D = 2; // GQA: 4 v-heads, 2 k-heads, ratio 2++ struct ggml_init_params ip = { 64*1024*1024, NULL, true };+ struct ggml_context * ctx = ggml_init(ip);++ // ggml layout (ne[0] innermost):+ // q,k : [S_k, H_k, n_tokens, n_seqs]+ // v : [S_v, H_v, n_tokens, n_seqs]+ // g : [1, H_v, n_tokens, n_seqs] scalar gate+ // beta: [1, H_v, n_tokens, n_seqs]+ // state:[S_v, S_v, H_v, n_seqs]+ struct ggml_tensor * q = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H_k, T, B);+ struct ggml_tensor * k = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H_k, T, B);+ struct ggml_tensor * v = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H_v, T, B);+ struct ggml_tensor * g = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 1, H_v, T, B);+ struct ggml_tensor * beta = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 1, H_v, T, B);+ struct ggml_tensor * state = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, D, H_v, B);++ ggml_set_name(q, "q"); ggml_set_name(k, "k"); ggml_set_name(v, "v");+ ggml_set_name(g, "g"); ggml_set_name(beta, "beta"); ggml_set_name(state, "state");++ struct ggml_tensor * out = ggml_gated_delta_net(ctx, q, k, v, g, beta, state, /*K=*/1);+ ggml_set_name(out, "out");++ struct ggml_cgraph * gf = ggml_new_graph(ctx);+ ggml_build_forward_expand(gf, out);++ ggml_backend_t backend = ggml_backend_cpu_init();+ ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);+ (void) buf;++ // DISTINCT per-head q/k so head0 and head1 differ (else GQA pairing is unobservable).+ // Layout [T, H_k, D]: t0{h0,h1}, t1{h0,h1}+ float qd[] = {1,0, 0,1, 0,1, 1,0}; // [T, H_k=2, D]+ float kd[] = {1,0, 0,1, 1,1, 0,1}; // [T, H_k=2, D]+ // V has 4 heads; heads 0,2 -> k-head0, heads 1,3 -> k-head1 (ggml pairing v_head % H_k).+ // Layout [T, H_v=4, D]+ float vd[] = {1,2, 3,4, 5,6, 7,8, 9,10, 11,12, 13,14, 15,16}; // [T, H_v=4, D]+ float gd[] = {0,0,0,0, 0,0,0,0}; // [T, H_v] scalar gate exp(g)=1+ float bd[] = {1,1,1,1, 1,1,1,1}; // full update+ float sd[H_v*D*D]; memset(sd, 0, sizeof(sd)); // zero initial state++ ggml_backend_tensor_set(q, qd, 0, sizeof(qd));+ ggml_backend_tensor_set(k, kd, 0, sizeof(kd));+ ggml_backend_tensor_set(v, vd, 0, sizeof(vd));+ ggml_backend_tensor_set(g, gd, 0, sizeof(gd));+ ggml_backend_tensor_set(beta, bd, 0, sizeof(bd));+ ggml_backend_tensor_set(state, sd, 0, sizeof(sd));++ if (ggml_backend_graph_compute(backend, gf) != GGML_STATUS_SUCCESS) {+ fprintf(stderr, "compute failed\n");+ return 1;+ }++ printf("out ne = [%lld, %lld, %lld, %lld]\n",+ (long long)out->ne[0], (long long)out->ne[1], (long long)out->ne[2], (long long)out->ne[3]);+ int64_t n = ggml_nelements(out);+ float * od = malloc(n * sizeof(float));+ ggml_backend_tensor_get(out, od, 0, n * sizeof(float));+ printf("flat out (%lld elems):\n", (long long)n);+ for (int64_t i = 0; i < n; i++) printf("%.6f%s", od[i], (i+1)%(out->ne[0]) ? " " : "\n");+ printf("\n");+ free(od);+ ggml_backend_buffer_free(buf);+ ggml_backend_free(backend);+ ggml_free(ctx);+ return 0;+}diff --git a/src/frontends/gguf/tests/gdn_oracle.c b/src/frontends/gguf/tests/gdn_oracle.cnew file mode 100644index 00000000000..42323182c79--- /dev/null+++ b/src/frontends/gguf/tests/gdn_oracle.c@@ -0,0 +1,80 @@+// Standalone ggml-CPU oracle for GGML_OP_GATED_DELTA_NET.+// Builds a single GDN node with the SAME tiny multi-head inputs as the OV frontend op-test,+// runs it on the ggml CPU backend, and prints the flat output. This is the authoritative+// reference: ggml's own kernel, not a hand-derived recurrence that might share the frontend's+// layout assumption.+#include "ggml.h"+#include "ggml-cpu.h"+#include "ggml-alloc.h"+#include "ggml-backend.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <math.h>++int main(void) {+ const int64_t B = 1, T = 2, H = 2, D = 2; // n_seqs, n_tokens, heads, head-dim (S_k=S_v=D)++ struct ggml_init_params ip = { 64*1024*1024, NULL, true }; // no_alloc: backend allocates+ struct ggml_context * ctx = ggml_init(ip);++ // ggml layout (ne[0] innermost):+ // q,k : [S_k, H_k, n_tokens, n_seqs] here H_k=H+ // v : [S_v, H_v, n_tokens, n_seqs]+ // g : [1, H_v, n_tokens, n_seqs] scalar gate+ // beta: [1, H_v, n_tokens, n_seqs]+ // state:[S_v, S_v, H_v, n_seqs]+ struct ggml_tensor * q = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H, T, B);+ struct ggml_tensor * k = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H, T, B);+ struct ggml_tensor * v = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, H, T, B);+ struct ggml_tensor * g = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 1, H, T, B);+ struct ggml_tensor * beta = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 1, H, T, B);+ struct ggml_tensor * state = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, D, D, H, B);++ ggml_set_name(q, "q"); ggml_set_name(k, "k"); ggml_set_name(v, "v");+ ggml_set_name(g, "g"); ggml_set_name(beta, "beta"); ggml_set_name(state, "state");++ struct ggml_tensor * out = ggml_gated_delta_net(ctx, q, k, v, g, beta, state, /*K=*/1);+ ggml_set_name(out, "out");++ struct ggml_cgraph * gf = ggml_new_graph(ctx);+ ggml_build_forward_expand(gf, out);++ // Allocate on CPU backend and fill inputs (same values/order as the OV op-test, [T,H,D]).+ ggml_backend_t backend = ggml_backend_cpu_init();+ ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);+ (void) buf;++ float qd[] = {1,0, 0,1, 0,1, 1,0}; // [T,H,D]+ float kd[] = {1,0, 0,1, 1,1, 0,1};+ float vd[] = {1,2, 3,4, 5,6, 7,8};+ float gd[] = {0,0, 0,0}; // [T,H]+ float bd[] = {1,1, 1,1};+ float sd[8]; memset(sd, 0, sizeof(sd)); // [H,D,D] zero initial state++ ggml_backend_tensor_set(q, qd, 0, sizeof(qd));+ ggml_backend_tensor_set(k, kd, 0, sizeof(kd));+ ggml_backend_tensor_set(v, vd, 0, sizeof(vd));+ ggml_backend_tensor_set(g, gd, 0, sizeof(gd));+ ggml_backend_tensor_set(beta, bd, 0, sizeof(bd));+ ggml_backend_tensor_set(state, sd, 0, sizeof(sd));++ if (ggml_backend_graph_compute(backend, gf) != GGML_STATUS_SUCCESS) {+ fprintf(stderr, "compute failed\n");+ return 1;+ }++ printf("out ne = [%lld, %lld, %lld, %lld]\n",+ (long long)out->ne[0], (long long)out->ne[1], (long long)out->ne[2], (long long)out->ne[3]);+ int64_t n = ggml_nelements(out);+ float * od = malloc(n * sizeof(float));+ ggml_backend_tensor_get(out, od, 0, n * sizeof(float));+ printf("flat out (%lld elems):\n", (long long)n);+ for (int64_t i = 0; i < n; i++) printf("%.6f%s", od[i], (i+1)%(out->ne[0]) ? " " : "\n");+ printf("\n");+ free(od);+ ggml_backend_buffer_free(buf);+ ggml_backend_free(backend);+ ggml_free(ctx);+ return 0;+}diff --git a/src/frontends/gguf/tests/imrope_oracle.c b/src/frontends/gguf/tests/imrope_oracle.cnew file mode 100644index 00000000000..b20955cc9fb--- /dev/null+++ b/src/frontends/gguf/tests/imrope_oracle.c@@ -0,0 +1,69 @@+// Standalone ggml-CPU oracle for GGML_OP_ROPE in IMROPE (interleaved M-RoPE) mode, at qwen3.5's+// exact config (n_dims=64, sections={11,11,10,0}, freq_base=1e7). Text decode uses the same+// position id for all 4 mrope sections, so pos is [p,p,p,p] per token. Prints the flat rotated+// output so the OV frontend op-test can assert against ggml's own IMROPE kernel.+#include "ggml.h"+#include "ggml-cpu.h"+#include "ggml-backend.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#define GGML_ROPE_TYPE_IMROPE 40++int main(void) {+ const int64_t head_dim = 64, n_head = 1, n_tokens = 2, batch = 1;+ const int n_dims = 64;+ int sections[4] = {11, 11, 10, 0};++ struct ggml_init_params ip = { 64*1024*1024, NULL, true };+ struct ggml_context * ctx = ggml_init(ip);++ // a: [head_dim, n_head, n_tokens, batch]+ struct ggml_tensor * a = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, head_dim, n_head, n_tokens, batch);+ // pos: mrope needs 4 * n_tokens int32 (4 sections). Layout: [t-sect | h-sect | w-sect | e-sect].+ struct ggml_tensor * pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, n_tokens * 4);+ ggml_set_name(a, "a"); ggml_set_name(pos, "pos");++ struct ggml_tensor * out = ggml_rope_multi(+ ctx, a, pos, NULL, n_dims, sections, GGML_ROPE_TYPE_IMROPE,+ /*n_ctx_orig*/262144, /*freq_base*/1e7f, /*freq_scale*/1.0f,+ /*ext_factor*/0.0f, /*attn_factor*/1.0f, /*beta_fast*/32.0f, /*beta_slow*/1.0f);+ ggml_set_name(out, "out");++ struct ggml_cgraph * gf = ggml_new_graph(ctx);+ ggml_build_forward_expand(gf, out);++ ggml_backend_t backend = ggml_backend_cpu_init();+ ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);+ (void) buf;++ // a: deterministic ramp per token: element e of token t = (t+1) + 0.01*e+ float ad[64*2];+ for (int t = 0; t < n_tokens; ++t)+ for (int e = 0; e < head_dim; ++e)+ ad[t*head_dim + e] = (float)(t+1) + 0.01f*e;+ // positions: token 0 -> pos 0, token 1 -> pos 1, identical across all 4 sections+ int32_t pd[8] = {0,1, 0,1, 0,1, 0,1};+ ggml_backend_tensor_set(a, ad, 0, sizeof(ad));+ ggml_backend_tensor_set(pos, pd, 0, sizeof(pd));++ if (ggml_backend_graph_compute(backend, gf) != GGML_STATUS_SUCCESS) {+ fprintf(stderr, "compute failed\n");+ return 1;+ }++ printf("out ne = [%lld, %lld, %lld, %lld]\n",+ (long long)out->ne[0], (long long)out->ne[1], (long long)out->ne[2], (long long)out->ne[3]);+ int64_t n = ggml_nelements(out);+ float * od = malloc(n * sizeof(float));+ ggml_backend_tensor_get(out, od, 0, n * sizeof(float));+ printf("flat out (%lld elems), per token row of head_dim:\n", (long long)n);+ for (int64_t i = 0; i < n; i++) printf("%.6f%s", od[i], (i+1)%(out->ne[0]) ? " " : "\n");+ printf("\n");+ free(od);+ ggml_backend_buffer_free(buf);+ ggml_backend_free(backend);+ ggml_free(ctx);+ return 0;+}diff --git a/src/frontends/gguf/tests/imrope_partial_oracle.c b/src/frontends/gguf/tests/imrope_partial_oracle.cnew file mode 100644index 00000000000..69eb6bbf4cc--- /dev/null+++ b/src/frontends/gguf/tests/imrope_partial_oracle.c@@ -0,0 +1,67 @@+// Standalone ggml-CPU oracle for GGML_OP_ROPE in IMROPE mode with PARTIAL rotary+// (n_dims < head_dim), at qwen3.5's exact full-attention config: head_dim=256,+// rope.dimension_count=64, sections={11,11,10,0}, freq_base=1e7. Only the first 64 dims of+// every head are rotated; the remaining 192 pass through unchanged. This is the case the+// head_dim==n_dims op-test (ImropeTextRealDims) never exercised and where the frontend used to+// rotate the whole head. Prints the flat output so the OV op-test can assert against ggml's kernel.+#include "ggml.h"+#include "ggml-cpu.h"+#include "ggml-backend.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#define GGML_ROPE_TYPE_IMROPE 40++int main(void) {+ const int64_t head_dim = 256, n_head = 1, n_tokens = 2, batch = 1;+ const int n_dims = 64; // partial: only first 64 of 256 rotated+ int sections[4] = {11, 11, 10, 0};++ struct ggml_init_params ip = { 64*1024*1024, NULL, true };+ struct ggml_context * ctx = ggml_init(ip);++ struct ggml_tensor * a = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, head_dim, n_head, n_tokens, batch);+ struct ggml_tensor * pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, n_tokens * 4);+ ggml_set_name(a, "a"); ggml_set_name(pos, "pos");++ struct ggml_tensor * out = ggml_rope_multi(+ ctx, a, pos, NULL, n_dims, sections, GGML_ROPE_TYPE_IMROPE,+ /*n_ctx_orig*/262144, /*freq_base*/1e7f, /*freq_scale*/1.0f,+ /*ext_factor*/0.0f, /*attn_factor*/1.0f, /*beta_fast*/32.0f, /*beta_slow*/1.0f);+ ggml_set_name(out, "out");++ struct ggml_cgraph * gf = ggml_new_graph(ctx);+ ggml_build_forward_expand(gf, out);++ ggml_backend_t backend = ggml_backend_cpu_init();+ ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);+ (void) buf;++ float ad[256*2];+ for (int t = 0; t < n_tokens; ++t)+ for (int e = 0; e < head_dim; ++e)+ ad[t*head_dim + e] = (float)(t+1) + 0.01f*e;+ int32_t pd[8] = {0,1, 0,1, 0,1, 0,1};+ ggml_backend_tensor_set(a, ad, 0, sizeof(ad));+ ggml_backend_tensor_set(pos, pd, 0, sizeof(pd));++ if (ggml_backend_graph_compute(backend, gf) != GGML_STATUS_SUCCESS) {+ fprintf(stderr, "compute failed\n");+ return 1;+ }++ printf("out ne = [%lld, %lld, %lld, %lld]\n",+ (long long)out->ne[0], (long long)out->ne[1], (long long)out->ne[2], (long long)out->ne[3]);+ int64_t n = ggml_nelements(out);+ float * od = malloc(n * sizeof(float));+ ggml_backend_tensor_get(out, od, 0, n * sizeof(float));+ printf("flat out (%lld elems), per token row of head_dim:\n", (long long)n);+ for (int64_t i = 0; i < n; i++) printf("%.6f%s", od[i], (i+1)%(out->ne[0]) ? " " : "\n");+ printf("\n");+ free(od);+ ggml_backend_buffer_free(buf);+ ggml_backend_free(backend);+ ggml_free(ctx);+ return 0;+}diff --git a/src/frontends/gguf/tests/op_test_utils.hpp b/src/frontends/gguf/tests/op_test_utils.hppindex eaa22e97b32..48c669aa478 100644--- a/src/frontends/gguf/tests/op_test_utils.hpp+++ b/src/frontends/gguf/tests/op_test_utils.hpp@@ -32,9 +32,11 @@#include "openvino/core/model.hpp"#include "openvino/core/partial_shape.hpp"#include "openvino/core/type/element_type.hpp"+#include "openvino/core/visibility.hpp"#include "openvino/frontend/gguf/frontend.hpp"#include "openvino/op/parameter.hpp"#include "openvino/runtime/core.hpp"+#include "openvino/runtime/properties.hpp"#include "openvino/runtime/tensor.hpp"#include "openvino/util/file_util.hpp"@@ -211,9 +213,15 @@ inline ov::Tensor make_f32_tensor(const ov::Shape& shape, const std::vector<floa}// Compile on CPU and run one inference with the given named inputs; return the single output.+//+// Inference precision is requested as f32: these tests validate the converted graph against an fp32+// reference, not the plugin's reduced-precision arithmetic, so wherever fp32 inference is available we+// want it regardless of the plugin's performance-mode default (e.g. bf16 on avx512_core_bf16 hosts).+// Where fp32 is not supported (ARM, which always infers in fp16) the request is silently ignored, and+// the wider tolerance below covers the resulting rounding error.inline ov::Tensor run_on_cpu(const std::shared_ptr<ov::Model>& model, const std::map<std::string, ov::Tensor>& inputs) {ov::Core core;- auto compiled = core.compile_model(model, "CPU");+ auto compiled = core.compile_model(model, "CPU", ov::hint::inference_precision(ov::element::f32));auto req = compiled.create_infer_request();for (const auto& kv : inputs) {req.set_tensor(kv.first, kv.second);@@ -222,15 +230,28 @@ inline ov::Tensor run_on_cpu(const std::shared_ptr<ov::Model>& model, const std:return req.get_output_tensor(0);}+// Default relative tolerance, per inference precision the CPU plugin actually uses.+//+// On ARM the f32 request above cannot be honored (the plugin always infers in fp16), so rounding+// error accumulates through long op chains such as rope; the measured worst case needs ~3e-3.+//+// Everywhere else the f32 request holds and the measured worst case across this suite is ~1.4e-6,+// so the bound stays near fp32 precision — tight enough that a real conversion error cannot hide+// inside it.+#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)+# define OV_GGUF_TEST_DEFAULT_RTOL 1e-2f+#else+# define OV_GGUF_TEST_DEFAULT_RTOL 1e-5f+#endif+// Compare against an fp32 reference with a combined absolute + relative tolerance:// |actual - expected| <= atol + rtol * |expected|-// The relative term matters on hardware that runs the graph in fp16 (e.g. ARM CPU by default),-// where the rounding error grows with the magnitude of the value; a fixed absolute atol tuned on-// fp32 x86 is too tight there. rtol defaults to ~fp16 precision (2^-9).+// The relative term matters on hardware that runs the graph in fp16 (e.g. ARM CPU), where the+// rounding error grows with the magnitude of the value.inline void expect_near(const ov::Tensor& actual,const std::vector<float>& expected,float atol = 1e-4f,- float rtol = 2e-3f) {+ float rtol = OV_GGUF_TEST_DEFAULT_RTOL) {ASSERT_EQ(actual.get_element_type(), ov::element::f32);ASSERT_EQ(actual.get_size(), expected.size());const float* a = actual.data<float>();diff --git a/src/frontends/gguf/tests/ssm_conv_oracle.c b/src/frontends/gguf/tests/ssm_conv_oracle.cnew file mode 100644index 00000000000..738bfb5df4f--- /dev/null+++ b/src/frontends/gguf/tests/ssm_conv_oracle.c@@ -0,0 +1,70 @@+// Standalone ggml-CPU oracle for GGML_OP_SSM_CONV at the qwen3.5/qwen3-next conv dims+// (d_conv=4, n_t>1, multiple channels). Builds one ggml_ssm_conv node, runs it on the ggml+// CPU backend, and prints the flat output so the OV frontend op-test can assert against ggml's+// own kernel instead of a hand-derived depthwise-conv reference.+//+// ggml layout:+// sx (conv state + input) : 3D [ncs, d_inner, n_s], ncs = n_t + d_conv - 1+// c (conv1d weight) : 2D [d_conv, d_inner]+// out : 3D [d_inner, n_t, n_s]+#include "ggml.h"+#include "ggml-cpu.h"+#include "ggml-backend.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++int main(void) {+ const int64_t d_conv = 4, d_inner = 3, n_t = 5, n_s = 1;+ const int64_t ncs = n_t + d_conv - 1; // 8++ struct ggml_init_params ip = { 64*1024*1024, NULL, true };+ struct ggml_context * ctx = ggml_init(ip);++ struct ggml_tensor * sx = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, ncs, d_inner, n_s);+ struct ggml_tensor * c = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d_conv, d_inner);+ ggml_set_name(sx, "sx"); ggml_set_name(c, "c");++ struct ggml_tensor * out = ggml_ssm_conv(ctx, sx, c);+ ggml_set_name(out, "out");++ struct ggml_cgraph * gf = ggml_new_graph(ctx);+ ggml_build_forward_expand(gf, out);++ ggml_backend_t backend = ggml_backend_cpu_init();+ ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);+ (void) buf;++ // sx: channel-major [d_inner][ncs]; ch0 = 1..8, ch1 = 11..18, ch2 = 21..28+ float sxd[3*8];+ for (int ch = 0; ch < d_inner; ++ch)+ for (int j = 0; j < ncs; ++j)+ sxd[ch*ncs + j] = (float)(ch*10 + j + 1);+ // c: per-channel kernel [d_inner][d_conv]; distinct so channel mixing would show up+ float cd[3*4] = {+ 0.5f, 0.25f, 0.125f, 0.0625f, // ch0+ 1.0f, 0.0f, 0.0f, 0.0f, // ch1 (picks earliest window element)+ 0.0f, 0.0f, 0.0f, 1.0f, // ch2 (picks latest window element)+ };+ ggml_backend_tensor_set(sx, sxd, 0, sizeof(sxd));+ ggml_backend_tensor_set(c, cd, 0, sizeof(cd));++ if (ggml_backend_graph_compute(backend, gf) != GGML_STATUS_SUCCESS) {+ fprintf(stderr, "compute failed\n");+ return 1;+ }++ printf("out ne = [%lld, %lld, %lld, %lld]\n",+ (long long)out->ne[0], (long long)out->ne[1], (long long)out->ne[2], (long long)out->ne[3]);+ int64_t n = ggml_nelements(out);+ float * od = malloc(n * sizeof(float));+ ggml_backend_tensor_get(out, od, 0, n * sizeof(float));+ printf("flat out (%lld elems), layout [n_s][n_t][d_inner]:\n", (long long)n);+ for (int64_t i = 0; i < n; i++) printf("%.6f%s", od[i], (i+1)%(out->ne[0]) ? " " : "\n");+ printf("\n");+ free(od);+ ggml_backend_buffer_free(buf);+ ggml_backend_free(backend);+ ggml_free(ctx);+ return 0;+}diff --git a/src/frontends/gguf/tests/test_ops.cpp b/src/frontends/gguf/tests/test_ops.cppindex 8f07b29855e..4af080b66f9 100644--- a/src/frontends/gguf/tests/test_ops.cpp+++ b/src/frontends/gguf/tests/test_ops.cpp@@ -584,6 +584,62 @@ TEST(GGUFOps, MulMatIdNused2) {expect_near(out, expected, 1e-4f);}+// MulMatId whose activations already carry the expanded expert axis ([n_token, n_used, k]) instead of+// a singleton -- the layout ggml uses for the ffn_down matmul, where each (token, expert) pair has its+// own activation row. Reshaping this form to one row per token would silently drop data, so the+// translator has to leave it as it is.+TEST(GGUFOps, MulMatIdActivationsPerExpert) {+ const int64_t n_expert = 3, m = 2, k = 2, n_tokens = 2, n_used = 2;+ auto model = SingleOpBuilder()+ .op("GGML_OP_MUL_MAT_ID")+ .input("w", ov::element::f32, {1, n_expert, m, k})+ .input("a", ov::element::f32, {1, n_tokens, n_used, k})+ .input("ids", ov::element::i32, {1, 1, n_tokens, n_used})+ .output("out", ov::element::f32, {1, n_tokens, n_used, m})+ .build();++ // experts: e0 rows [1,0],[0,1]; e1 rows [2,0],[0,2]; e2 rows [3,0],[0,3]+ std::vector<float> w{1, 0, 0, 1, 2, 0, 0, 2, 3, 0, 0, 3};+ // a[token][used] -- a distinct activation row per (token, expert) pair.+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8};+ std::vector<int32_t> ids{0, 1, 2, 0}; // tok0 uses experts {0,1}; tok1 uses {2,0}++ ov::Tensor ids_t(ov::element::i32, ov::Shape{1, 1, (size_t)n_tokens, (size_t)n_used});+ std::copy(ids.begin(), ids.end(), ids_t.data<int32_t>());+ auto out = run_on_cpu(model,+ {{"w", make_f32_tensor({1, (size_t)n_expert, (size_t)m, (size_t)k}, w)},+ {"a", make_f32_tensor({1, (size_t)n_tokens, (size_t)n_used, (size_t)k}, a)},+ {"ids", ids_t}});++ // out[token][used][row] = dot(expert(ids[token][used]).row, a[token][used])+ // tok0: e0 . [1,2] = [1,2]; e1 . [3,4] = [6,8]+ // tok1: e2 . [5,6] = [15,18]; e0 . [7,8] = [7,8]+ std::vector<float> expected{1, 2, 6, 8, 15, 18, 7, 8};+ expect_near(out, expected, 1e-4f);+}++// MulMatId over an empty token axis. Every non-final chunk of a chunked prefill produces no logits, so+// its inp_out_ids gather leaves the last layer's activations with 0 rows; that empty extent must flow+// through to an empty result rather than being broadcast up to n_used (which OpenVINO rejects).+TEST(GGUFOps, MulMatIdEmptyTokens) {+ const int64_t n_expert = 3, m = 2, k = 2, n_used = 2;+ auto model = SingleOpBuilder()+ .op("GGML_OP_MUL_MAT_ID")+ .input("w", ov::element::f32, {1, n_expert, m, k})+ .input("a", ov::element::f32, {1, ov::Dimension::dynamic(), 1, k})+ .input("ids", ov::element::i32, {1, 1, ov::Dimension::dynamic(), n_used})+ .output("out", ov::element::f32, {1, ov::Dimension::dynamic(), n_used, m})+ .build();++ std::vector<float> w{1, 0, 0, 1, 2, 0, 0, 2, 3, 0, 0, 3};+ auto out = run_on_cpu(model,+ {{"w", make_f32_tensor({1, (size_t)n_expert, (size_t)m, (size_t)k}, w)},+ {"a", ov::Tensor(ov::element::f32, ov::Shape{1, 0, 1, (size_t)k})},+ {"ids", ov::Tensor(ov::element::i32, ov::Shape{1, 1, 0, (size_t)n_used})}});++ EXPECT_EQ(out.get_shape(), (ov::Shape{1, 0, (size_t)n_used, (size_t)m}));+}+// GetRows batched gather for MoE routing weights: data [1, n_tok, n_expert, 1], indices// [1,1,n_tok,n_used] -> per-token gather of n_used of the n_expert probs -> [1, n_tok, n_used, 1].TEST(GGUFOps, GetRowsMoeWeights) {@@ -634,6 +690,38 @@ TEST(GGUFOps, SsmConv) {expect_near(out, expected, 1e-4f);}+// SsmConv at the real qwen3.5/qwen3-next conv dims (d_conv=4, n_t=5, d_inner=3): the size-2/3+// SsmConv above collapses the token axis (n_t=2) and the kernel (d_conv=3); this exercises the+// model's actual window length with n_t>1 across multiple channels. Reference comes from the+// standalone ggml-CPU oracle (ssm_conv_oracle.c), not a hand-derived conv, so it pins the OV+// GroupConvolution + transpose/reshape layout against ggml's own kernel.+TEST(GGUFOps, SsmConvRealDims) {+ const size_t d_conv = 4, d_inner = 3, n_t = 5, ncs = n_t + d_conv - 1; // ncs=8+ auto model = SingleOpBuilder()+ .op("GGML_OP_SSM_CONV")+ .input("sx", ov::element::f32, {1, 1, d_inner, ncs})+ .input("c", ov::element::f32, {1, 1, d_inner, d_conv})+ .output("out", ov::element::f32, {1, 1, n_t, d_inner})+ .build();++ // sx channel-major [d_inner][ncs]: ch0 = 1..8, ch1 = 11..18, ch2 = 21..28+ std::vector<float> sx(d_inner * ncs);+ for (size_t ch = 0; ch < d_inner; ++ch)+ for (size_t j = 0; j < ncs; ++j)+ sx[ch * ncs + j] = static_cast<float>(ch * 10 + j + 1);+ // c per-channel [d_inner][d_conv]: ch0 weighted, ch1 picks window-start, ch2 picks window-end+ std::vector<float> c{0.5f, 0.25f, 0.125f, 0.0625f, 1, 0, 0, 0, 0, 0, 0, 1};+ auto out = run_on_cpu(model,+ {{"sx", make_f32_tensor({1, 1, d_inner, ncs}, sx)},+ {"c", make_f32_tensor({1, 1, d_inner, d_conv}, c)}});++ // ggml-CPU oracle (ssm_conv_oracle.c) flat output, layout [n_t][d_inner]:+ // row t = [ch0_t, ch1_t, ch2_t]. ch1 = sx window-start (11..15), ch2 = window-end (24..28).+ std::vector<float> expected{+ 1.625f, 11, 24, 2.5625f, 12, 25, 3.5f, 13, 26, 4.4375f, 14, 27, 5.375f, 15, 28};+ expect_near(out, expected, 1e-4f);+}+// Softmax with attention sinks (gpt-oss): a 2nd input shaped [1,1,1,n_head] is a per-head sink,// NOT a mask. It is appended as one hidden logit column, softmax runs over the widened last axis,// and the sink column is dropped -- so each row sums to (1 - sink_weight) instead of 1.@@ -862,6 +950,136 @@ TEST(GGUFOps, RopeNeoxFullRotary) {expect_near(out, expected, 1e-4f);}+// IMROPE (interleaved M-RoPE, qwen3.5 / qwen3vl) at qwen3.5's exact config: head_dim=64,+// n_dims=64, sections={11,11,10,0}, freq_base=1e7. Text decode uses the SAME position id for all+// four mrope sections, so IMROPE reduces to theta[j]=pos*theta_scale^j with split-halves pairing+// — identical to NEOX. This guards the frontend's imrope path (make_sin_cos j%3 gather + rope.cpp+// TYPE_IMROPE split/sub/add/concat) against ggml's own kernel. Expected values come from the+// standalone ggml-CPU oracle imrope_oracle.c (ggml_rope_multi, GGML_ROPE_TYPE_IMROPE).+TEST(GGUFOps, ImropeTextRealDims) {+ const int64_t head_dim = 64, T = 2, n_head = 1;+ RopeConfig cfg;+ cfg.n_dims = static_cast<int>(head_dim);+ cfg.freq_base = 1e7f;+ cfg.freq_scale = 1.0f;+ cfg.ext_factor = 0.0f;+ cfg.attn_factor = 1.0f;+ cfg.beta_fast = 32.0f;+ cfg.beta_slow = 1.0f;+ cfg.n_ctx_orig = 262144;+ const int op_case = (2 << 16); // high 16 bits = TYPE_IMROPE++ // pos: mrope needs 4*T ints, section-major [t-sect | h-sect | w-sect | e-sect]; text uses the+ // same position per section, so token t -> pos t in every section: {0,1, 0,1, 0,1, 0,1}.+ auto model = SingleOpBuilder()+ .op("GGML_OP_ROPE")+ .input("data", ov::element::f32, {1, T, n_head, head_dim})+ .input("pos", ov::element::i32, {1, 1, 1, 4 * T})+ .output("out", ov::element::f32, {1, T, n_head, head_dim})+ .op_case(op_case)+ .attr<RopeConfig>("rope_config", cfg)+ .build();++ std::vector<float> data(T * head_dim);+ for (int t = 0; t < T; ++t)+ for (int e = 0; e < head_dim; ++e)+ data[t * head_dim + e] = static_cast<float>(t + 1) + 0.01f * e;++ ov::Tensor pos_t(ov::element::i32, ov::Shape{1, 1, 1, (size_t)(4 * T)});+ int32_t pos_vals[8] = {0, 1, 0, 1, 0, 1, 0, 1};+ std::copy(pos_vals, pos_vals + 8, pos_t.data<int32_t>());++ auto out = run_on_cpu(model,+ {{"data", make_f32_tensor({1, (size_t)T, (size_t)n_head, (size_t)head_dim}, data)},+ {"pos", pos_t}});++ // From imrope_oracle.c (ggml-CPU IMROPE), layout [T][head_dim].+ std::vector<float> expected{+ // token 0 (pos 0) — identity+ 1.000000f, 1.010000f, 1.020000f, 1.030000f, 1.040000f, 1.050000f, 1.060000f, 1.070000f,+ 1.080000f, 1.090000f, 1.100000f, 1.110000f, 1.120000f, 1.130000f, 1.140000f, 1.150000f,+ 1.160000f, 1.170000f, 1.180000f, 1.190000f, 1.200000f, 1.210000f, 1.220000f, 1.230000f,+ 1.240000f, 1.250000f, 1.260000f, 1.270000f, 1.280000f, 1.290000f, 1.300000f, 1.310000f,+ 1.320000f, 1.330000f, 1.340000f, 1.350000f, 1.360000f, 1.370000f, 1.380000f, 1.390000f,+ 1.400000f, 1.410000f, 1.420000f, 1.430000f, 1.440000f, 1.450000f, 1.460000f, 1.470000f,+ 1.480000f, 1.490000f, 1.500000f, 1.510000f, 1.520000f, 1.530000f, 1.540000f, 1.550000f,+ 1.560000f, 1.570000f, 1.580000f, 1.590000f, 1.600000f, 1.610000f, 1.620000f, 1.630000f,+ // token 1 (pos 1)+ -0.871608f, 0.330166f, 1.051162f, 1.466389f, 1.708109f, 1.852569f, 1.941705f, 1.998783f,+ 2.036994f, 2.063982f, 2.084241f, 2.100448f, 2.114208f, 2.126487f, 2.137869f, 2.148707f,+ 2.159216f, 2.169524f, 2.179711f, 2.189825f, 2.199894f, 2.209936f, 2.219961f, 2.229976f,+ 2.239986f, 2.249991f, 2.259995f, 2.269997f, 2.279998f, 2.289999f, 2.299999f, 2.309999f,+ 2.936443f, 3.059410f, 2.907070f, 2.737353f, 2.610280f, 2.527328f, 2.477454f, 2.449871f,+ 2.436607f, 2.432320f, 2.433586f, 2.438262f, 2.445020f, 2.453050f, 2.461852f, 2.471125f,+ 2.480683f, 2.490415f, 2.500252f, 2.510153f, 2.520093f, 2.530056f, 2.540034f, 2.550021f,+ 2.560013f, 2.570008f, 2.580004f, 2.590003f, 2.600002f, 2.610001f, 2.620001f, 2.630001f};++ expect_near(out, expected, 1e-4f);+}++// IMROPE with PARTIAL rotary (n_dims < head_dim) at qwen3.5's real full-attention config:+// head_dim=256 but rope.dimension_count=64. Only the first 64 dims of every head are rotated; the+// remaining 192 pass through UNCHANGED. The head_dim==n_dims test above never exercised this, and+// the frontend used to rotate the whole head (splitting all 256 dims) -- corrupting every+// full-attention layer and, downstream, every token. Expected from imrope_partial_oracle.c+// (ggml_rope_multi, GGML_ROPE_TYPE_IMROPE, n_dims=64, head_dim=256): token 0 is identity, token 1's+// first 64 dims are the same rotated values as ImropeTextRealDims and its tail is the raw ramp.+TEST(GGUFOps, ImropePartialRotary) {+ const int64_t head_dim = 256, T = 2, n_head = 1;+ const int n_dims = 64; // partial rotary+ RopeConfig cfg;+ cfg.n_dims = n_dims;+ cfg.freq_base = 1e7f;+ cfg.freq_scale = 1.0f;+ cfg.ext_factor = 0.0f;+ cfg.attn_factor = 1.0f;+ cfg.beta_fast = 32.0f;+ cfg.beta_slow = 1.0f;+ cfg.n_ctx_orig = 262144;+ const int op_case = (2 << 16); // TYPE_IMROPE++ auto model = SingleOpBuilder()+ .op("GGML_OP_ROPE")+ .input("data", ov::element::f32, {1, T, n_head, head_dim})+ .input("pos", ov::element::i32, {1, 1, 1, 4 * T})+ .output("out", ov::element::f32, {1, T, n_head, head_dim})+ .op_case(op_case)+ .attr<RopeConfig>("rope_config", cfg)+ .build();++ std::vector<float> data(T * head_dim);+ for (int t = 0; t < T; ++t)+ for (int e = 0; e < head_dim; ++e)+ data[t * head_dim + e] = static_cast<float>(t + 1) + 0.01f * e;++ ov::Tensor pos_t(ov::element::i32, ov::Shape{1, 1, 1, (size_t)(4 * T)});+ int32_t pos_vals[8] = {0, 1, 0, 1, 0, 1, 0, 1};+ std::copy(pos_vals, pos_vals + 8, pos_t.data<int32_t>());++ auto out = run_on_cpu(model,+ {{"data", make_f32_tensor({1, (size_t)T, (size_t)n_head, (size_t)head_dim}, data)},+ {"pos", pos_t}});++ // token 1's first 64 rotated dims (from imrope_partial_oracle.c; identical to ImropeTextRealDims).+ const float rot1[64] = {+ -0.871608f, 0.330166f, 1.051162f, 1.466389f, 1.708109f, 1.852569f, 1.941705f, 1.998783f,+ 2.036994f, 2.063982f, 2.084241f, 2.100448f, 2.114208f, 2.126487f, 2.137869f, 2.148707f,+ 2.159216f, 2.169524f, 2.179711f, 2.189825f, 2.199894f, 2.209936f, 2.219961f, 2.229976f,+ 2.239986f, 2.249991f, 2.259995f, 2.269997f, 2.279998f, 2.289999f, 2.299999f, 2.309999f,+ 2.936443f, 3.059410f, 2.907070f, 2.737353f, 2.610280f, 2.527328f, 2.477454f, 2.449871f,+ 2.436607f, 2.432320f, 2.433586f, 2.438262f, 2.445020f, 2.453050f, 2.461852f, 2.471125f,+ 2.480683f, 2.490415f, 2.500252f, 2.510153f, 2.520093f, 2.530056f, 2.540034f, 2.550021f,+ 2.560013f, 2.570008f, 2.580004f, 2.590003f, 2.600002f, 2.610001f, 2.620001f, 2.630001f};++ std::vector<float> expected(T * head_dim);+ for (int e = 0; e < head_dim; ++e)+ expected[e] = 1.0f + 0.01f * e; // token 0: pos 0 -> identity+ for (int e = 0; e < head_dim; ++e)+ expected[head_dim + e] = (e < n_dims) ? rot1[e] : (2.0f + 0.01f * e); // token 1: rotate head, pass tail++ expect_near(out, expected, 1e-4f);+}+// The f4e2m1 nibble -> value lookup used by the packed MXFP4 dequant (mirrors mul_mat_id.cpp).static const float kF4E2M1[16] = {0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 3.0f, 4.0f, 6.0f,-0.0f, -0.5f, -1.0f, -1.5f, -2.0f, -3.0f, -4.0f, -6.0f};@@ -1018,10 +1236,12 @@ TEST(GGUFOps, FlashAttnExt) {expect_near(out, expected, 2e-2f); // fp16 SDPA}-// GatedDeltaNet (qwen3next linear attention) as a recurrent scan. Minimal scalar case-// B=H=S=1, T=2 exercises the full per-token gated delta update + output packing-// [attn_t0, attn_t1, final_state].-TEST(GGUFOps, GatedDeltaNet) {+// GatedDeltaNet, reference (Loop) path. With head size S=1 the gate last-dim equals S_v, so this is+// the per-key-dimension gating case (kda) that the fused op does not support and which therefore+// lowers to the serializable Loop scan. Minimal scalar case B=H=S=1, T=2 exercises the full+// per-token gated delta update + output packing [attn_t0, attn_t1, final_state]. This model stays+// serializable, so we also assert no internal GatedDeltaNet op is present.+TEST(GGUFOps, GatedDeltaNetRefFallback) {const int64_t B = 1, T = 2, H = 1, S = 1;auto shp = ov::PartialShape{B, T, H, S};auto model = SingleOpBuilder()@@ -1060,6 +1280,373 @@ TEST(GGUFOps, GatedDeltaNet) {}expected.push_back(state); // final state, packed after the attn outputsexpect_near(out, expected, 1e-4f);++ // Fallback path is core-op only: no internal fused op, and it uses a Loop scan.+ bool has_fused = false, has_loop = false;+ for (const auto& node : model->get_ordered_ops()) {+ if (std::string(node->get_type_name()) == std::string("GatedDeltaNet"))+ has_fused = true;+ if (std::string(node->get_type_name()) == std::string("Loop"))+ has_loop = true;+ }+ EXPECT_FALSE(has_fused);+ EXPECT_TRUE(has_loop);+}++// K > 1 (multiple recurrent-state snapshot slots, speculative-decode rollback) reserves K state+// blocks in the ggml output while both frontend paths pack one, so conversion must fail loudly+// rather than emit a graph whose snapshot views read the wrong block.+TEST(GGUFOps, GatedDeltaNetMultipleSnapshotSlotsRejected) {+ const int64_t B = 1, T = 2, H = 1, D = 2, K = 2;+ auto qkv_shp = ov::PartialShape{B, T, H, D};+ auto gate_shp = ov::PartialShape{B, T, H, 1};+ auto builder = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .attr<int64_t>("gdn_state_slots", K)+ .input("q", ov::element::f32, qkv_shp)+ .input("k", ov::element::f32, qkv_shp)+ .input("v", ov::element::f32, qkv_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, {B, H, D, D})+ .output("out", ov::element::f32, {1, 1, (T + K * D) * B, D * H});+ EXPECT_THROW(builder.build(), ov::Exception);+}++// GatedDeltaNet, fused-op path. A scalar gate (gate last-dim 1 with head size Dv>1) selects the+// fused ov::op::internal::GatedDeltaNet op instead of the Loop scan. B=H=1, T=2, D=Dv=2. We assert+// the fused op is actually emitted and that its result matches the core reference recurrence.+// NOTE: a model on this path contains an internal op and is therefore NOT IR-serializable+// (see src/frontends/gguf/docs/internal_ops.md).+TEST(GGUFOps, GatedDeltaNetFused) {+ const int64_t B = 1, T = 2, H = 1, D = 2; // head size D = Dv = 2, scalar gate+ auto qkv_shp = ov::PartialShape{B, T, H, D};+ auto gate_shp = ov::PartialShape{B, T, H, 1}; // scalar gate -> fused path+ auto state_shp = ov::PartialShape{B, H, D, D}; // ggml [B, H_v, value_dim, key_dim]+ auto model = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .input("q", ov::element::f32, qkv_shp)+ .input("k", ov::element::f32, qkv_shp)+ .input("v", ov::element::f32, qkv_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, state_shp)+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H})+ .build();++ // Assert the fused internal op is present (this is the whole point of this path).+ bool has_fused = false;+ for (const auto& node : model->get_ordered_ops()) {+ if (std::string(node->get_type_name()) == std::string("GatedDeltaNet"))+ has_fused = true;+ }+ ASSERT_TRUE(has_fused) << "fused ov::op::internal::GatedDeltaNet was not emitted";++ // Per-token, per-dim inputs (row-major over [T, D]).+ std::vector<float> q{1, 0, 0, 1}, k{1, 0, 0, 1}, v{1, 2, 3, 4};+ std::vector<float> g{0.0f, 0.0f}, beta{1.0f, 1.0f}; // exp(g)=1, full update+ std::vector<float> state0(D * D, 0.0f);+ auto out = run_on_cpu(model,+ {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, q)},+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, k)},+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, v)},+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, g)},+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, beta)},+ {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}});++ // Reference: mirror ov::reference::gated_delta_net for B=H=1. state[d][dv]; q scaled by+ // 1/sqrt(D). For each token: decay state by exp(g); h_k[dv] = sum_d state[d][dv]*k[d];+ // update state[d][dv] += k[d]*(v[dv]-h_k[dv])*beta; attn[dv] = sum_d state[d][dv]*q_scaled[d].+ const float scale = 1.0f / std::sqrt((float)D);+ std::vector<std::vector<float>> st(D, std::vector<float>(D, 0.0f)); // st[d][dv]+ std::vector<float> attn; // [T*D]+ for (int t = 0; t < T; ++t) {+ std::vector<float> qs(D), kv(D);+ for (int d = 0; d < D; ++d) {+ qs[d] = q[t * D + d] * scale;+ kv[d] = k[t * D + d];+ }+ float gexp = std::exp(g[t]);+ for (int d = 0; d < D; ++d)+ for (int dv = 0; dv < D; ++dv)+ st[d][dv] *= gexp;+ for (int dv = 0; dv < D; ++dv) {+ float h_k = 0.0f;+ for (int d = 0; d < D; ++d)+ h_k += st[d][dv] * kv[d];+ float upd = (v[t * D + dv] - h_k) * beta[t];+ for (int d = 0; d < D; ++d)+ st[d][dv] += kv[d] * upd;+ }+ for (int dv = 0; dv < D; ++dv) {+ float a = 0.0f;+ for (int d = 0; d < D; ++d)+ a += st[d][dv] * qs[d];+ attn.push_back(a);+ }+ }+ // Packed output layout: [attn (T*D) | final_state (D*D)] flattened. The frontend transposes the+ // op's [key_dim, value_dim] state back to ggml's [value_dim, key_dim] before flattening, so the+ // state is packed value-dim outer, key-dim inner.+ std::vector<float> expected = attn;+ for (int dv = 0; dv < D; ++dv)+ for (int d = 0; d < D; ++d)+ expected.push_back(st[d][dv]);+ expect_near(out, expected, 1e-4f);+}++// GatedDeltaNet, fused-op path with MULTIPLE HEADS (H=2). qwen3-next real dims are H=32; the+// single-head tests above (H=1) collapse the head axis so they never exercise the per-head packing+// of attn/state into the flat output. This reproduces the multi-head case: for B=1, T tokens and+// H heads of size D, the packed output is [1,1,(T+D), D*H] -- attention on the first T rows (each+// row = H heads x D values, head-outer) and the H final states on the last D rows. Independent+// per-head recurrences let a head-axis packing/transpose bug surface as a mismatch.+TEST(GGUFOps, GatedDeltaNetFusedMultiHead) {+ const int64_t B = 1, T = 2, H = 2, D = 2; // scalar gate (last-dim 1), head size D>1 -> fused path+ auto qkv_shp = ov::PartialShape{B, T, H, D};+ auto gate_shp = ov::PartialShape{B, T, H, 1};+ auto state_shp = ov::PartialShape{B, H, D, D}; // ggml [B, H_v, value_dim, key_dim]+ auto model = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .input("q", ov::element::f32, qkv_shp)+ .input("k", ov::element::f32, qkv_shp)+ .input("v", ov::element::f32, qkv_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, state_shp)+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H})+ .build();++ bool has_fused = false;+ for (const auto& node : model->get_ordered_ops())+ if (std::string(node->get_type_name()) == std::string("GatedDeltaNet"))+ has_fused = true;+ ASSERT_TRUE(has_fused) << "fused ov::op::internal::GatedDeltaNet was not emitted";++ // Distinct per-head, per-token, per-dim inputs (row-major over [T, H, D]).+ std::vector<float> q{1, 0, 0, 1, /*t1*/ 0, 1, 1, 0};+ std::vector<float> k{1, 0, 0, 1, /*t1*/ 1, 1, 0, 1};+ std::vector<float> v{1, 2, 3, 4, /*t1*/ 5, 6, 7, 8};+ std::vector<float> g{0.0f, 0.0f, 0.0f, 0.0f}; // exp(g)=1+ std::vector<float> beta{1.0f, 1.0f, 1.0f, 1.0f}; // full update+ std::vector<float> state0(H * D * D, 0.0f);+ auto idx = [&](int t, int h, int d) { return (t * H + h) * D + d; }; // [T,H,D]+ auto gidx = [&](int t, int h) { return t * H + h; }; // [T,H]++ auto out = run_on_cpu(model,+ {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, q)},+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, k)},+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, v)},+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, g)},+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, beta)},+ {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}});++ (void) idx;+ (void) gidx;+ // Authoritative reference: the flat output of ggml's own CPU GGML_OP_GATED_DELTA_NET kernel for+ // these exact inputs (generated by the standalone oracle in+ // src/frontends/gguf/tests/gdn_oracle.c, run against llama.cpp's libggml-cpu). Using ggml's+ // kernel -- rather than a hand-derived recurrence -- avoids baking the frontend's own layout+ // assumptions into the expectation. The packed layout is [S_v*H, T + K*S_v] flattened: T=2+ // attention rows (width S_v*H, head-outer/value-inner) then K*S_v=2 final-state rows. Note the+ // state is packed head-outer/value-dim/key-dim -- a multi-head order the H=1 tests can't probe.+ std::vector<float> expected{+ // attention, token 0 and token 1 (each row: head0[sv0,sv1], head1[sv0,sv1])+ 0.707107f, 1.414214f, 2.121320f, 2.828427f,+ 2.828427f, 2.828427f, 0.000000f, 0.000000f,+ // final state, two rows (head-outer): head0 [dv0(d0,d1), dv1(d0,d1)], head1 [...]+ 5.000000f, 4.000000f, 6.000000f, 4.000000f,+ 0.000000f, 7.000000f, 0.000000f, 8.000000f};+ expect_near(out, expected, 1e-4f);+}++// GatedDeltaNet, DECOMPOSED (Loop reference) path with MULTIPLE HEADS. Same inputs and same ggml-CPU+// authoritative reference as GatedDeltaNetFusedMultiHead, but forces the serializable Loop scan+// (force_ref attribute) even for the scalar-gate case. Both paths must match ggml; running the real+// model showed they produce DIFFERENT wrong outputs, so at least one mishandles the head axis. This+// isolates which. The Loop path is the one used when a model must stay IR-serializable, so its+// multi-head correctness matters independently of the fused op.+TEST(GGUFOps, GatedDeltaNetRefMultiHead) {+ const int64_t B = 1, T = 2, H = 2, D = 2;+ auto qkv_shp = ov::PartialShape{B, T, H, D};+ auto gate_shp = ov::PartialShape{B, T, H, 1};+ auto state_shp = ov::PartialShape{B, H, D, D};++ auto model = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .attr<bool>("force_ref", true)+ .input("q", ov::element::f32, qkv_shp)+ .input("k", ov::element::f32, qkv_shp)+ .input("v", ov::element::f32, qkv_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, state_shp)+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H})+ .build();++ // This path must be the core-op Loop scan, not the fused internal op.+ bool has_fused = false, has_loop = false;+ for (const auto& node : model->get_ordered_ops()) {+ const std::string tn = node->get_type_name();+ if (tn == "GatedDeltaNet")+ has_fused = true;+ if (tn == "Loop")+ has_loop = true;+ }+ ASSERT_FALSE(has_fused) << "expected the decomposed path, but the fused op was emitted";+ ASSERT_TRUE(has_loop) << "expected the Loop-scan decomposition";++ std::vector<float> q{1, 0, 0, 1, 0, 1, 1, 0};+ std::vector<float> k{1, 0, 0, 1, 1, 1, 0, 1};+ std::vector<float> v{1, 2, 3, 4, 5, 6, 7, 8};+ std::vector<float> g{0.0f, 0.0f, 0.0f, 0.0f};+ std::vector<float> beta{1.0f, 1.0f, 1.0f, 1.0f};+ std::vector<float> state0(H * D * D, 0.0f);++ auto out = run_on_cpu(model,+ {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, q)},+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, k)},+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, v)},+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, g)},+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, beta)},+ {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}});++ // Same ggml-CPU oracle values as the fused multi-head test.+ std::vector<float> expected{+ 0.707107f, 1.414214f, 2.121320f, 2.828427f,+ 2.828427f, 2.828427f, 0.000000f, 0.000000f,+ 5.000000f, 4.000000f, 6.000000f, 4.000000f,+ 0.000000f, 7.000000f, 0.000000f, 8.000000f};+ expect_near(out, expected, 1e-4f);+}++// GatedDeltaNet with GQA (H_v != H_k) -- the head-mapping path that EVERY existing GDN test misses.+// Real qwen3.5 has num_v_heads=32, num_k_heads=16 (ratio 2): each V head pairs with Q/K head+// (v_head % H_k). All the tests above use H_k==H_v, so the frontend's GQA repeat (fused: Tile;+// ref: Broadcast) was never checked against ggml. A wrong pairing (grouped vs interleaved, or+// wrong modulus) computes every non-first head against the wrong key -- a sharp, per-token error+// that a sum-based cross-backend metric smears into apparent "drift". This uses H_v=4, H_k=2 with+// distinct per-head inputs; expected = ggml-CPU oracle gdn_gqa_oracle.c.+static const std::vector<float> kGdnGqaExpected{+ // attention rows (T=2), each row = 4 v-heads x D=2, head-outer/value-inner+ 0.707107f, 1.414214f, 2.121320f, 2.828427f, 3.535534f, 4.242640f, 4.949748f, 5.656854f,+ 5.656854f, 5.656854f, 0.000000f, 0.000000f, 5.656854f, 5.656854f, 0.000000f, 0.000000f,+ // final-state rows (D=2), head-outer: each head [dv0(d0,d1), dv1(d0,d1)]+ 9.000000f, 8.000000f, 10.000000f, 8.000000f, 0.000000f, 11.000000f, 0.000000f, 12.000000f,+ 13.000000f, 8.000000f, 14.000000f, 8.000000f, 0.000000f, 15.000000f, 0.000000f, 16.000000f};++static void run_gdn_gqa(bool force_ref) {+ const int64_t B = 1, T = 2, H_v = 4, H_k = 2, D = 2;+ auto q_shp = ov::PartialShape{B, T, H_k, D};+ auto v_shp = ov::PartialShape{B, T, H_v, D};+ auto gate_shp = ov::PartialShape{B, T, H_v, 1};+ auto state_shp = ov::PartialShape{B, H_v, D, D}; // ggml [B, H_v, value_dim, key_dim]++ auto model = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .attr<bool>("force_ref", force_ref)+ .input("q", ov::element::f32, q_shp)+ .input("k", ov::element::f32, q_shp)+ .input("v", ov::element::f32, v_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, state_shp)+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H_v})+ .build();++ // q/k: [T, H_k, D]; v: [T, H_v, D] -- distinct per head so the GQA pairing is observable.+ std::vector<float> q{1, 0, 0, 1, 0, 1, 1, 0};+ std::vector<float> k{1, 0, 0, 1, 1, 1, 0, 1};+ std::vector<float> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};+ std::vector<float> g(H_v * T, 0.0f);+ std::vector<float> beta(H_v * T, 1.0f);+ std::vector<float> state0(H_v * D * D, 0.0f);++ auto out = run_on_cpu(model,+ {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H_k, (size_t)D}, q)},+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H_k, (size_t)D}, k)},+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H_v, (size_t)D}, v)},+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H_v, 1}, g)},+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H_v, 1}, beta)},+ {"state", make_f32_tensor({(size_t)B, (size_t)H_v, (size_t)D, (size_t)D}, state0)}});+ expect_near(out, kGdnGqaExpected, 1e-4f);+}++TEST(GGUFOps, GatedDeltaNetFusedGQA) {+ run_gdn_gqa(/*force_ref=*/false);+}++TEST(GGUFOps, GatedDeltaNetRefGQA) {+ run_gdn_gqa(/*force_ref=*/true);+}++// GatedDeltaNet at T != D (T=3 tokens, D=4 head-size, H=2). The multi-head tests above use T==D==2,+// which makes the packed-attention rows (T of them) and the packed-state rows (D of them) the same+// width AND makes a token<->value-axis transpose in the output flattening invisible. Real qwen3-next+// dims are T=5, D=128 -- very much T != D -- and forcing the fused vs decomposed path on the real+// model produced DIFFERENT wrong tokens, which is the signature of exactly such a collapsed-axis bug.+// This case (T != D) distinguishes them. Oracle values from gdn_oracle2 (ggml CPU, same kernel).+// Packed output is [D*H, T + D]: T=3 attention rows (width D*H, head-outer/value-inner) then D=4+// final-state rows.+namespace {+// ggml-CPU oracle output for the T=3,H=2,D=4 inputs below (row-major, 7 rows x 8 cols).+const std::vector<float> kGdnTneqDExpected{+ 0.037500f, 0.075000f, 0.112500f, 0.150000f, 0.885000f, 1.062000f, 1.239000f, 1.416000f,+ 2.495686f, 2.863373f, 3.231059f, 3.598745f, 7.552056f, 8.348866f, 9.145678f, 9.942489f,+ 10.676509f, 11.612682f, 12.548857f, 13.485029f, 18.103098f, 19.490808f, 20.878521f, 22.266232f,+ 1.785152f, 2.487126f, 3.189099f, 3.891073f, 1.928201f, 2.700328f, 3.472456f, 4.244583f,+ 2.071249f, 2.913531f, 3.755813f, 4.598094f, 2.214298f, 3.126734f, 4.039169f, 4.951605f,+ 7.141428f, 4.162388f, 2.434744f, 2.688347f, 7.614682f, 4.536554f, 2.686254f, 2.846659f,+ 8.087935f, 4.910720f, 2.937764f, 3.004971f, 8.561190f, 5.284886f, 3.189275f, 3.163283f};++// Inputs (row-major [T,H,D] for q/k/v, [T,H] for g/beta), matching gdn_oracle2.c.+const std::vector<float> kGdnTneqDq{+ 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f,+ 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f};+const std::vector<float> kGdnTneqDk{+ 0.05f, 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.05f, 0.10f, 0.15f, 0.20f, 0.25f,+ 0.30f, 0.35f, 0.05f, 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.05f, 0.10f, 0.15f};+const std::vector<float> kGdnTneqDv{+ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f,+ 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f};+const std::vector<float> kGdnTneqDg{0.0f, -0.1f, -0.2f, 0.0f, -0.1f, -0.2f};+const std::vector<float> kGdnTneqDbeta{0.5f, 0.6f, 0.7f, 0.8f, 0.5f, 0.6f};++ov::Tensor run_gdn_tneqd(bool force_ref) {+ const int64_t B = 1, T = 3, H = 2, D = 4;+ auto qkv_shp = ov::PartialShape{B, T, H, D};+ auto gate_shp = ov::PartialShape{B, T, H, 1};+ auto state_shp = ov::PartialShape{B, H, D, D};+ auto model = SingleOpBuilder()+ .op("GGML_OP_GATED_DELTA_NET")+ .attr<bool>("force_ref", force_ref)+ .input("q", ov::element::f32, qkv_shp)+ .input("k", ov::element::f32, qkv_shp)+ .input("v", ov::element::f32, qkv_shp)+ .input("g", ov::element::f32, gate_shp)+ .input("beta", ov::element::f32, gate_shp)+ .input("state", ov::element::f32, state_shp)+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H})+ .build();+ std::vector<float> state0((size_t)(H * D * D), 0.0f);+ return run_on_cpu(model,+ {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDq)},+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDk)},+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDv)},+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDg)},+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDbeta)},+ {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}});+}+} // namespace++TEST(GGUFOps, GatedDeltaNetFusedTneqD) {+ auto out = run_gdn_tneqd(/*force_ref=*/false);+ expect_near(out, kGdnTneqDExpected, 1e-3f);+}++TEST(GGUFOps, GatedDeltaNetRefTneqD) {+ auto out = run_gdn_tneqd(/*force_ref=*/true);+ expect_near(out, kGdnTneqDExpected, 1e-3f);}// Im2col 1D: unfold a width-KW sliding window over the innermost image axis. For IC=1, stride=1,@@ -1171,4 +1758,254 @@ TEST(GGUFOps, Add1) {expect_near(out, expected);}+// Cumsum: prefix sum along ggml dim 0 = the last OV axis. Each row accumulates independently.+TEST(GGUFOps, Cumsum) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_CUMSUM")+ .input("x", ov::element::f32, {2, 4})+ .output("out", ov::element::f32, {2, 4})+ .build();++ std::vector<float> x{1, 2, 3, 4, 5, 6, 7, 8};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 4}, x)}});++ std::vector<float> expected{1, 3, 6, 10, 5, 11, 18, 26};+ expect_near(out, expected);+}++// Sqr: element-wise square.+TEST(GGUFOps, Sqr) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_SQR")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> x{1, -2, 3, -4, 0.5f, -0.25f};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size());+ for (size_t i = 0; i < x.size(); ++i)+ expected[i] = x[i] * x[i];+ expect_near(out, expected);+}++// Sqrt: element-wise square root (non-negative inputs).+TEST(GGUFOps, Sqrt) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_SQRT")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> x{0.0f, 1.0f, 4.0f, 9.0f, 2.0f, 0.25f};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size());+ for (size_t i = 0; i < x.size(); ++i)+ expected[i] = std::sqrt(x[i]);+ expect_near(out, expected);+}++// Diag: a [.,.,1,n] vector becomes a [.,.,n,n] diagonal matrix (row axis = OV axis 2).+TEST(GGUFOps, Diag) {+ const int64_t n = 3;+ auto model = SingleOpBuilder()+ .op("GGML_OP_DIAG")+ .input("x", ov::element::f32, {1, 1, 1, n})+ .output("out", ov::element::f32, {1, 1, n, n})+ .build();++ std::vector<float> x{2, 5, 7};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 1, 1, static_cast<size_t>(n)}, x)}});++ std::vector<float> expected(n * n, 0.0f);+ for (int64_t i = 0; i < n; ++i)+ expected[i * n + i] = x[i];+ expect_near(out, expected);+}++// Unary Sigmoid: 1 / (1 + exp(-x)) via the 1to1 template.+TEST(GGUFOps, UnarySigmoid) {+ auto model = SingleOpBuilder()+ .op("GGML_UNARY_OP_SIGMOID")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> x{0.0f, 1.0f, -1.0f, 2.0f, -2.0f, 0.5f};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size());+ for (size_t i = 0; i < x.size(); ++i)+ expected[i] = 1.0f / (1.0f + std::exp(-x[i]));+ expect_near(out, expected);+}++// Unary Exp: element-wise exponential (moderate inputs to stay well inside f32 range).+TEST(GGUFOps, UnaryExp) {+ auto model = SingleOpBuilder()+ .op("GGML_UNARY_OP_EXP")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> x{0.0f, 1.0f, -1.0f, 2.0f, -2.0f, 0.5f};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size());+ for (size_t i = 0; i < x.size(); ++i)+ expected[i] = std::exp(x[i]);+ expect_near(out, expected);+}++// Unary Neg: element-wise negation.+TEST(GGUFOps, UnaryNeg) {+ auto model = SingleOpBuilder()+ .op("GGML_UNARY_OP_NEG")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> x{1, -2, 3, -4, 0.5f, -0.25f};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size());+ for (size_t i = 0; i < x.size(); ++i)+ expected[i] = -x[i];+ expect_near(out, expected);+}++// Tri: zero out elements outside a triangular region of a square matrix. tri_type selects the region:+// 0=UPPER_DIAG (col>=row), 1=UPPER (col>row), 2=LOWER_DIAG (col<=row), 3=LOWER (col<row).+TEST(GGUFOps, TriLowerDiag) {+ const int64_t n = 3;+ auto model = SingleOpBuilder()+ .op("GGML_OP_TRI")+ .input("x", ov::element::f32, {1, 1, n, n})+ .output("out", ov::element::f32, {1, 1, n, n})+ .attr<int>("tri_type", 2) // LOWER_DIAG: keep col <= row+ .build();++ // Row-major [n,n] with distinct values.+ std::vector<float> x{1, 2, 3, 4, 5, 6, 7, 8, 9};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 1, static_cast<size_t>(n), static_cast<size_t>(n)}, x)}});++ std::vector<float> expected(n * n, 0.0f);+ for (int64_t row = 0; row < n; ++row)+ for (int64_t col = 0; col < n; ++col)+ if (col <= row)+ expected[row * n + col] = x[row * n + col];+ expect_near(out, expected);+}++// Tri UPPER (strict): keep col > row.+TEST(GGUFOps, TriUpper) {+ const int64_t n = 3;+ auto model = SingleOpBuilder()+ .op("GGML_OP_TRI")+ .input("x", ov::element::f32, {1, 1, n, n})+ .output("out", ov::element::f32, {1, 1, n, n})+ .attr<int>("tri_type", 1) // UPPER: keep col > row+ .build();++ std::vector<float> x{1, 2, 3, 4, 5, 6, 7, 8, 9};+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 1, static_cast<size_t>(n), static_cast<size_t>(n)}, x)}});++ std::vector<float> expected(n * n, 0.0f);+ for (int64_t row = 0; row < n; ++row)+ for (int64_t col = 0; col < n; ++col)+ if (col > row)+ expected[row * n + col] = x[row * n + col];+ expect_near(out, expected);+}++// Fill: set every element to a constant scalar; output has the input's shape.+TEST(GGUFOps, Fill) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_FILL")+ .input("x", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .attr<float>("fill_value", -1.5f)+ .build();++ std::vector<float> x{1, 2, 3, 4, 5, 6}; // ignored; only shape matters+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3}, x)}});++ std::vector<float> expected(x.size(), -1.5f);+ expect_near(out, expected);+}++// Div: plain element-wise divide when both inputs already share a shape.+// (The silu(x)/x -> sigmoid(x) fold requires input 0 to be a Multiply(x,Sigmoid(x)) node, which a+// single-op decoder cannot express -- that path is exercised by the qwen2moe E2E test instead.)+TEST(GGUFOps, Div) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_DIV")+ .input("a", ov::element::f32, {2, 3})+ .input("b", ov::element::f32, {2, 3})+ .output("out", ov::element::f32, {2, 3})+ .build();++ std::vector<float> a{1, 2, 3, 4, 5, 6};+ std::vector<float> b{2, 4, 3, 8, 5, 12};+ auto out = run_on_cpu(model, {{"a", make_f32_tensor({2, 3}, a)}, {"b", make_f32_tensor({2, 3}, b)}});++ std::vector<float> expected(a.size());+ for (size_t i = 0; i < a.size(); ++i)+ expected[i] = a[i] / b[i];+ expect_near(out, expected);+}++// Div with ggml-style integer-repeat broadcast: the denominator [1,2] repeats to match [1,4].+TEST(GGUFOps, DivBroadcast) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_DIV")+ .input("a", ov::element::f32, {1, 4})+ .input("b", ov::element::f32, {1, 2})+ .output("out", ov::element::f32, {1, 4})+ .build();++ std::vector<float> a{2, 4, 6, 8};+ std::vector<float> b{2, 4}; // repeats to {2, 4, 2, 4}+ auto out = run_on_cpu(model, {{"a", make_f32_tensor({1, 4}, a)}, {"b", make_f32_tensor({1, 2}, b)}});++ expect_near(out, {1, 1, 3, 2});+}++// Div over an empty token axis, as produced by a non-final chunked-prefill chunk (see+// MulMatIdEmptyTokens). Both operands are empty, so the ggml-style repeat has nothing to repeat and+// must be skipped rather than computing a 0/0 repeat count.+TEST(GGUFOps, DivEmptyTokens) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_DIV")+ .input("a", ov::element::f32, {ov::Dimension::dynamic(), 4})+ .input("b", ov::element::f32, {ov::Dimension::dynamic(), 4})+ .output("out", ov::element::f32, {ov::Dimension::dynamic(), 4})+ .build();++ auto out = run_on_cpu(model, {{"a", ov::Tensor(ov::element::f32, ov::Shape{0, 4})},+ {"b", ov::Tensor(ov::element::f32, ov::Shape{0, 4})}});++ EXPECT_EQ(out.get_shape(), (ov::Shape{0, 4}));+}++// Set: write src into a contiguous region of dst (flattened) starting at set_offset_elems.+TEST(GGUFOps, Set) {+ auto model = SingleOpBuilder()+ .op("GGML_OP_SET")+ .input("dst", ov::element::f32, {2, 4})+ .input("src", ov::element::f32, {1, 2})+ .output("out", ov::element::f32, {2, 4})+ .attr<int64_t>("set_offset_elems", 2)+ .build();++ std::vector<float> dst(8, 1.0f);+ std::vector<float> src{10, 20};+ auto out = run_on_cpu(model, {{"dst", make_f32_tensor({2, 4}, dst)}, {"src", make_f32_tensor({1, 2}, src)}});++ // Flattened dst with src written at [2,3], reshaped back to [2,4].+ expect_near(out, {1, 1, 10, 20, 1, 1, 1, 1});+}+} // namespace