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 / pass / align_eltwise_ranks.h
| 1 | #pragma once |
| 2 | |
| 3 | #include <openvino/pass/matcher_pass.hpp> |
| 4 | |
| 5 | namespace ov { |
| 6 | namespace frontend { |
| 7 | namespace ggml { |
| 8 | namespace pass { |
| 9 | |
| 10 | // Give a binary eltwise op's two operands the same rank, by unsqueezing leading axes onto the |
| 11 | // shorter one. |
| 12 | // |
| 13 | // This is semantically a no-op -- NUMPY broadcasting already left-pads the lower-rank operand |
| 14 | // with 1s, and the result rank is max(rank_a, rank_b) either way. It exists purely to work |
| 15 | // around an OpenVINO GPU-plugin defect: an eltwise op whose operands differ in rank is computed |
| 16 | // incorrectly once the plugin fuses it as a post-op into an `rms` primitive. gemma-4 dense hits |
| 17 | // this under stateful execution, where the layer tail adds a rank-3 residual to the rank-4 |
| 18 | // RMS-norm output; the model then degenerates into repeated tokens on GPU while CPU is correct. |
| 19 | // Equalising the ranks keeps the fusion and makes it compute the right answer. |
| 20 | // |
| 21 | // Deliberately a graph pass rather than something the op translators do: rank is load-bearing |
| 22 | // during translation (several translators and later passes read operand ranks), and rewriting |
| 23 | // operands mid-translate breaks the attention path. Running after the graph is complete avoids |
| 24 | // that entirely. |
| 25 | // |
| 26 | // Only applies when both operands are real tensors -- a tensor-vs-Constant mismatch is the |
| 27 | // RMS norm's own eps/rsqrt arithmetic, which folds into the `rms` primitive rather than |
| 28 | // becoming a fused post-op, and is not affected by the defect. The norm output itself is never |
| 29 | // unsqueezed: when it is the lower-rank operand (gemma-3), that breaks the fused path instead. |
| 30 | class AlignEltwiseOperandRanks : public ov::pass::MatcherPass { |
| 31 | public: |
| 32 | OPENVINO_MATCHER_PASS_RTTI("ov::frontend::ggml::pass::AlignEltwiseOperandRanks") |
| 33 | AlignEltwiseOperandRanks(); |
| 34 | }; |
| 35 | |
| 36 | } // namespace pass |
| 37 | } // namespace ggml |
| 38 | } // namespace frontend |
| 39 | } // namespace ov |