forked from ggml-org/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 7
Enhance OpenVINO backend with view operations and new ops #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhaixuejun1993
wants to merge
6
commits into
ravi9:dev_backend_openvino
Choose a base branch
from
zhaixuejun1993:xuejun/enable_ops
base: dev_backend_openvino
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae2c12d
OpenVINO backend: enable get_rows with view
zhaixuejun1993 b44bfbc
OpenVINO backend: enable view + norm/rms_norm
zhaixuejun1993 45a401c
OpenVINO backend: concat op
zhaixuejun1993 49b57ae
OpenVINO backend: argsort op
zhaixuejun1993 c935097
OpenVINO backend: enable unary + view & GGML_UNARY_OP_SOFTPLUS
zhaixuejun1993 514f868
Fix issue for test-backend-ops in TOPK_MOE, which compare VIEW ops re…
zhaixuejun1993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include "../node_context.h" | ||
| #include "../op_table.h" | ||
| #include "../utils.h" | ||
| #include "ggml.h" | ||
|
|
||
| #include <openvino/frontend/exception.hpp> | ||
| #include <openvino/op/constant.hpp> | ||
| #include <openvino/op/squeeze.hpp> | ||
| #include <openvino/op/topk.hpp> | ||
|
|
||
| namespace ov { | ||
| namespace frontend { | ||
| namespace ggml { | ||
| namespace op { | ||
|
|
||
| OutputVector translate_argsort(const NodeContext & context) { | ||
| num_inputs_check(context, 1, 1); | ||
|
|
||
| auto input = process_view_input_new(context, 0); | ||
|
|
||
| const int32_t order = context.get_output_op_params()[0]; | ||
|
|
||
| ov::op::v11::TopK::Mode mode; | ||
| switch (order) { | ||
| case GGML_SORT_ORDER_ASC: | ||
| mode = ov::op::v11::TopK::Mode::MIN; | ||
| break; | ||
| case GGML_SORT_ORDER_DESC: | ||
| mode = ov::op::v11::TopK::Mode::MAX; | ||
| break; | ||
| default: | ||
| FRONT_END_OP_CONVERSION_CHECK(false, "Unsupported GGML_OP_ARGSORT order: ", order); | ||
| } | ||
|
|
||
| auto k = std::make_shared<ov::op::v0::Squeeze>(get_dimensions(input.get_node_shared_ptr(), {3}), | ||
| ov::op::v0::Constant::create(ov::element::i64, {1}, {0})); | ||
|
|
||
| auto topk = std::make_shared<ov::op::v11::TopK>(input, | ||
| k, | ||
| 3, | ||
| mode, | ||
| ov::op::v11::TopK::SortType::SORT_VALUES, | ||
| context.get_output_type(), | ||
| false); | ||
|
|
||
| return rename_outputs_with_suffix({topk->output(1)}, context.get_name()); | ||
| } | ||
|
|
||
| } // namespace op | ||
| } // namespace ggml | ||
| } // namespace frontend | ||
| } // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include "../node_context.h" | ||
| #include "../op_table.h" | ||
| #include "../utils.h" | ||
|
|
||
| #include <memory> | ||
| #include <openvino/frontend/exception.hpp> | ||
| #include <openvino/op/concat.hpp> | ||
| #include <openvino/op/convert.hpp> | ||
|
|
||
| namespace ov { | ||
| namespace frontend { | ||
| namespace ggml { | ||
| namespace op { | ||
|
|
||
| OutputVector translate_concat(const NodeContext & context) { | ||
| num_inputs_check(context, 2, 2); | ||
|
|
||
| const int32_t * op_params = context.get_output_op_params(); | ||
| FRONT_END_CHECK_IMPLEMENTED(op_params != nullptr, "CONCAT requires output op params"); | ||
|
|
||
| const auto output_shape = context.get_output_shape(); | ||
| FRONT_END_CHECK_IMPLEMENTED(output_shape.rank().is_static(), "CONCAT requires static output rank"); | ||
|
|
||
| const auto rank = output_shape.rank().get_length(); | ||
| const int32_t ggml_dim = op_params[0]; | ||
| FRONT_END_CHECK_IMPLEMENTED(ggml_dim >= 0 && ggml_dim < rank, "CONCAT axis is out of range"); | ||
|
|
||
| auto input_0 = process_view_input_new(context, 0); | ||
| auto input_1 = process_view_input_new(context, 1); | ||
| const auto output_type = context.get_output_type(); | ||
|
|
||
| if (input_0.get_element_type() != output_type) { | ||
| input_0 = std::make_shared<ov::op::v0::Convert>(input_0, output_type); | ||
| } | ||
| if (input_1.get_element_type() != output_type) { | ||
| input_1 = std::make_shared<ov::op::v0::Convert>(input_1, output_type); | ||
| } | ||
|
|
||
| const auto axis = static_cast<int64_t>(rank - 1 - ggml_dim); | ||
| auto res = std::make_shared<ov::op::v0::Concat>(OutputVector{input_0, input_1}, axis); | ||
|
|
||
| return rename_outputs_with_suffix({res}, context.get_name()); | ||
| } | ||
|
|
||
| } // namespace op | ||
| } // namespace ggml | ||
| } // namespace frontend | ||
| } // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "../node_context.h" | ||
| #include "../op_table.h" | ||
| #include "../utils.h" | ||
|
|
||
| #include <openvino/op/abs.hpp> | ||
| #include <openvino/op/add.hpp> | ||
| #include <openvino/op/constant.hpp> | ||
| #include <openvino/op/exp.hpp> | ||
| #include <openvino/op/log.hpp> | ||
| #include <openvino/op/negative.hpp> | ||
| #include <openvino/op/relu.hpp> | ||
|
|
||
| namespace ov { | ||
| namespace frontend { | ||
| namespace ggml { | ||
| namespace op { | ||
|
|
||
| OutputVector translate_unary_softplus(const NodeContext & context) { | ||
| num_inputs_check(context, 1, 1); | ||
|
|
||
| auto input = process_view_input_new(context, 0); | ||
| const auto element_type = input.get_element_type(); | ||
| auto one = ov::op::v0::Constant::create(element_type, ov::Shape{}, {1.0f}); | ||
|
|
||
| auto positive = std::make_shared<ov::op::v0::Relu>(input); | ||
| auto abs = std::make_shared<ov::op::v0::Abs>(input); | ||
| auto neg_abs = std::make_shared<ov::op::v0::Negative>(abs); | ||
| auto exp_neg_abs = std::make_shared<ov::op::v0::Exp>(neg_abs); | ||
| auto log_term = std::make_shared<ov::op::v0::Log>(std::make_shared<ov::op::v1::Add>(one, exp_neg_abs)); | ||
| auto res = std::make_shared<ov::op::v1::Add>(positive, log_term); | ||
|
|
||
| return rename_outputs_with_suffix({res}, context.get_name()); | ||
| } | ||
|
|
||
| } // namespace op | ||
| } // namespace ggml | ||
| } // namespace frontend | ||
| } // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this? Hardcoding backend-specific checks for OpenVino into the GGML code isn't ideal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can not avoid, the VIEW op is handled in following node, which can be fused maybe, so can not compare, it has to be isolated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it required for a model support or unit test currently?