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 <openvino/core/except.hpp> 6#include <openvino/op/add.hpp> 7#include <openvino/op/concat.hpp> 8#include <openvino/op/constant.hpp> 9#include <openvino/op/convert.hpp> 10#include <openvino/op/equal.hpp> 11#include <openvino/op/gather.hpp> 12#include <openvino/op/greater_eq.hpp> 13#include <openvino/op/if.hpp> 14#include <openvino/op/less.hpp> 15#include <openvino/op/logical_or.hpp> 16#include <openvino/op/multiply.hpp> 17#include <openvino/op/range.hpp> 18#include <openvino/op/reshape.hpp> 19#include <openvino/op/shape_of.hpp> 20#include <openvino/op/slice.hpp> 21#include <openvino/op/squeeze.hpp> 22#include <openvino/op/unsqueeze.hpp> 23#include <vector> 24 25namespace ov { 26namespace frontend { 27namespace ggml { 28namespace op { 29 30OutputVector translate_scale (const NodeContext & context ) { 31num_inputs_check (context ,1 ,1 ); 32 33float scale ; 34float bias ; 35memcpy (& scale , (float * )context .get_output_op_params ()+ 0 ,sizeof (float )); 36memcpy (& bias , (float * )context .get_output_op_params ()+ 1 ,sizeof (float )); 37 38auto scale_node = std::make_shared < ov::op::v0::Constant > (ov::element::f32 , ov::Shape {}, std::vector < float > {scale }); 39 40if (context .get_op_case ()== 1 && context .has_input ("cache_rs_reset_len" )) { 41auto cache_rs_reset_idx = context .get_input ("cache_rs_reset_idx" ); 42auto cache_rs_reset_len = context .get_input ("cache_rs_reset_len" ); 43 44auto cache_rs = context .get_input (0 ); 45 46auto cache_shape = std::make_shared < ov::op::v3::ShapeOf > (cache_rs , ov::element::i64 ); 47auto n_slots_1d = std::make_shared < ov::op::v8::Gather > ( 48cache_shape , ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {1 }, {2 }), 49 ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {}, {0 })); 50auto n_slots = std::make_shared < ov::op::v0::Squeeze > (n_slots_1d ); 51 52auto iota = std::make_shared < ov::op::v4::Range > ( 53 ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {}, {0 }),n_slots , 54 ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {}, {1 }), ov::element::i64 ); 55 56auto idx_plus_len = std::make_shared < ov::op::v1::Add > (cache_rs_reset_idx ,cache_rs_reset_len ); 57auto less_than_idx = std::make_shared < ov::op::v1::Less > (iota ,cache_rs_reset_idx ); 58auto greater_equal_idx_plus_len = std::make_shared < ov::op::v1::GreaterEqual > (iota ,idx_plus_len ); 59auto keep_mask = std::make_shared < ov::op::v1::LogicalOr > (less_than_idx ,greater_equal_idx_plus_len ); 60 61auto keep_mask_f32 = std::make_shared < ov::op::v0::Convert > (keep_mask , ov::element::f32 ); 62auto keep_mask_reshape = std::make_shared < ov::op::v0::Unsqueeze > ( 63keep_mask_f32 , ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {1 }, {1 })); 64 65auto cleared_cache_rs = std::make_shared < ov::op::v1::Multiply > (cache_rs ,keep_mask_reshape ); 66return rename_outputs_with_suffix ({cleared_cache_rs },context .get_name ()); 67 } 68 69auto scaled = std::make_shared < ov::op::v1::Multiply > (context .get_input (0 ),scale_node ); 70 71 std::shared_ptr < ov::Node > res ; 72if (bias != 0.0f ) { 73auto bias_node = 74 std::make_shared < ov::op::v0::Constant > (ov::element::f32 , ov::Shape {}, std::vector < float > {bias }); 75res = std::make_shared < ov::op::v1::Add > (scaled ,bias_node ); 76 }else { 77res = scaled ; 78 } 79 80return rename_outputs_with_suffix ({res },context .get_name ()); 81} 82 83}// namespace op 84}// namespace ggml 85}// namespace frontend 86}// namespace ov