ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-openvino / openvino / op / moe_compressed.hpp
| 1 | // Copyright (C) 2018-2026 Intel Corporation |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | // |
| 4 | // Local mirror of OpenVINO's internal ov::op::internal::MOE and MOECompressed ops. |
| 5 | // |
| 6 | // The class bodies are provided by the linked libopenvino.so; only the declarations are |
| 7 | // needed here so the backend can construct the node directly (same approach as |
| 8 | // GatherMatmul and GatedDeltaNet). The class layout must stay in sync with |
| 9 | // openvino/src/core/dev_api/openvino/op/moe.hpp |
| 10 | // openvino/src/common/transformations/include/ov_ops/moe_compressed.hpp |
| 11 | // |
| 12 | // \note MOE op classes are under development and subject to change. |
| 13 | |
| 14 | #pragma once |
| 15 | |
| 16 | #include <optional> |
| 17 | |
| 18 | #include "openvino/core/type/element_type.hpp" |
| 19 | #include "openvino/op/op.hpp" |
| 20 | |
| 21 | namespace ov::op::internal { |
| 22 | |
| 23 | class OPENVINO_API MOE : public ov::op::Op { |
| 24 | public: |
| 25 | OPENVINO_OP("MOE") |
| 26 | |
| 27 | MOE() = default; |
| 28 | |
| 29 | MOE(const OutputVector & args) : Op(args) {} |
| 30 | |
| 31 | enum class Expert_type { GEMM2_BIAS_SWIGLU_CLAMP, GEMM3_SWIGLU }; |
| 32 | |
| 33 | enum class Activation_type { SWIGLU, GEGLU_TANH, GEGLU_ERF }; |
| 34 | |
| 35 | struct Config { |
| 36 | Expert_type expert_type{ Expert_type::GEMM2_BIAS_SWIGLU_CLAMP }; |
| 37 | float expert_alpha{ 0.0f }; |
| 38 | float expert_beta{ 1.0f }; |
| 39 | size_t gate_idx{ 0 }; |
| 40 | Activation_type activation_type{ Activation_type::SWIGLU }; |
| 41 | }; |
| 42 | |
| 43 | MOE(const OutputVector & args, const Config & config); |
| 44 | |
| 45 | const Config & get_config() const; |
| 46 | void set_config(const Config & config); |
| 47 | |
| 48 | bool visit_attributes(AttributeVisitor & visitor) override; |
| 49 | void validate_and_infer_types() override; |
| 50 | std::shared_ptr<Node> clone_with_new_inputs(const OutputVector & new_args) const override; |
| 51 | |
| 52 | private: |
| 53 | Config m_config; |
| 54 | }; |
| 55 | |
| 56 | class OPENVINO_API MOECompressed : public MOE { |
| 57 | public: |
| 58 | OPENVINO_OP("MOECompressed", "", ov::op::internal::MOE) |
| 59 | |
| 60 | MOECompressed() = default; |
| 61 | |
| 62 | struct Config : public MOE::Config { |
| 63 | size_t hidden_size = 0; |
| 64 | size_t inter_size = 0; |
| 65 | size_t num_expert = 0; |
| 66 | size_t num_shared_expert = 0; |
| 67 | size_t top_k = 0; |
| 68 | // numeric_limits<size_t>::max() means per_channel compression (single group) |
| 69 | size_t group_size = 0; |
| 70 | bool has_batch_dim = false; |
| 71 | bool has_zp = false; |
| 72 | ov::element::Type out_type = ov::element::dynamic; |
| 73 | std::optional<float> scale_factor; |
| 74 | }; |
| 75 | |
| 76 | MOECompressed(const OutputVector & args, const Config & config); |
| 77 | |
| 78 | const Config & get_config() const { return m_config; } |
| 79 | |
| 80 | void set_scale_factor(float scale_factor) { m_config.scale_factor = scale_factor; } |
| 81 | |
| 82 | bool visit_attributes(AttributeVisitor & visitor) override; |
| 83 | void validate_and_infer_types() override; |
| 84 | std::shared_ptr<Node> clone_with_new_inputs(const OutputVector & new_args) const override; |
| 85 | |
| 86 | protected: |
| 87 | Config m_config; |
| 88 | }; |
| 89 | |
| 90 | } // namespace ov::op::internal |