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
2 changes: 1 addition & 1 deletion ggml/src/ggml-openvino/ggml-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ std::pair<ModelParams, ComputeParams> GgmlOvDecoder::compute_llm_params(ggml_cgr
model_params.head_size = cache_k_permute->ne[0];
model_params.n_heads_kv = cache_k_permute->ne[2];
compute_params.input_len = node->src[0]->ne[1];
compute_params.token_len_per_seq = node->ne[2];
compute_params.token_len_per_seq = node->src[0]->ne[1];

auto * cache_k_view = cache_k_permute->src[0];
if (cache_k_view->op != GGML_OP_VIEW) {
Expand Down
11 changes: 10 additions & 1 deletion ggml/src/ggml-openvino/openvino/op/rope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ OutputVector translate_rope(const NodeContext & context) {
if (context.get_input_size() == 3) {
rope_freqs_weight = context.get_input(2).get_node_shared_ptr();
}
auto sin_cos = make_sin_cos(op_params, inp_pos, rope_freqs_weight, mode == TYPE_IMROPE);
std::shared_ptr<ov::Node> token_len_per_seq;
if (context.has_input("token_len_per_seq")) {
token_len_per_seq = context.get_input("token_len_per_seq").get_node_shared_ptr();
}
auto sin_cos = make_sin_cos(op_params,
inp_pos,
rope_freqs_weight,
mode == TYPE_IMROPE,
false,
token_len_per_seq);
sin_theta_node = sin_cos.first;
cos_theta_node = sin_cos.second;
}
Expand Down
6 changes: 6 additions & 0 deletions ggml/src/ggml-openvino/openvino/translate_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void add_rope_sin_cos(TensorMap & tensor_map, GgmlDecoder & ggml_model_decoder)
if (ggml_model_decoder.has_mixed_rope_params()) {
return;
}
// Dynamic active-sequence slicing is reconstructed per ROPE node. Reusing a
// single shared rope_sin/rope_cos across the whole graph is unsafe here,
// because the graph-level inp_pos does not necessarily match each ROPE use.
if (tensor_map.find("seq_active_start") != tensor_map.end() && tensor_map.find("seq_active_end") != tensor_map.end()) {
return;
}
int32_t * rope_params = ggml_model_decoder.get_rope_params();
if (tensor_map.find("inp_pos") == tensor_map.end() || rope_params == nullptr) {
return;
Expand Down
10 changes: 9 additions & 1 deletion ggml/src/ggml-openvino/openvino/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ std::pair<ov::Output<Node>, ov::Output<Node>> make_sin_cos(int32_t * rope_params
std::shared_ptr<ov::Node> inp_pos,
std::shared_ptr<ov::Node> rope_freqs_weight,
bool imrope,
bool stateful) {
bool stateful,
std::shared_ptr<ov::Node> token_len_per_seq) {
if (stateful) {
inp_pos = std::make_shared<ov::op::v0::Squeeze>(inp_pos, ov::op::v0::Constant::create(ov::element::i64, {1}, {0}));
inp_pos = std::make_shared<ov::op::v0::Convert>(inp_pos, ov::element::f32);
Expand All @@ -140,6 +141,13 @@ std::pair<ov::Output<Node>, ov::Output<Node>> make_sin_cos(int32_t * rope_params
auto pos_perm =
std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 3, 1, 2});
inp_pos = std::make_shared<ov::op::v1::Transpose>(inp_pos, pos_perm);

if (!imrope && token_len_per_seq) {
auto zero = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
inp_pos = std::make_shared<ov::op::v8::Slice>(inp_pos, zero, token_len_per_seq, one, axis);
}
}

float freq_base;
Expand Down
3 changes: 2 additions & 1 deletion ggml/src/ggml-openvino/openvino/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ std::pair<ov::Output<Node>, ov::Output<Node>> make_sin_cos(int32_t* rope_params,
std::shared_ptr<ov::Node> inp_pos,
std::shared_ptr<ov::Node> rope_freqs_weight = nullptr,
bool imrope = false,
bool stateful = false);
bool stateful = false,
std::shared_ptr<ov::Node> token_len_per_seq = nullptr);

ov::Output<ov::Node> process_view_input(const NodeContext& context, int input_index, int slice_len = 0);

Expand Down
Loading