Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-openvino/openvino/pass/squeeze_matmul.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-openvino / openvino / pass / squeeze_matmul.cpp` 59 lines ยท 2492 bytes Raw Blame History 1 #include "squeeze_matmul.h" 2 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 14 namespace opp = ov::pass::pattern; 15 16 namespace ov { 17 namespace frontend { 18 namespace ggml { 19 namespace pass { 20 21 // For quantized models, NPUW expects the activation to be 3d in DQ(DynamicQuantization) opt, e.g. DQMatMulGQ2i 22 SqueezeMatmul::SqueezeMatmul() { 23 auto m_act = opp::any_input(); 24 auto m_wei = opp::any_input(); 25 auto m_matmul = opp::wrap_type({m_act, m_wei}); 26 27 const auto callback = [=](ov::pass::pattern::Matcher & m) { 28 const auto & pattern_map = m.get_pattern_value_map(); 29 auto matmul_node = 30 ov::as_type_ptr(pattern_map.at(m_matmul).get_node_shared_ptr()); 31 auto act = pattern_map.at(m_act); 32 auto wei = pattern_map.at(m_wei); 33 auto act_shape = act.get_partial_shape(); 34 auto wei_shape = wei.get_partial_shape(); 35 if (act_shape.rank().is_dynamic() || wei_shape.rank().is_dynamic()) { 36 return false; 37 } 38 if (act_shape.rank().get_length() == 4 && wei_shape.rank().get_length() == 2) { 39 auto axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}); 40 auto squeezed_act = std::make_shared(act, axis); 41 auto new_matmul = std::make_shared(squeezed_act, wei, matmul_node->get_transpose_a(), 42 matmul_node->get_transpose_b()); 43 auto unsqueezed_output = std::make_shared(new_matmul, axis); 44 unsqueezed_output->set_friendly_name(matmul_node->get_friendly_name()); 45 ov::copy_runtime_info(matmul_node, {squeezed_act, new_matmul, unsqueezed_output}); 46 ov::replace_node(matmul_node, unsqueezed_output); 47 return true; 48 } 49 return false; 50 }; 51 52 register_matcher(std::make_shared(m_matmul, "ov::frontend::ggml::pass::SqueezeMatmul"), 53 callback); 54 } 55 56 } // namespace pass 57 } // namespace ggml 58 } // namespace frontend 59 } // namespace ov