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/set_rows.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 / set_rows.cpp` 96 lines ยท 4594 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 #include 17 #include 18 #include 19 #include 20 #include 21 #include 22 #include 23 #include 24 #include 25 26 namespace ov { 27 namespace frontend { 28 namespace ggml { 29 namespace op { 30 31 OutputVector translate_set_rows(const NodeContext & context) { 32 num_inputs_check(context, 3, 3); 33 34 auto data = process_view_input_new(context, 0); 35 auto indices = process_view_input_new(context, 1); 36 auto dst = process_view_input_new(context, 2); 37 38 data = std::make_shared(data, context.get_output_type()); 39 40 const auto indices_shape = context.get_input_shape(1); 41 const bool multidim_indices = indices_shape.rank().is_static() && 42 indices_shape.rank().get_length() == 4 && 43 ((indices_shape[1].is_static() && indices_shape[1].get_length() > 1) || 44 (indices_shape[2].is_static() && indices_shape[2].get_length() > 1)); 45 46 auto axes = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {2}); 47 48 Output res; 49 if (context.is_stateful()) { 50 int concat_axis = 1; 51 int64_t dim2 = dst.get_partial_shape()[2].get_length(); 52 int64_t dim3 = dst.get_partial_shape()[3].get_length(); 53 data = std::make_shared( 54 data, ov::op::v0::Constant::create(ov::element::i64, {4}, {(int64_t) 1, (int64_t) -1, dim2, dim3}), false); 55 res = std::make_shared(OutputVector{dst, data}, concat_axis); 56 } else if (multidim_indices) { 57 auto updates_shape = std::make_shared(data, ov::element::i64); 58 59 auto indices_rank3 = std::make_shared( 60 indices, ov::op::v0::Constant::create(ov::element::i64, {1}, {0})); 61 auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1}); 62 auto indices_rank4_shape = std::make_shared(OutputVector{get_dimensions(updates_shape, {0, 1, 2}), one}, 0); 63 auto indices_rank4 = std::make_shared(indices_rank3, indices_rank4_shape, false); 64 auto broadcasted_indices = std::make_shared(indices_rank4, updates_shape); 65 66 res = std::make_shared(dst, broadcasted_indices, data, axes); 67 } else { 68 auto row_size = context.get_input_shape(2)[3].get_length(); 69 auto ind_squeezed = std::make_shared( 70 indices, ov::op::v0::Constant::create(ov::element::i64, {3}, {0, 1, 2})); 71 auto data_reshaped = std::make_shared( 72 data, 73 ov::op::v0::Constant::create(ov::element::i64, {4}, 74 {(int64_t) 1, (int64_t) 1, (int64_t) -1, (int64_t) row_size}), 75 false); 76 res = std::make_shared(dst, ind_squeezed, data_reshaped, axes); 77 } 78 79 auto dst_reshape = ov::as_type_ptr(dst.get_node_shared_ptr()); 80 if (!multidim_indices && dst_reshape) { 81 // Fix the case of multiple sequences, reshape back to original shape [1, n_seq, ctx_per_seq, emb] 82 // ctx_per_seq is not fixed due to llama-bench compatibility 83 auto dst_shape_partial = dst_reshape->get_input_partial_shape(0); 84 std::vector dst_shape = {dst_shape_partial[0].get_length(), dst_shape_partial[1].get_length(), 85 dst_shape_partial[2].is_static() ? dst_shape_partial[2].get_length() : -1, 86 dst_shape_partial[3].get_length()}; 87 res = std::make_shared(res, ov::op::v0::Constant::create(ov::element::i64, {4}, dst_shape), 88 false); 89 } 90 return rename_outputs_with_suffix({res}, context.get_name()); 91 } 92 93 } // namespace op 94 } // namespace ggml 95 } // namespace frontend 96 } // namespace ov