char-fork/llama.cpp

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

Zijun YuOpenVINO: Qwen3.5, memory optimization, and test-recurrent-state-rollback (#26952)aee56b3ab

char/aliceai-t5-moe
1.7 KiB45 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/reduce_sum.hpp>
9#include <openvino/op/unsqueeze.hpp>
10
11namespace ov {
12namespace frontend {
13namespace ggml {
14namespace op {
15
16OutputVector translate_add(const NodeContext & context) {
17    num_inputs_check(context, 2, 2);
18
19    if (context.get_op_case() == 1) {
20        // MoE expert-plane sum (see is_moe_expert_sum_add): input 1 is a VIEW plane of the
21        // shared base tensor `experts` = [n_embd, n_expert_used, n_tokens, 1] (ggml order) ->
22        // [1, n_tokens, n_expert_used, n_embd] (OV order). The whole ADD chain is equivalent to
23        // reducing the expert axis (OV axis 2) of that base, so bypass the chain and the
24        // per-plane Slices entirely.
25        size_t view_size = context.get_view_input_size(1);
26        auto base_name = context.get_view_input_src_name(1, view_size - 1);
27        auto base = context.get_input(base_name);
28
29        auto reduced = std::make_shared<ov::op::v1::ReduceSum>(
30            base, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}), false);
31        auto res =
32            std::make_shared<ov::op::v0::Unsqueeze>(reduced, ov::op::v0::Constant::create(ov::element::i64, {1}, {1}));
33        return rename_outputs_with_suffix({res}, context.get_name());
34    }
35
36    auto input_0 = process_view_input_new(context, 0);
37    auto input_1 = process_view_input_new(context, 1);
38    auto res = std::make_shared<ov::op::v1::Add>(input_0, input_1);
39    return rename_outputs_with_suffix({res}, context.get_name());
40}
41
42}  // namespace op
43}  // namespace ggml
44}  // namespace frontend
45}  // namespace ov