Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ggml/src/ggml-openvino/ggml-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ int GgmlOvDecoder::compute_op_case(const ggml_tensor * node) const {
}
op_case = 2;
}
{
auto * src = node->src[0];
if ((ggml_nelements(node) != ggml_nelements(src)) && m_naive) {
// Compare each dimension of node and src, if only one dimension differs then op_case=3
int diff_count = 0;
for (int i = 0; i < GGML_MAX_DIMS; i++) {
if (node->ne[i] != src->ne[i]) {
diff_count++;
}
}
if (diff_count == 1) {
op_case = 3;
}
}
}
break;
}
default:
Expand Down
36 changes: 35 additions & 1 deletion ggml/src/ggml-openvino/openvino/op/view.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../op_table.h"
#include "../utils.h"

#include <openvino/op/reshape.hpp>
namespace ov {
namespace frontend {
namespace ggml {
Expand All @@ -14,6 +14,40 @@ OutputVector translate_view(const NodeContext & context) {
return rename_outputs_with_suffix({process_view_input(context, 0, dst_shape[2] * dst_shape[3])},
context.get_name());
}
// op_case 3
if (context.get_op_case() == 3) {
auto input = context.get_input(0);
auto input_ov_shape = input.get_partial_shape();
std::cout << "Input " << " shape (OpenVINO): " << input_ov_shape << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging prints need to be removed before merge


auto input_llama_shape = context.get_input_shape(0).to_shape();
std::cout << "Input " << " shape (LLaMA): " << input_llama_shape << std::endl;

// if the input ov shape size is different from the input llama shape size, it means the input is already reshaped and we need to reshape it back to the original shape before slicing
if (input_ov_shape.size() != input_llama_shape.size()) {
input = std::make_shared<ov::op::v1::Reshape>(input, ov::op::v0::Constant::create(ov::element::i64, {input_llama_shape.size()}, input_llama_shape), false);
std::cout << "Input (reshaped)" << " shape (OpenVINO): " << input.get_partial_shape() << std::endl;
}

auto dst_shape = context.get_output_shape().to_shape();

// find the index of dst_shape that is different from input shape, and use that index to slice the input
int slice_dim = -1;
for (size_t i = 0; i < dst_shape.size(); ++i) {
if (dst_shape[i] != input_llama_shape[i]) {
slice_dim = i;
break;
}
}

auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {dst_shape[slice_dim]});
auto stride = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
auto axes = ov::op::v0::Constant::create(ov::element::i64, {1}, {slice_dim});
auto sliced = std::make_shared<ov::op::v8::Slice>(input, begin, end, stride, axes);
// print_shape(sliced, "Sliced");
return {sliced};
}
return {context.get_input(0)};
}

Expand Down
Loading