#pragma once
#include "node_context.h"
#include <memory>
#include <openvino/core/node.hpp>
#include <openvino/op/convert.hpp>
#include <openvino/op/shape_of.hpp>
#include <openvino/op/slice.hpp>
#include <utility>
namespace ov {
namespace frontend {
namespace ggml {
void num_inputs_check(const NodeContext & context, size_t min_inputs, size_t max_inputs);
std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::op::v3::ShapeOf> & shape,
const std::vector<int> & dims);
std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::Node> & node, const std::vector<int> & dims);
OutputVector rename_outputs_with_suffix(const OutputVector & outputs, const std::string & suffix);
std::pair<ov::Output<Node>, ov::Output<Node>> make_sin_cos(int32_t * rope_params,
std::shared_ptr<ov::Node> inp_pos,
std::shared_ptr<ov::Node> rope_freqs_weight = nullptr,
int mode = 0,
bool stateful = false,
int64_t head_dim = 0);
std::shared_ptr<ov::Node> gather_compressed_rows(const ov::Output<ov::Node> & weights,
const ov::Output<ov::Node> & indices);
ov::Output<ov::Node> process_view_input(const NodeContext & context, int input_index, int slice_len = 0, int axis = -1);
ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int input_index);
bool is_recurrent_cache_reset_case(const NodeContext & context);
OutputVector translate_recurrent_cache_reset(const NodeContext & context);
ov::Output<ov::Node> get_kq_mask_input(const NodeContext & context, size_t input_index);
inline bool is_kvcache_4d_shape(const ov::PartialShape & shape) {
return shape.rank().is_static() && shape.rank().get_length() == 4 && shape[1].is_dynamic() &&
shape[2].is_static() && shape[3].is_static();
}
constexpr const char * GGML_OV_GROUPED_ROWS = "ggml_ov_grouped_rows";
constexpr const char * GGML_OV_V_TOKEN_MAJOR = "ggml_ov_v_token_major";
constexpr const char * GGML_OV_SSM_SCAN_PACKED = "ggml_ov_ssm_scan_packed";
namespace op {
template <typename T> OutputVector translate_1to1_match_2_inputs(const NodeContext & context) {
num_inputs_check(context, 2, 2);
auto input_0 = process_view_input_new(context, 0);
auto input_1 = process_view_input_new(context, 1);
auto output_type = context.get_output_type();
if (input_0.get_element_type() != input_1.get_element_type()) {
if (input_0.get_element_type() != ov::element::f32) {
input_0 = std::make_shared<ov::op::v0::Convert>(input_0, ov::element::f32);
}
if (input_1.get_element_type() != ov::element::f32) {
input_1 = std::make_shared<ov::op::v0::Convert>(input_1, ov::element::f32);
}
}
ov::Output<ov::Node> res = std::make_shared<T>(input_0, input_1);
if (res.get_element_type() != output_type) {
res = std::make_shared<ov::op::v0::Convert>(res, output_type);
}
return rename_outputs_with_suffix({res}, context.get_name());
}
template <typename T> OutputVector translate_1to1_match_1_input(const NodeContext & context) {
num_inputs_check(context, 1, 1);
auto input = process_view_input_new(context, 0);
auto res = std::make_shared<T>(input);
return rename_outputs_with_suffix({res}, context.get_name());
}
}
} } }