char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
890f1a27e
char/aliceai-t5-moe
1#include "../node_context.h" 2#include "../op_table.h" 3#include "../utils.h" 4 5#include <climits> 6#include <cstdint> 7#include <memory> 8#include <openvino/core/node.hpp> 9#include <openvino/core/node_output.hpp> 10#include <openvino/op/broadcast.hpp> 11#include <openvino/op/concat.hpp> 12#include <openvino/op/constant.hpp> 13#include <openvino/op/convert.hpp> 14#include <openvino/op/matmul.hpp> 15#include <openvino/op/reshape.hpp> 16#include <openvino/op/slice.hpp> 17#include <openvino/op/transpose.hpp> 18#include <openvino/op/unsqueeze.hpp> 19#include <openvino/op/util/op_types.hpp> 20#include <vector> 21 22namespace ov { 23namespace frontend { 24namespace ggml { 25namespace op { 26 27OutputVector translate_mulmat (const NodeContext & context ) { 28num_inputs_check (context ,2 ,2 ); 29 30int op_case = context .get_op_case (); 31 32 ov::Output < Node > res ; 33 ov::Output < ov::Node > B ; 34 ov::Output < ov::Node > A ; 35if (op_case == 3 ) { 36B = process_view_input (context ,0 ); 37A = process_view_input (context ,1 ); 38 }else { 39B = process_view_input_new (context ,0 ); 40A = process_view_input_new (context ,1 ); 41 } 42 43if (A .get_element_type ()!= B .get_element_type ()) { 44B = std::make_shared < ov::op::v0::Convert > (context .get_input (0 ),context .get_input_type (1 )); 45 } 46 47auto B_shape = context .get_input_shape (0 ).to_shape (); 48auto A_shape = context .get_input_shape (1 ).to_shape (); 49int64_t A_batch = A_shape [1 ]; 50int64_t B_batch = B_shape [1 ]; 51 52auto A_batch_larger = A_batch > B_batch ; 53auto batch_large = A_batch_larger ?A_batch :B_batch ; 54auto batch_small = A_batch_larger ?B_batch :A_batch ; 55 56Output < Node > Z = A_batch_larger ?B :A ; 57auto Z_shape = A_batch_larger ?B_shape :A_shape ; 58int64_t factor = batch_large /batch_small ; 59if (factor > 1 && batch_small > 1 ) { 60auto batch_large_node = ov::op::v0::Constant ::create (ov::element::i64 , {1 }, std::vector < int64_t > {batch_large }); 61auto batch_small_node = ov::op::v0::Constant ::create (ov::element::i64 , {1 }, std::vector < int64_t > {batch_small }); 62auto factor_node = ov::op::v0::Constant ::create (ov::element::i64 , {1 }, std::vector < int64_t > {factor }); 63 64auto unsqueeze_axes = ov::op::v0::Constant ::create (ov::element::i64 ,Shape {}, {2 }); 65auto Z_unsqueezed = std::make_shared < ov::op::v0::Unsqueeze > (Z ,unsqueeze_axes ); 66 67auto broadcast_shape = ov::op::v0::Constant ::create ( 68 ov::element::i64 , {5 }, {(int64_t )1 , (int64_t )1 ,factor , (int64_t )1 , (int64_t )1 }); 69auto new_Z_shape = ov::op::v0::Constant ::create (ov::element::i64 , {4 }, 70 {(int64_t )0 ,batch_large , (int64_t )-1 , (int64_t )Z_shape [3 ]}); 71if (op_case == 2 ) { 72new_Z_shape = ov::op::v0::Constant ::create (ov::element::i64 , {4 }, 73 {(int64_t )0 ,batch_large , (int64_t )Z_shape [2 ], (int64_t )-1 }); 74 } 75 76auto Z_broadcasted = std::make_shared < ov::op::v3::Broadcast > (Z_unsqueezed ,broadcast_shape , 77 ov::op::BroadcastType ::BIDIRECTIONAL ); 78Z = std::make_shared < ov::op::v1::Reshape > (Z_broadcasted ,new_Z_shape , true); 79 } 80if (A_batch_larger ) { 81B = Z ; 82 }else { 83A = Z ; 84 } 85 86bool transpose_b = true; 87res = std::make_shared < ov::op::v0::MatMul > (A ,B , false,transpose_b ); 88 89const auto output_type = context .get_output_type (); 90if (res .get_element_type ()!= output_type ) { 91res = std::make_shared < ov::op::v0::Convert > (res ,output_type ); 92 } 93 94return rename_outputs_with_suffix ({res },context .get_name ()); 95} 96 97}// namespace op 98}// namespace ggml 99}// namespace frontend 100}// namespace ov