char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
aee56b3ab
char/aliceai-t5-moe
1#include "../node_context.h" 2#include "../op_table.h" 3#include "../utils.h" 4 5#include <cstdint> 6#include <openvino/frontend/exception.hpp> 7#include <openvino/op/add.hpp> 8#include <openvino/op/constant.hpp> 9#include <openvino/op/convert.hpp> 10#include <openvino/op/range.hpp> 11#include <openvino/op/reduce_prod.hpp> 12#include <openvino/op/reshape.hpp> 13#include <openvino/op/scatter_update.hpp> 14#include <openvino/op/shape_of.hpp> 15 16namespace ov { 17namespace frontend { 18namespace ggml { 19namespace op { 20 21// GGML SET writes src1 into a view of src0 and returns the updated tensor. 22OutputVector translate_set (const NodeContext & context ) { 23num_inputs_check (context ,2 ,2 ); 24 25auto dst = process_view_input_new (context ,0 ); 26auto src = process_view_input_new (context ,1 ); 27 28src = std::make_shared < ov::op::v0::Convert > (src ,context .get_output_type ()); 29 30const auto dst_stride = context .get_input_stride (0 ); 31FRONT_END_OP_CONVERSION_CHECK (dst_stride .size () >=4 ,"SET requires 4D destination strides" ); 32 33const auto * op_params = reinterpret_cast < const uint32_t *> (context .get_output_op_params ()); 34const size_t offset = static_cast < size_t > (op_params [3 ]); 35 36const size_t elem_size = dst_stride .back (); 37FRONT_END_OP_CONVERSION_CHECK (elem_size != 0 && offset %elem_size == 0 , 38"SET offset must be aligned to destination element size" ); 39 40const int64_t offset_elems = static_cast < int64_t > (offset /elem_size ); 41 42auto dst_flat = std::make_shared < ov::op::v1::Reshape > ( 43dst , 44 ov::op::v0::Constant ::create (ov::element::i64 , {1 }, {-1 }), 45 false); 46 47auto src_flat = std::make_shared < ov::op::v1::Reshape > ( 48src , 49 ov::op::v0::Constant ::create (ov::element::i64 , {1 }, {-1 }), 50 false); 51 52auto src_shape = std::make_shared < ov::op::v3::ShapeOf > (src_flat , ov::element::i64 ); 53auto src_len = std::make_shared < ov::op::v1::ReduceProd > ( 54src_shape , 55 ov::op::v0::Constant ::create (ov::element::i64 , {1 }, {0 }), 56 false); 57 58auto start = ov::op::v0::Constant ::create (ov::element::i64 , {}, {offset_elems }); 59auto stop = std::make_shared < ov::op::v1::Add > (start ,src_len ); 60auto step = ov::op::v0::Constant ::create (ov::element::i64 , {}, {1 }); 61 62auto indices = std::make_shared < ov::op::v4::Range > (start ,stop ,step , ov::element::i64 ); 63auto axis = ov::op::v0::Constant ::create (ov::element::i64 , {}, {0 }); 64 65auto updated_flat = std::make_shared < ov::op::v3::ScatterUpdate > (dst_flat ,indices ,src_flat ,axis ); 66 67auto dst_shape = std::make_shared < ov::op::v3::ShapeOf > (dst , ov::element::i64 ); 68auto res = std::make_shared < ov::op::v1::Reshape > (updated_flat ,dst_shape , false); 69 70return rename_outputs_with_suffix ({res },context .get_name ()); 71} 72 73}// namespace op 74}// namespace ggml 75}// namespace frontend 76}// namespace ov