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 <openvino/op/transpose.hpp> 6 7namespace ov { 8namespace frontend { 9namespace ggml { 10namespace op { 11 12OutputVector translate_transpose (const NodeContext & context ) { 13num_inputs_check (context ,1 ,1 ); 14 15// Compute permute order from input/output shape and stride information 16// so it adapts to different input and output layouts. 17auto input_shape = context .get_input_shape (0 ).to_shape (); 18auto input_stride = context .get_input_stride (0 ); 19auto output_shape = context .get_output_shape ().to_shape (); 20auto output_stride = context .get_output_stride (); 21 22// Compute permute order by matching output and input stride rankings. 23// Build <stride, dim_index> pairs. 24 std::vector < std::pair < size_t ,int >> output_stride_dims ; 25 std::vector < std::pair < size_t ,int >> input_stride_dims ; 26 27for (int i = 0 ;i < 4 ;++ i ) { 28output_stride_dims .push_back ({output_stride [i ],i }); 29input_stride_dims .push_back ({input_stride [i ],i }); 30 } 31 32// Sort by stride in descending order. 33 std::sort (output_stride_dims .rbegin (),output_stride_dims .rend ()); 34 std::sort (input_stride_dims .rbegin (),input_stride_dims .rend ()); 35 36// Build permute order. 37 std::vector < int64_t > permute_order (4 ); 38for (int i = 0 ;i < 4 ;++ i ) { 39int output_dim = output_stride_dims [i ].second ; 40int input_dim = input_stride_dims [i ].second ; 41permute_order [output_dim ]= input_dim ; 42 } 43 44auto input = process_view_input_new (context ,0 ); 45 46auto res = std::make_shared < ov::op::v1::Transpose > ( 47input , ov::op::v0::Constant ::create (ov::element::i64 , {4 },permute_order )); 48return rename_outputs_with_suffix ({res },context .get_name ()); 49} 50 51}// namespace op 52}// namespace ggml 53}// namespace frontend 54}// namespace ov