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/scale.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 / scale.cpp` 90 lines ยท 3641 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 25 namespace ov { 26 namespace frontend { 27 namespace ggml { 28 namespace op { 29 30 OutputVector translate_scale(const NodeContext & context) { 31 num_inputs_check(context, 1, 1); 32 33 float scale; 34 float bias; 35 memcpy(&scale, (float *) context.get_output_op_params() + 0, sizeof(float)); 36 memcpy(&bias, (float *) context.get_output_op_params() + 1, sizeof(float)); 37 38 auto scale_node = std::make_shared(ov::element::f32, ov::Shape{}, std::vector{scale}); 39 40 if (context.get_op_case() == 2) { 41 return {context.get_input(0)}; 42 } 43 44 if (context.get_op_case() == 1 && context.has_input("cache_rs_reset_len")) { 45 auto cache_rs_reset_idx = context.get_input("cache_rs_reset_idx"); 46 auto cache_rs_reset_len = context.get_input("cache_rs_reset_len"); 47 48 auto cache_rs = context.get_input(0); 49 50 auto cache_shape = std::make_shared(cache_rs, ov::element::i64); 51 auto n_slots_1d = std::make_shared( 52 cache_shape, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}), 53 ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0})); 54 auto n_slots = std::make_shared(n_slots_1d); 55 56 auto iota = std::make_shared( 57 ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}), n_slots, 58 ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {1}), ov::element::i64); 59 60 auto idx_plus_len = std::make_shared(cache_rs_reset_idx, cache_rs_reset_len); 61 auto less_than_idx = std::make_shared(iota, cache_rs_reset_idx); 62 auto greater_equal_idx_plus_len = std::make_shared(iota, idx_plus_len); 63 auto keep_mask = std::make_shared(less_than_idx, greater_equal_idx_plus_len); 64 65 auto keep_mask_f32 = std::make_shared(keep_mask, ov::element::f32); 66 auto keep_mask_reshape = std::make_shared( 67 keep_mask_f32, ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1})); 68 69 auto cleared_cache_rs = std::make_shared(cache_rs, keep_mask_reshape); 70 return rename_outputs_with_suffix({cleared_cache_rs}, context.get_name()); 71 } 72 73 auto scaled = std::make_shared(process_view_input_new(context, 0), scale_node); 74 75 std::shared_ptr res; 76 if (bias != 0.0f) { 77 auto bias_node = 78 std::make_shared(ov::element::f32, ov::Shape{}, std::vector{bias}); 79 res = std::make_shared(scaled, bias_node); 80 } else { 81 res = scaled; 82 } 83 84 return rename_outputs_with_suffix({res}, context.get_name()); 85 } 86 87 } // namespace op 88 } // namespace ggml 89 } // namespace frontend 90 } // namespace ov