Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-openvino/openvino/op/rms_norm.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-openvino / openvino / op / rms_norm.cpp` 89 lines ยท 3665 bytes Raw Blame History 1 #include "../node_context.h" 2 #include "../op_table.h" 3 #include "../utils.h" 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 namespace ov { 18 namespace frontend { 19 namespace ggml { 20 namespace op { 21 22 OutputVector translate_rms_norm(const NodeContext & context) { 23 num_inputs_check(context, 1, 1); 24 25 auto op_case = context.get_op_case(); 26 27 ov::Output input_node; 28 if (op_case == 3) { 29 // Flatten sequence and token dimensions to match the gate layout. 30 auto input_shape = context.get_input_shape(0).to_shape(); 31 input_node = std::make_shared( 32 context.get_input(0), 33 ov::op::v0::Constant::create( 34 ov::element::i64, {4}, std::vector{1, -1, (int64_t) input_shape[2], (int64_t) input_shape[3]}), 35 false); 36 } else if (op_case == 1) { 37 input_node = process_view_input_new(context, 0); 38 } else if (op_case == 2) { 39 auto ssm_state_size = context.get_ssm_state_size(); 40 // The GDN op packs [attn | new_state] along the row axis; the state occupies the last 41 // ssm_state_size * n_seqs rows. Slice it off (scaling by the active sequence count) to keep 42 // just the attention output. 43 ov::Output state_end; 44 if (context.has_input("s_copy_active_slot_len")) { 45 auto len = context.get_input("s_copy_active_slot_len"); 46 auto state_rows = std::make_shared( 47 ov::op::v0::Constant::create(ov::element::i64, {1}, {ssm_state_size}), len); 48 state_end = std::make_shared(state_rows); 49 } else { 50 state_end = ov::op::v0::Constant::create(ov::element::i64, {1}, {-ssm_state_size}); 51 } 52 auto gdn_attn_output = std::make_shared( 53 context.get_input(0), ov::op::v0::Constant::create(ov::element::i64, {1}, {0}), state_end, 54 ov::op::v0::Constant::create(ov::element::i64, {1}, {1}), 55 ov::op::v0::Constant::create(ov::element::i64, {1}, {2})); 56 57 auto input_shape = context.get_input_shape(0).to_shape(); 58 input_node = std::make_shared( 59 gdn_attn_output, 60 ov::op::v0::Constant::create( 61 ov::element::i64, {4}, std::vector{1, -1, (int64_t) input_shape[2], (int64_t) input_shape[3]}), 62 false); 63 64 } else { 65 input_node = process_view_input_new(context, 0); 66 } 67 auto square = std::make_shared(input_node, input_node); 68 69 auto mean = std::make_shared( 70 square, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}), true); 71 72 float eps; 73 memcpy(&eps, context.get_output_op_params(), sizeof(float)); 74 75 auto rms = std::make_shared( 76 std::make_shared(mean, ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {eps}))); 77 78 auto reciprocal = 79 std::make_shared(ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {1.0f}), rms); 80 81 auto res = std::make_shared(input_node, reciprocal); 82 83 return rename_outputs_with_suffix({res}, context.get_name()); 84 } 85 86 } // namespace op 87 } // namespace ggml 88 } // namespace frontend 89 } // namespace ov