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
[NPUW] add npuw pattern fix for dequantizeLinear op when scale is fp16 (#31330)
bopeng12343e9f5d42f298
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cppindex 021a8b43605..9f6255eb03e 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp@@ -366,8 +366,9 @@ DQMatMulGQi::DQMatMulGQi(Context::Ref ctx) {auto out_shape = matched_node_matmul->output(0).get_shape();if (ov::element::i4 == matched_qweight->get_element_type() && qweight_shape.size() == 3 &&- ov::element::f32 == matched_qcoeff->get_element_type() && qcoeff_shape.size() == 3 &&- act_shape.size() == 3 && act_shape[1] == 1 && // single-token case+ (ov::element::f32 == matched_qcoeff->get_element_type() ||+ ov::element::f16 == matched_qcoeff->get_element_type()) &&+ qcoeff_shape.size() == 3 && act_shape.size() == 3 && act_shape[1] == 1 && // single-token caseqcoeff_shape[0] == qweight_shape[0] && qcoeff_shape[1] == 1 && qcoeff_shape[2] == qweight_shape[2] &&!matched_matmul->get_transpose_a() && !matched_matmul->get_transpose_b()) {if (!ctx.get().mm_dq_full) {@@ -403,7 +404,9 @@ DQMatMulGQi::DQMatMulGQi(Context::Ref ctx) {ctx.get().permute(matched_qweight, {0, 2, 1});// Mark S closure to be lowered fo f16- ctx.get().to_f16(matched_qcoeff);+ if (ov::element::f32 == matched_qcoeff->get_element_type()) {+ ctx.get().to_f16(matched_qcoeff);+ }// Reshape the Act to group formatconst auto NSPLIT = qweight_shape[0];@@ -651,8 +654,9 @@ DQMatMulGQiP::DQMatMulGQiP(Context::Ref ctx) {auto act_shape = matched_out_mmi.get_shape();if (ov::element::i4 == matched_qweight->get_element_type() && qweight_shape.size() == 3 &&- ov::element::f32 == matched_qcoeff->get_element_type() && qcoeff_shape.size() == 3 &&- act_shape.size() == 3 && act_shape[1] > 1 && // multi-token case+ (ov::element::f32 == matched_qcoeff->get_element_type() ||+ ov::element::f16 == matched_qcoeff->get_element_type()) &&+ qcoeff_shape.size() == 3 && act_shape.size() == 3 && act_shape[1] > 1 && // multi-token caseqcoeff_shape[0] == qweight_shape[0] && qcoeff_shape[1] == 1 && qcoeff_shape[2] == qweight_shape[2] &&!matched_matmul->get_transpose_a() && !matched_matmul->get_transpose_b()) {if (!ctx.get().mm_dq_full) {@@ -688,7 +692,9 @@ DQMatMulGQiP::DQMatMulGQiP(Context::Ref ctx) {ctx.get().permute(matched_qweight, {0, 2, 1});// Mark S closure to be lowered fo f16- ctx.get().to_f16(matched_qcoeff);+ if (ov::element::f32 == matched_qcoeff->get_element_type()) {+ ctx.get().to_f16(matched_qcoeff);+ }// Reshape the Act to group formatconst auto NSPLIT = qweight_shape[0];diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.cpp b/src/plugins/intel_npu/src/plugin/npuw/util.cppindex bc4075f4009..16d2d0e32bc 100644--- a/src/plugins/intel_npu/src/plugin/npuw/util.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/util.cpp@@ -604,7 +604,8 @@ ov::Tensor ov::npuw::util::permute(const ov::Tensor& t, const std::vector<std::sif (axes[0] == 2 && axes[1] == 0 && axes[2] == 1) {return transpose(t);} else if (axes[0] == 0 && axes[1] == 2 && axes[2] == 1) {- NPUW_ASSERT(t.get_element_type() == ov::element::i4 || t.get_element_type() == ov::element::f32);+ NPUW_ASSERT(t.get_element_type() == ov::element::i4 || t.get_element_type() == ov::element::f32 ||+ t.get_element_type() == ov::element::f16);ov::Shape tshape = {shape[0], shape[2], shape[1]};ov::Tensor tnew(t.get_element_type(), tshape);@@ -622,6 +623,13 @@ ov::Tensor ov::npuw::util::permute(const ov::Tensor& t, const std::vector<std::sr,shape[1]);break;+ case ov::element::f16:+ twrite<uint16_t>(tnew,+ tread<uint16_t>(t, p * shape[1] + r, c, shape[2]),+ p * shape[2] + c,+ r,+ shape[1]);+ break;default:NPUW_ASSERT(false && "Element type is not supported yet");}