char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
9789c4ecd
char/aliceai-t5-moe
1#include "squeeze_matmul.h" 2 3#include <openvino/core/graph_util.hpp> 4#include <openvino/core/rt_info.hpp> 5#include <openvino/op/constant.hpp> 6#include <openvino/op/matmul.hpp> 7#include <openvino/op/squeeze.hpp> 8#include <openvino/op/unsqueeze.hpp> 9#include <openvino/pass/pattern/op/label.hpp> 10#include <openvino/pass/pattern/op/pattern.hpp> 11#include <openvino/pass/pattern/op/wrap_type.hpp> 12 13namespace opp= ov::pass::pattern; 14 15namespace ov { 16namespace frontend { 17namespace ggml { 18namespace pass { 19 20// For quantized models, NPUW expects the activation to be 3d in DQ(DynamicQuantization) opt, e.g. DQMatMulGQ2i 21SqueezeMatmul ::SqueezeMatmul () { 22auto m_act = opp::any_input (); 23auto m_wei = opp::any_input (); 24auto m_matmul = opp::wrap_type < ov::op::v0::MatMul > ({m_act ,m_wei }); 25 26const auto callback = [= ](ov::pass::pattern::Matcher & m ) { 27const auto & pattern_map = m .get_pattern_value_map (); 28auto matmul_node = 29 std::dynamic_pointer_cast < ov::op::v0::MatMul > (pattern_map .at (m_matmul ).get_node_shared_ptr ()); 30auto act = pattern_map .at (m_act ); 31auto wei = pattern_map .at (m_wei ); 32auto act_shape = act .get_partial_shape (); 33auto wei_shape = wei .get_partial_shape (); 34if (act_shape .rank ().is_dynamic ()|| wei_shape .rank ().is_dynamic ()) { 35return false; 36 } 37if (act_shape .rank ().get_length ()== 4 && wei_shape .rank ().get_length ()== 2 ) { 38auto axis = ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {1 }, {0 }); 39auto squeezed_act = std::make_shared < ov::op::v0::Squeeze > (act ,axis ); 40auto new_matmul = std::make_shared < ov::op::v0::MatMul > (squeezed_act ,wei ,matmul_node -> get_transpose_a (), 41matmul_node -> get_transpose_b ()); 42auto unsqueezed_output = std::make_shared < ov::op::v0::Unsqueeze > (new_matmul ,axis ); 43unsqueezed_output -> set_friendly_name (matmul_node -> get_friendly_name ()); 44 ov::copy_runtime_info (matmul_node , {squeezed_act ,new_matmul ,unsqueezed_output }); 45 ov::replace_node (matmul_node ,unsqueezed_output ); 46return true; 47 } 48return false; 49 }; 50 51register_matcher (std::make_shared < ov::pass::pattern::Matcher > (m_matmul ,"ov::frontend::ggml::pass::SqueezeMatmul" ), 52callback ); 53} 54 55}// namespace pass 56}// namespace ggml 57}// namespace frontend 58}// namespace ov