← Back to Pull requests

[GPU] Fix MoE fusion accuracy for flattened PagedAttention inputs #38631

Closed
unknown closed this pull request without merging on Oct 12, 2026 06:28 UTC
View on GitHub
unknown unknown commented on Oct 06, 2026 13:05 UTC
Author

Description of the issue (symptom, root cause, and resolution)


  • MiniCPM-V-4.7-35B-A3B INT4 generated incorrect output on GPU with the GenAI PagedAttention pipeline, while CPU and Optimum GPU produced correct results.

  • The unfused MoE graph restores flattened hidden states to [tokens, hidden]. However, the fusion could select [tokens, 1, hidden] as the fused MoE input.

  • Because the fused MoE output preserves the shape of input 0, adding [tokens, 1, hidden] to the shared-expert output [tokens, hidden] caused unintended broadcasting to [tokens, tokens, hidden].

  • The two-GEMM and three-GEMM fusion paths use hidden_states_m when it matches the final unfused output shape; otherwise, they use the input before the matched Unsqueeze.

  • If the selected MoE input still differs from the original output shape, the final Reshape is cloned after the fused MoE. This preserves both the optimization and the original output-shape semantics.

  • has_batch_dim is derived locally from the selected input rank: rank 3 indicates a batch dimension, while rank 2 indicates flattened input. Fusion is skipped only for dynamic or unsupported input ranks.

  • This removes the model-global PagedAttention assumption and supports subgraphs with different input and output shape conventions.

  • The FP16-only MoE router restriction was removed because the registered GPU implementation supports both FP16 and FP32. Positive transformation coverage now includes both precisions.
  • Relevant code


  • src/common/transformations/src/transformations/common_optimizations/moe_op_fusion.cpp

  • - Convert3GatherMatmulMoeBlockToMoeOp
    - Convert2GatherMatmulMoeBlockToMoeOp
  • src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp

  • - Registers MoeOpFusion without a model-global has_batch_dim value.
  • src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_router.cpp

  • - FuseMoESoftmaxRouter
    - FuseMoESigmoidRouter

    Reproduction and validation

    ov_transformations_tests \
      --device_suffix=1 \
      --gtest_filter='TransformationTestsF.Convert*GatherMatmulMoeBlockToMoeOp*'
    
    ov_gpu_unit_tests \
      --device_suffix=1 \
      --gtest_filter='smoke/FuseMoERouterTest.*'
    

    Problematic graph


    The original unfused graph restores the flattened [tokens, hidden] shape before combining the routed and shared-expert branches.

    flowchart LR
        H["Hidden states<br/>[tokens, 1, hidden]"]
        R["Reshape<br/>[tokens, hidden]"]
        M["GatherMatMul MoE blocks"]
        O["Final Reshape<br/>[tokens, hidden]"]
        E["Shared expert<br/>[tokens, hidden]"]
        A["Add<br/>[tokens, hidden]"]
    
        H --> R --> M --> O --> A
        H --> E --> A
    

    Before the fix, the fusion could use the tensor containing the singleton dimension as input 0. The routed branch therefore produced [tokens, 1, hidden], causing unintended broadcasting when combined with [tokens, hidden].

    flowchart LR
        H["Selected hidden states<br/>[tokens, 1, hidden]"]
        M["Fused MoE<br/>[tokens, 1, hidden]"]
        E["Shared expert<br/>[tokens, hidden]"]
        A["Broadcast Add<br/>[tokens, tokens, hidden]"]
        C["Corrupted hidden states"]
    
        H --> M --> A
        H --> E --> A
        A --> C
    
        style A fill:#ffcccc,stroke:#cc0000
        style C fill:#ffcccc,stroke:#cc0000
    

    The fix first compares hidden_states_m with the final unfused output shape. If they differ, it selects the input before the matched Unsqueeze, which is the actual flattened BGM input.

    When the selected input matches the original output, as in the MiniCPM topology, the fused MoE directly preserves [tokens, hidden]. If it still differs, the transformation remains enabled and clones the original final Reshape after the fused MoE.

    flowchart LR
        C1["Captured candidate<br/>[tokens, 1, hidden]"]
        C2["Pre-Unsqueeze candidate<br/>[tokens, hidden]"]
        S["Select MoE input"]
        M["Fused MoE"]
        O["Original output contract"]
        V{"Output shape matches?"}
        R["Cloned final Reshape"]
        E["Shared expert"]
        A["Add with preserved shape"]
    
        C1 --> S
        C2 --> S
        S --> M --> V
        O --> V
        V -- Yes --> A
        V -- No --> R --> A
        E --> A
    
        style S fill:#ccffcc,stroke:#008800
        style R fill:#ccffcc,stroke:#008800
        style A fill:#ccffcc,stroke:#008800
    

    Tickets


  • CVS-195765
  • Diff: 552 lines (+414 / -138) across 6 files Reviewer: v-Golubev Review duration: 8243m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 552 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #38631"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.1% (MEDIUM) · Higher = larger blast radius
    48.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19% · Safe to merge
    19%