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/reshape.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 / reshape.cpp` 86 lines ยท 2817 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 15 namespace ov { 16 namespace frontend { 17 namespace ggml { 18 namespace op { 19 20 OutputVector translate_reshape(const NodeContext & context) { 21 num_inputs_check(context, 1, 1); 22 if (context.get_input(0).get_partial_shape().is_static() && 23 context.get_input_shape(0) == context.get_output_shape()) { 24 return {context.get_input(0)}; 25 } 26 27 const int op_case = context.get_op_case(); 28 const auto output_shape = context.get_output_shape().to_shape(); 29 std::vector shape(output_shape.begin(), output_shape.end()); 30 std::shared_ptr new_shape_node; 31 switch (op_case) { 32 case 0: 33 break; 34 case 1: 35 case 9: 36 shape[1] = -1; 37 if (context.is_stateful() && op_case == 1) { 38 shape.erase(shape.begin()); 39 } 40 break; 41 case 2: 42 case 3: 43 shape[2] = -1; 44 if (op_case == 3) { 45 shape[3] = 1; 46 } 47 break; 48 case 4: 49 return {context.get_input(0).get_node_shared_ptr()->input_value(0)}; 50 case 5: 51 case 7: 52 shape = {1, 1, -1, shape[3]}; 53 if (context.is_stateful() && op_case == 5) { 54 shape.erase(shape.begin()); 55 } 56 break; 57 case 6: 58 // Recurrent inputs keep the active sequence count separate from the token count. 59 if (context.has_input("s_copy_active_slot_len")) { 60 auto n_slot_active_len = context.get_input("s_copy_active_slot_len"); 61 auto emb_size = ov::op::v0::Constant::create(ov::element::i64, {1}, {shape[3]}); 62 auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1}); 63 auto neg_one = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}); 64 new_shape_node = 65 std::make_shared(ov::OutputVector{one, n_slot_active_len, neg_one, emb_size}, 0); 66 } else { 67 shape = {1, 1, -1, shape[3]}; 68 } 69 break; 70 case 8: 71 shape[0] = -1; 72 break; 73 default: 74 FRONT_END_OP_CONVERSION_CHECK(false, "Unsupported RESHAPE case: ", op_case); 75 } 76 if (!new_shape_node) { 77 new_shape_node = ov::op::v0::Constant::create(ov::element::i64, {shape.size()}, shape); 78 } 79 auto res = std::make_shared(context.get_input(0), new_shape_node, false); 80 return rename_outputs_with_suffix({res}, context.get_name()); 81 } 82 83 } // namespace op 84 } // namespace ggml 85 } // namespace frontend 86 } // namespace ov