interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-openvino / openvino / op / glu_geglu_quick.cpp

62 lines · 2349 bytes Raw Blame History
1#include "../node_context.h"
2#include "../op_table.h"
3#include "../utils.h"
4
5#include <memory>
6#include <openvino/core/node_output.hpp>
7#include <openvino/op/constant.hpp>
8#include <openvino/op/multiply.hpp>
9#include <openvino/op/slice.hpp>
10#include <openvino/op/swish.hpp>
11
12namespace ov {
13namespace frontend {
14namespace ggml {
15namespace op {
16
17OutputVector translate_glu_geglu_quick(const NodeContext & context) {
18 num_inputs_check(context, 1, 2);
19
20 ov::Output<ov::Node> src0;
21 ov::Output<ov::Node> src1;
22 if (context.get_input_size() == 2) {
23 src0 = process_view_input_new(context, 0);
24 src1 = process_view_input_new(context, 1);
25 } else {
26 // split along last axis, nc = ne[0] / 2
27 auto combined = process_view_input_new(context, 0);
28 auto combined_shape = combined.get_partial_shape();
29 int64_t last_dim_val = combined_shape[combined_shape.rank().get_length() - 1].get_length();
30 int64_t nc = last_dim_val / 2;
31
32 auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
33 auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
34 auto start0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
35 auto stop0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
36 auto start1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
37 auto stop1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2 * nc});
38
39 src0 = std::make_shared<ov::op::v8::Slice>(combined, start0, stop0, step, axis);
40 src1 = std::make_shared<ov::op::v8::Slice>(combined, start1, stop1, step, axis);
41 }
42
43 int32_t * params = context.get_output_op_params();
44 const int32_t swapped = params[1];
45 if (swapped) {
46 std::swap(src0, src1);
47 }
48
49 // GELU_QUICK(x) = x * sigmoid(1.702 * x)
50 // Create the constant in the same type as src0 to avoid f16/f32 mismatch.
51 auto input_type = src0.get_element_type();
52 auto coef = ov::op::v0::Constant::create(input_type, ov::Shape{}, {1.702f});
53 auto gated = std::make_shared<ov::op::v4::Swish>(src0, coef);
54 auto res = std::make_shared<ov::op::v1::Multiply>(gated, src1);
55
56 return rename_outputs_with_suffix({res}, context.get_name());
57}
58
59} // namespace op
60} // namespace ggml
61} // namespace frontend
62} // namespace ov