char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Zijun Yuopenvino: OV 2026.2, context-shift, Q5_1 support, gemma4 dense/embedding, and -fa off (#24503)890f1a27e

char/aliceai-t5-moe
2.0 KiB58 linesraw
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) {
21    num_inputs_check(context, 1, 1);
22
23    auto 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)
27    auto mean = std::make_shared<ov::op::v1::ReduceMean>(
28        input_node, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}), true);
29
30    // Step 2: Calculate (input - mean)
31    auto centered = std::make_shared<ov::op::v1::Subtract>(input_node, mean);
32
33    // Step 3: Calculate squared differences (input - mean)^2
34    auto squared = std::make_shared<ov::op::v1::Power>(
35        centered, ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {2.0f}));
36
37    // Step 4: Calculate variance = mean((input - mean)^2)
38    auto variance = std::make_shared<ov::op::v1::ReduceMean>(
39        squared, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}), true);
40
41    // Step 5: Get epsilon from op_params
42    float eps;
43    memcpy(&eps, context.get_output_op_params(), sizeof(float));
44
45    // Step 6: Calculate std = sqrt(variance + eps)
46    auto std_dev = std::make_shared<ov::op::v0::Sqrt>(std::make_shared<ov::op::v1::Add>(
47        variance, ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {eps})));
48
49    // Step 7: Normalize: output = (input - mean) / std
50    auto res = std::make_shared<ov::op::v1::Divide>(centered, std_dev);
51
52    return rename_outputs_with_suffix({res}, context.get_name());
53}
54
55}  // namespace op
56}  // namespace ggml
57}  // namespace frontend
58}  // namespace ov