Skip to content

openvino: match the MoE fusion on the rank-3 stateful graph - #335

Merged
ravi9 merged 1 commit into
ravi9:dev_backend_openvinofrom
cavusmustafa:moe_fusion_rank3_stateful
Oct 5, 2026
Merged

ravi9 merged 1 commit into
ravi9:dev_backend_openvinofrom
cavusmustafa:moe_fusion_rank3_stateful

Conversation

@cavusmustafa

Copy link
Copy Markdown
Collaborator

FuseMoeCompressedFusedGateUp only matched the rank-4 graph, so under GGML_OPENVINO_STATEFUL_EXECUTION=1 gemma-4 26B-A4B silently ran the unfused MoE path: pp512 dropped from ~1600 t/s to 66 t/s while decode kept its gain.

The pattern did not bind at all (the callback was never invoked), because the rank-3 graph differs in node structure, not only in rank:

rank-4: GatherMatmul -> Transpose -> Unsqueeze -> [Convert] -> Slice
rank-3: GatherMatmul -> Convert -> Transpose -> Slice

The rank-3 graph never drops to a batch dim, so it has no Unsqueeze after the expert GEMM - that Unsqueeze sits between the GEGLU and the down projection instead - and its Convert is on the other side of the Transpose. Wrap both in optional<>, which matches either form, in the gate/up and down branches.

With the pattern binding, the routing guard is reached and rejects rank 3. Routing arrives as [n_tokens, top_k, 1] there versus [1, n_tokens, top_k, 1] on the rank-4 graph, so normalise it up to the rank-4 form, keep the op config that the stateless path already validates, and squeeze the batch dim back off the result. Guard that the replacement shape matches the ReduceSum it replaces.

26B-A4B on Arc B390, GPU, GGML_OPENVINO_REQUANT_KQUANT=q4_asym64_all: stateful pp512 66 -> 1585 t/s, tg128 30.2; prefill now at parity with stateless (1609) instead of 24x behind it.

The stateless path is unchanged: 26B perplexity is bit-identical before and after (7990.0534 +/- 1274.45692), and test-backend-ops -o MUL_MAT_ID on OPENVINO0 goes from 575/577 to 577/577.

Overview

Additional information

Requirements

@cavusmustafa
cavusmustafa force-pushed the moe_fusion_rank3_stateful branch from 7e45125 to e6100fc Compare October 3, 2026 16:36
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from 308ccd8 to 836d571 Compare October 3, 2026 19:48
@cavusmustafa
cavusmustafa force-pushed the moe_fusion_rank3_stateful branch from e6100fc to b68dc9e Compare October 5, 2026 19:00
@ravi9
ravi9 force-pushed the moe_fusion_rank3_stateful branch from b68dc9e to 324a0c5 Compare October 5, 2026 21:40
@ravi9
ravi9 marked this pull request as ready for review October 5, 2026 22:32
@ravi9
ravi9 requested a review from wine99 as a code owner October 5, 2026 22:32
@ravi9
ravi9 merged commit c0b1b7d into ravi9:dev_backend_openvino Oct 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants