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
3.1 KiB88 linesraw
1#pragma once
2
3#include "node_context.h"
4
5#include <memory>
6#include <openvino/core/node.hpp>
7#include <openvino/op/shape_of.hpp>
8#include <openvino/op/slice.hpp>
9#include <utility>
10
11namespace ov {
12namespace frontend {
13namespace ggml {
14
15std::string getCurrentTime();
16
17void dump_ov_model(std::shared_ptr<ov::Model> model);
18
19void num_inputs_check(const NodeContext & context, size_t min_inputs, size_t max_inputs);
20
21int non_cont_dim(std::vector<size_t> ne, std::vector<size_t> nb);
22
23template <typename T> std::vector<int> argsort_descend(const std::vector<T> & v) {
24    std::vector<int> idx(v.size());
25    std::iota(idx.begin(), idx.end(), 0);
26    std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) { return v[i1] > v[i2]; });
27    return idx;
28}
29
30template <typename T> std::vector<T> sorted_descend(std::vector<T> v) {
31    std::sort(v.begin(), v.end(), [](T a, T b) { return a > b; });
32    return v;
33}
34
35template <typename T> bool is_permuted(const std::vector<T> & strides) {
36    for (size_t i = 0; i < strides.size() - 1; ++i) {
37        if (strides[i] < strides[i + 1]) {
38            return true;
39        }
40    }
41    return false;
42}
43
44template <typename T> std::vector<T> permute(const std::vector<T> & x, const std::vector<int> & perm) {
45    std::vector<T> result;
46    result.reserve(perm.size());
47    for (int i : perm) {
48        result.push_back(x[i]);
49    }
50    return result;
51}
52
53std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::op::v3::ShapeOf> & shape,
54                                         const std::vector<int> & dims);
55std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::Node> & node, const std::vector<int> & dims);
56
57OutputVector rename_outputs_with_suffix(const OutputVector & outputs, const std::string & suffix);
58
59std::pair<ov::Output<Node>, ov::Output<Node>> make_sin_cos(int32_t * rope_params,
60                                                           std::shared_ptr<ov::Node> inp_pos,
61                                                           std::shared_ptr<ov::Node> rope_freqs_weight = nullptr,
62                                                           bool imrope = false,
63                                                           bool stateful = false);
64
65ov::Output<ov::Node> process_view_input(const NodeContext & context, int input_index, int slice_len = 0, int axis = -1);
66
67ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int input_index);
68
69namespace op {
70template <typename T> OutputVector translate_1to1_match_2_inputs(const NodeContext & context) {
71    num_inputs_check(context, 2, 2);
72    auto input_0 = process_view_input_new(context, 0);
73    auto input_1 = process_view_input_new(context, 1);
74    auto res = std::make_shared<T>(input_0, input_1);
75    return rename_outputs_with_suffix({res}, context.get_name());
76}
77
78template <typename T> OutputVector translate_1to1_match_1_input(const NodeContext & context) {
79    num_inputs_check(context, 1, 1);
80    auto input = process_view_input_new(context, 0);
81    auto res = std::make_shared<T>(input);
82    return rename_outputs_with_suffix({res}, context.get_name());
83}
84}  // namespace op
85
86}  // namespace ggml
87}  // namespace frontend
88}  // namespace ov