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 <memory> 6#include <openvino/op/add.hpp> 7#include <openvino/op/constant.hpp> 8#include <openvino/op/divide.hpp> 9#include <openvino/op/multiply.hpp> 10#include <openvino/op/power.hpp> 11#include <openvino/op/reduce_mean.hpp> 12#include <openvino/op/sqrt.hpp> 13#include <openvino/op/subtract.hpp> 14 15namespace ov { 16namespace frontend { 17namespace ggml { 18namespace op { 19 20OutputVector translate_norm (const NodeContext & context ) { 21num_inputs_check (context ,1 ,1 ); 22 23auto input_node = process_view_input_new (context ,0 ); 24 25// Step 1: Calculate mean along the last dimension 26// mean = reduce_mean(input, axis=-1, keepdims=true) 27auto mean = std::make_shared < ov::op::v1::ReduceMean > ( 28input_node , ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {1 }, {-1 }), true); 29 30// Step 2: Calculate (input - mean) 31auto centered = std::make_shared < ov::op::v1::Subtract > (input_node ,mean ); 32 33// Step 3: Calculate squared differences (input - mean)^2 34auto squared = std::make_shared < ov::op::v1::Power > ( 35centered , ov::op::v0::Constant ::create (ov::element::f32 , ov::Shape {1 }, {2.0f })); 36 37// Step 4: Calculate variance = mean((input - mean)^2) 38auto variance = std::make_shared < ov::op::v1::ReduceMean > ( 39squared , ov::op::v0::Constant ::create (ov::element::i64 , ov::Shape {1 }, {-1 }), true); 40 41// Step 5: Get epsilon from op_params 42float eps ; 43memcpy (& eps ,context .get_output_op_params (),sizeof (float )); 44 45// Step 6: Calculate std = sqrt(variance + eps) 46auto std_dev = std::make_shared < ov::op::v0::Sqrt > (std::make_shared < ov::op::v1::Add > ( 47variance , ov::op::v0::Constant ::create (ov::element::f32 , ov::Shape {1 }, {eps }))); 48 49// Step 7: Normalize: output = (input - mean) / std 50auto res = std::make_shared < ov::op::v1::Divide > (centered ,std_dev ); 51 52return rename_outputs_with_suffix ({res },context .get_name ()); 53} 54 55}// namespace op 56}// namespace ggml 57}// namespace frontend 58}// namespace ov