Skip to content

Cm u2 fc gnk native - #39044

Draft
vmadananth wants to merge 32 commits into
openvinotoolkit:masterfrom
vmadananth:cm-u2-fc-gnk-native
Draft

vmadananth wants to merge 32 commits into
openvinotoolkit:masterfrom
vmadananth:cm-u2-fc-gnk-native

Conversation

@vmadananth

@vmadananth vmadananth commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Native GNK path for CM only. When cm::woq_u2_accepts_gnk passes (Xe2/Xe3 + CM JIT, u2 weights, gs = 64, N % 32 == 0, f16 per-group scale, per-group zp, f16 inference precision), the ONNX MatMulNBits reordered-B chain

u2[G,N,gs] → Convert → Subtract(zp) → Multiply(scale) → Transpose{1,0,2} → Reshape[N,K] → MatMul(transpose_b)

stays compressed. It becomes a FullyConnectedCompressed with weights_layout=GNK on the raw [G, N, gs] u2 weights, and the CM kernel runs it with WLAYOUT=0. Otherwise the chain is constant-folded to f16 exactly as on master.

The non-CM permute-to-NK fallback is #38206's scope; whichever lands second reconciles the shared pattern.

Changes

  • impls/cm/fully_connected_woq_u2_gnk.hpp: cm::woq_u2_accepts_gnk, the single check used by the three places below.
  • transformations_pipeline.cpp: is_decompression_multiply keeps Multiply → Transpose{1,0,2} → Reshape(3D→2D) → MatMul on constant weights unfolded only when the check passes. Every other chain behaves as on master.
  • compressed_weights_pattern.hpp: new narrow branch gnk_transpose_reshape_m (order {1,0,2}, rank 3→2, output [N, G·gs]). The existing branches are unchanged.
  • ConvertFullyConnectedToFullyConnectedCompressed:
    • On that branch, re-checks and emits the GNK FC (transpose_b=true, transpose_b_scale/zp=false, scale/zp squeezed to [G, N]). No Transpose or Reshape is left on the weights.
    • Asserts if the two checks disagree.
  • CM u2 FC: validate_impl accepts GNK via the same check. N/K come from fc_weight_dims. WLAYOUT=0 for GNK. Fusion reads the epilogue N from fc_weight_dims.

Dependencies / commit structure

Validation (Xe2/Xe3 with CM JIT)

  • --gtest_filter=*woq_u2*: 130 run, 129 passed, 1 skipped (no_cm_device, which runs only on a device without CM). New tests:
    • gnk_check.accepts_only_cm_eligible_gnk: each accept/reject condition of the check.
    • gnk_pipeline.eligible_chain_becomes_gnk_fc: [80,5120,64] through the full TransformationsPipeline gives one GNK FC on the raw u2 constant.
    • gnk_fold.matches_pipeline_without_gnk (gs=32, N=5104, no zp): the graph and constants are identical to a run with the GNK path disabled; no compressed FC or u2 constant remains.
    • gnk.selects_cm_and_matches_nk (M=5/40, f16/f32 out): CM is selected without forcing, WLAYOUT=0 is used, and the output is bit-identical to the NK layout of the same weights.
  • *fully_connected*:*FullyConnected*:*ConvertFCToCompressed*:*ConvertMatMulToFullyConnected*:*dynamic_quantize*:*fc_weights_layout*: 1417 run, 1385 passed, 0 failed, 32 skipped (31 device-specific int4 GEMV + no_cm_device).

@vmadananth
vmadananth requested review from a team as code owners October 20, 2026 21:36
@github-actions github-actions Bot added category: GPU OpenVINO GPU plugin category: transformations OpenVINO Runtime library - Transformations labels Oct 20, 2026
vmadananth and others added 10 commits October 21, 2026 12:16
…multiplying FC weight dimensions'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
# Conflicts:
#	src/plugins/intel_gpu/include/intel_gpu/primitives/fully_connected.hpp
#	src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
…gpu-fc-weights-layout

# Conflicts:
#	src/plugins/intel_gpu/include/intel_gpu/primitives/fully_connected.hpp
#	src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
# Conflicts:
#	src/plugins/intel_gpu/include/intel_gpu/primitives/fully_connected.hpp
#	src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
#	src/plugins/intel_gpu/src/graph/registry/fully_connected_impls.cpp
# Conflicts:
#	src/plugins/intel_gpu/include/intel_gpu/op/fc_weights_layout.hpp
#	src/plugins/intel_gpu/include/intel_gpu/primitives/fully_connected.hpp
#	src/plugins/intel_gpu/src/graph/fully_connected.cpp
#	src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp
#	src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
#	src/plugins/intel_gpu/src/plugin/transformations/op/fully_connected.cpp
#	src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_weights_layout_test.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove onednn change in the PR which I think is not needed

@geunhwan geunhwan added this to the 2026.5 milestone Oct 30, 2026

@e-ddykim e-ddykim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging #38206, transpose_before_reshape_m precedes and shadows gnk_transpose_reshape_m. This means the native GNK path introduced by this PR is never reached, and the PR's own GNK tests would fail. The pattern overlap/order needs to be reconciled in this PR.

@Kotomi-Du

Copy link
Copy Markdown
Contributor

this PR seems to cover all the changes from both #39011 and #38894. Do you want to convert rest of two into draft then?

const auto G = w[0].get_length();
const auto gs = w[2].get_length();
return {w[1], w[0] * w[2], G, gs};
}

@Kotomi-Du Kotomi-Du Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible that weights-rank = 3 not because it is per group quantization, but because it is MOE model as I described in this PR #39268.

In MOE model, it is 3D which has first dimension as experts. Please make sure the refactor of weights layout also take this case into consideration.

vmadananth added a commit to vmadananth/openvino that referenced this pull request Nov 3, 2026
@vmadananth
vmadananth marked this pull request as draft November 4, 2026 20:25
@vmadananth

Copy link
Copy Markdown
Contributor Author

This PR is merged with #38894

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: GPU OpenVINO GPU plugin category: transformations OpenVINO Runtime library - Transformations orca_CF

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants