char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
5397c3619
char/aliceai-t5-moe
1#include "../node_context.h" 2#include "../op_table.h" 3#include "../utils.h" 4 5#include <memory> 6#include <openvino/core/node.hpp> 7#include <openvino/core/node_output.hpp> 8#include <openvino/op/add.hpp> 9#include <openvino/op/constant.hpp> 10#include <openvino/op/convert.hpp> 11#include <openvino/op/gather.hpp> 12#include <openvino/op/reshape.hpp> 13#include <openvino/op/shape_of.hpp> 14 15namespace ov { 16namespace frontend { 17namespace ggml { 18namespace op { 19 20static ov::Output < ov::Node > reshape_add_id_input_to_2d (const ov::Output < ov::Node > & input , 21const ov::PartialShape & input_shape , 22const std::vector < int > & dims ) { 23const auto actual_shape = input .get_partial_shape (); 24if (actual_shape .rank ().is_static ()&& actual_shape .rank ().get_length ()== 2 ) { 25return input ; 26 } 27 28if (input_shape .rank ().is_static ()&& input_shape .rank ().get_length ()== 2 ) { 29return input ; 30 } 31 32auto shape = std::make_shared < ov::op::v3::ShapeOf > (input , ov::element::i64 ); 33return std::make_shared < ov::op::v1::Reshape > (input ,get_dimensions (shape ,dims ), false); 34} 35 36OutputVector translate_add_id (const NodeContext & context ) { 37num_inputs_check (context ,3 ,3 ); 38 39auto input = process_view_input_new (context ,0 ); 40auto bias = process_view_input_new (context ,1 ); 41auto ids = process_view_input_new (context ,2 ); 42 43// OpenVINO uses reversed GGML dimensions: 44// input: [1, n_token, n_used, n_embd] 45// bias: [1, 1, n_expert, n_embd] 46// ids: [1, 1, n_token, n_used] 47// Model bias constants may already be stored as [n_expert, n_embd]. 48bias = reshape_add_id_input_to_2d (bias ,context .get_input_shape (1 ), {2 ,3 }); 49ids = reshape_add_id_input_to_2d (ids ,context .get_input_shape (2 ), {2 ,3 }); 50 51if (ids .get_element_type ()!= ov::element::i32 && ids .get_element_type ()!= ov::element::i64 ) { 52ids = std::make_shared < ov::op::v0::Convert > (ids , ov::element::i32 ); 53 } 54 55auto gather_axis = ov::op::v0::Constant ::create (ov::element::i32 , ov::Shape {}, {0 }); 56 ov::Output < ov::Node > selected_bias = std::make_shared < ov::op::v8::Gather > (bias ,ids ,gather_axis ); 57selected_bias = std::make_shared < ov::op::v1::Reshape > ( 58selected_bias , std::make_shared < ov::op::v3::ShapeOf > (input , ov::element::i64 ), false); 59 60if (selected_bias .get_element_type ()!= input .get_element_type ()) { 61selected_bias = std::make_shared < ov::op::v0::Convert > (selected_bias ,input .get_element_type ()); 62 } 63 64 ov::Output < ov::Node > res = std::make_shared < ov::op::v1::Add > (input ,selected_bias ); 65const auto output_type = context .get_output_type (); 66if (res .get_element_type ()!= output_type ) { 67res = std::make_shared < ov::op::v0::Convert > (res ,output_type ); 68 } 69 70return rename_outputs_with_suffix ({res },context .get_name ()); 71} 72 73}// namespace op 74}// namespace ggml 75}// namespace frontend 76}// namespace ov