9789c4ecdc
* Update build doc * Add cgraph tensor output name to OV op name * Update openvino build instructions * Add initial NPU support * draft NPU support version 2: prefill + kvcache * NPU support version 2: prefill + kvcache * Change due to ggml cgraph changes, not correct yet * Change due to ggml cgraph changes, llama-3.2 CPU work * Add AMD64 to CMakeLists * Change due to ggml cgraph changes, all device work * Refactor: clean, fix warning * Update clang-format * Statful transformation for CPU GPU * Add SwiGLU * Fuse to SDPA * Replace Concat with Broadcast in MulMat for GQA * Pull out indices creation for kv cache update * Refactor: remove past_token_len from extra_inputs * Fix Phi3 SwiGLU and SoftMax * Pull out sin cos from rope * Reduce memory: free ov weights node after graph conversion * Fix CPY due to cgraph change * Added OpenVINO CI/CD. Updated docs * Fix llama-cli * Fix Phi3 ROPE; Add test-backend-ops * Fix NPU * Fix llama-bench; Clang-format * Fix llama-perplexity * temp. changes for mark decomp * matmul in fp32 * mulmat input conversion fix * mulmat type conversion update * add mark decomp pass * Revert changes in fuse_to_sdpa * Update build.md * Fix test-backend-ops * Skip test-thread-safety; Run ctest only in ci/run.sh * Use CiD for NPU * Optimize tensor conversion, improve TTFT * Support op SET_ROWS * Fix NPU * Remove CPY * Fix test-backend-ops * Minor updates for raising PR * Perf: RMS fused to OV internal RMS op * Fix after rebasing - Layout of cache k and cache v are unified: [seq, n_head, head_size] - Add CPY and FLASH_ATTN_EXT, flash attn is not used yet - Skip test-backend-ops due to flash attn test crash - Add mutex around graph conversion to avoid test-thread-safety fali in the future - Update NPU config - Update GPU config to disable SDPA opt to make phi-3 run * Change openvino device_type to GPU; Enable flash_attn * Update supports_buft and supports_op for quantized models * Add quant weight conversion functions from genai gguf reader * Quant models run with accuracy issue * Fix accuracy: disable cpu_repack * Fix CI; Disable test-backend-ops * Fix Q4_1 * Fix test-backend-ops: Treat quantized tensors as weights * Add NPU Q4_0 support * NPU perf: eliminate zp * Dequantize q4_1 q4_k q6_k for NPU * Add custom quant type: q8_1_c, q4_0_128 * Set m_is_static=false as default in decoder * Simpilfy translation of get_rows * Fix after rebasing * Improve debug util; Eliminate nop ReshapeReshape * STYLE: make get_types_to_requant a function * Support BF16 model * Fix NPU compile * WA for npu 1st token acc issue * Apply EliminateZP only for npu * Add GeGLU * Fix Hunyuan * Support iSWA * Fix NPU accuracy * Fix ROPE accuracy when freq_scale != 1 * Minor: not add attention_size_swa for non-swa model * Minor refactor * Add Q5_K to support phi-3-q4_k_m * Requantize Q6_K (gs16) to gs32 on GPU * Fix after rebasing * Always apply Eliminate_ZP to fix GPU compile issue on some platforms * kvcachefusion support * env variable GGML_OPENVINO_DISABLE_SDPA_OPTIMIZATION added * Fix for Phi3 * Fix llama-cli (need to run with --no-warmup) * Fix add_sliced_mask; Revert mulmat, softmax; Remove input attention_size, iSWA model not working * fix after rebasing * Fix llama-3-8b and phi3-mini q4_0 NPU * Update to OV-2025.3 and CMakeLists.txt * Add OV CI cache * Apply CISC review and update CI to OV2025.3 * Update CI to run OV dep install before build * Update OV dockerfile to use OV2025.3 and update build docs * Style: use switch in supports_ops * Style: middle ptr and ref align, omit optional struct keyword * NPU Unify PD (#14) * Stateless. Fix llama-cli llama-server * Simplify broadcast op in attention * Replace get_output_tensor+memcpy with set_output_tensor * NPU unify PD. Unify dynamic and static dims * Clean placeholders in ggml-openvino.cpp * NPU unify PD (handled internally) * change graph to 4d, support multi sequences * Fix llama-bench * Fix NPU * Update ggml-decoder.cpp Hitting error while compiling on windows: error C3861: 'unsetenv': identifier not found Reason: unsetenv() is a POSIX function; it doesn’t exist on Windows. Visual Studio (MSVC) won’t recognize it. Proposed fix: Use _putenv_s() (Windows equivalent) This is supported by MSVC and achieves the same effect: it removes the environment variable from the process environment. This keeps cross-platform compatibility. * Update ggml-decoder.cpp * Update ggml-decoder.cpp * Update ggml-decoder.cpp * Update ggml-decoder.cpp * Update ggml-decoder.cpp * Remove the second decoder for node. Moving the function into the model decoder * Fix error for naive * NPU prefill chunking * NPU fix llama-bench * fallback naive run with accuracy issue * NPU support llma-perplexity -b 512 --no-warmup * Refactor: split ov_graph_compute for dynamic and static * remove unused API GgmlOvDecoder::get_output_stride(const std::string & name) * minor update due to ov 2025.4 * remove unused API GgmlOvDecoder::get_output_names() * remove unused API get_output_shape(const std::string & name) * Modified API GgmlOvDecoder::get_output_type(const std::string & name) * Removed API GgmlOvDecoder::get_output_op_params(const std::string & name) * Removed API get_output_ggml_tensor(const std::string & name) * Removed API m_outputs * Removed m_output_names * Removed API GgmlOvDecoder::get_input_names() * Removed API GgmlOvDecoder::get_input_stride(const std::string& name) * Removed API get_input_type * Removed API get_input_type * Removed API GgmlOvDecoder::get_input_shape(const std::string & name) * Removed API GgmlOvDecoder::get_input_op_params(const std::string & name) * Fix error for decoder cache * Reuse cached decoder * GPU remove Q6_K requantization * NPU fix wrong model output shape * NPU fix q4 perf regression * Remove unused variable nodes * Fix decoder can_reuse for llama-bench * Update build.md for Windows * backend buffer: allocate on host * Use shared_buffer for GPU NPU; Refactor * Add ov_backend_host_buffer; Use cached remote context * Put kvcache on GPU * Use ggml_aligned_malloc * only use remote tensor for kvcache * only use remote tensor for kvcache for GPU * FIX: use remote tensor from singleton * Update build.md to include OpenCL * NPU always requant to q4_0_128 * Optimize symmetric quant weight extraction: use single zp * Use Q8_0_C in token embd, lm_head, and for 5 and 6 bits quant * Update build.md * Support -ctk f32 * Initial stateful graph support * Update ggml/src/ggml-openvino/ggml-decoder.cpp Co-authored-by: Yamini Nimmagadda <yamini.nimmagadda@intel.com> * code cleanup * npu perf fix * requant to f16 for Q6 embed on NPU * Update ggml/src/ggml-openvino/ggml-decoder.cpp * Update ggml/src/ggml-openvino/ggml-openvino-extra.cpp * Create OPENVINO.md in llama.cpp backend docs * Update OPENVINO.md * Update OPENVINO.md * Update OPENVINO.md * Update build.md * Update OPENVINO.md * Update OPENVINO.md * Update OPENVINO.md * kq_mask naming fix * Syntax correction for workflows build file * Change ov backend buffer is_host to false * Fix llama-bench -p -n where p<=256 * Fix --direct-io 0 * Don't put kvcache on GPU in stateful mode * Remove hardcode names * Fix stateful shapes * Simplification for stateful and update output shape processing * Remove hardcode names * Avoid re-compilation in llama-bench * Extract zp directly instead of bias * Refactor weight tensor processing * create_weight_node accept non-ov backend buffer * remove changes in llama-graph.cpp * stateful masking fix (#38) Fix for stateful accuracy issues and cl_out_of_resources error in stateful GPU with larger context sizes. * Fix test-backend-ops crash glu, get_rows, scale, rms_norm, add * hardcoded name handling for rope_freqs.weight * Suppress logging and add error handling to allow test-backend-ops to complete * Fix MUL_MAT with broadcast; Add unsupported MUL_MAT FLASH_ATTN cases * Use bias instead of zp in test-backend-ops * Update OV in CI, Add OV CI Tests in GH Actions * Temp fix for multithreading bug * Update OV CI, fix review suggestions. * fix editorconfig-checker, update docs * Fix tabs to spaces for editorconfig-checker * fix editorconfig-checker * Update docs * updated model link to be GGUF model links * Remove GGML_CPU_REPACK=OFF * Skip permuted ADD and MUL * Removed static variables from utils.cpp * Removed initializing non-existing variable * Remove unused structs * Fix test-backend-ops for OV GPU * unify api calling * Update utils.cpp * When the dim is dynamic, throw an error, need to is stastic forst * Add interface compute_model_outputs(), which get the model output through computing the node use count & status in the cgraph to avoid the flag using * No need to return * Fix test-backend-ops for OV GPU LNL * Fix test-thread-safety * use the shape from infer request of output tensor create to avoid issue * fix dynamic output shape issue * fix issue for the unused node in tests * Remove unused lock * Add comment * Update openvino docs * update to OV release version 2026.0 * add ci ov-gpu self hosted runner * fix editorconfig * Fix perplexity * Rewrite the model inputs finding mechanism (#54) * Rewrite the model inputs finding logistic * Put stateful shape handle in get input shape * Put the iteration logistic in func * Added ggml-ci-intel-openvino-gpu and doc update * .hpp files converted to .h * fix ggml-ci-x64-intel-openvino-gpu * Fix for stateful execution bug in llama-bench * Minor updates after stateful llama-bench fix * Update ggml/src/ggml-openvino/utils.cpp Co-authored-by: Yamini Nimmagadda <yamini.nimmagadda@intel.com> * Remove multiple get_shape calls * Bring back mutex into compute * Fix VIEW op, which slice the input node * Added token_len_per_seq existence check before slicing masks and moved node retrieval inside guarded block to prevent missing-key access * Temp. fix for test requant errors * Update to OV ggml-ci to low-perf * ci : temporary disable "test-llama-archs" * ci : cache v4 -> v5, checkout v4 -> v6, fix runner tag * docs : update url * Fix OV link in docker and Update docs --------- Co-authored-by: Ravi Panchumarthy <ravi.panchumarthy@intel.com> Co-authored-by: Cavus Mustafa <mustafa.cavus@intel.com> Co-authored-by: Arshath <arshath.ramzan@intel.com> Co-authored-by: XuejunZhai <Xuejun.Zhai@intel.com> Co-authored-by: Yamini Nimmagadda <yamini.nimmagadda@intel.com> Co-authored-by: Xuejun Zhai <Xuejun.Zhai@intel> Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
294 lines
13 KiB
C++
294 lines
13 KiB
C++
#include "translate_session.h"
|
|
|
|
#include "ggml-openvino/openvino/node_context.h"
|
|
#include "ggml-openvino/openvino/utils.h"
|
|
#include "input_model.h"
|
|
#include "pass/eliminate_zp.h"
|
|
#include "pass/mark_decompression_convert_constant_folding.h"
|
|
#include "pass/squeeze_matmul.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <openvino/core/node.hpp>
|
|
#include <openvino/op/add.hpp>
|
|
#include <openvino/op/broadcast.hpp>
|
|
#include <openvino/op/concat.hpp>
|
|
#include <openvino/op/convert.hpp>
|
|
#include <openvino/op/convert_like.hpp>
|
|
#include <openvino/op/cos.hpp>
|
|
#include <openvino/op/divide.hpp>
|
|
#include <openvino/op/gather.hpp>
|
|
#include <openvino/op/multiply.hpp>
|
|
#include <openvino/op/parameter.hpp>
|
|
#include <openvino/op/range.hpp>
|
|
#include <openvino/op/reshape.hpp>
|
|
#include <openvino/op/result.hpp>
|
|
#include <openvino/op/sin.hpp>
|
|
#include <openvino/op/slice.hpp>
|
|
#include <openvino/op/squeeze.hpp>
|
|
#include <openvino/op/strided_slice.hpp>
|
|
#include <openvino/op/transpose.hpp>
|
|
#include <openvino/op/unsqueeze.hpp>
|
|
#include <openvino/pass/constant_folding.hpp>
|
|
#include <openvino/pass/make_stateful.hpp>
|
|
#include <openvino/core/preprocess/pre_post_process.hpp>
|
|
|
|
namespace ov {
|
|
namespace frontend {
|
|
namespace ggml {
|
|
|
|
using namespace ov::op;
|
|
|
|
namespace {
|
|
|
|
ov::pass::MakeStateful::ParamResPairs get_kv_param_res_pairs(
|
|
const std::shared_ptr<ov::Model> & model,
|
|
const std::map<std::string, std::string> & kv_param_res_names) {
|
|
ov::pass::MakeStateful::ParamResPairs pairs;
|
|
const auto & params = model->get_parameters();
|
|
const auto & results = model->get_results();
|
|
|
|
for (const auto & param_res : kv_param_res_names) {
|
|
const auto & param_name = param_res.first;
|
|
const auto & res_name = param_res.second;
|
|
|
|
auto param_it = std::find_if(params.begin(), params.end(), [&](const std::shared_ptr<v0::Parameter> & node) {
|
|
return node->get_friendly_name() == param_name;
|
|
});
|
|
|
|
OPENVINO_ASSERT(param_it != params.end(), "The tensor name ", param_name,
|
|
" is not associated with any of "
|
|
"Parameters in the network.");
|
|
|
|
auto res_it = std::find_if(results.begin(), results.end(), [&](const std::shared_ptr<v0::Result> & node) {
|
|
return node->get_friendly_name() == res_name;
|
|
});
|
|
|
|
OPENVINO_ASSERT(res_it != results.end(), "The tensor name ", res_name,
|
|
" is not associated with any of "
|
|
"Results in the network.");
|
|
|
|
std::shared_ptr<ov::op::v0::Parameter> param = *param_it;
|
|
std::shared_ptr<ov::op::v0::Result> res = *res_it;
|
|
pairs.emplace_back(param, res);
|
|
}
|
|
return pairs;
|
|
}
|
|
|
|
void add_sliced_mask(TensorMap & tensor_map, GgmlDecoder & ggml_model_decoder) {
|
|
|
|
auto create_sliced_mask = [&](const std::string & mask_name, const std::string & sliced_name, bool is_static) {
|
|
if ((tensor_map.find(mask_name) != tensor_map.end()) &&
|
|
(tensor_map.find("token_len_per_seq") != tensor_map.end())) {
|
|
auto token_len_per_seq = tensor_map.at("token_len_per_seq").get_node_shared_ptr();
|
|
auto mask = tensor_map.at(mask_name).get_node_shared_ptr();
|
|
std::shared_ptr<ov::Node> mask_sliced;
|
|
if (is_static) {
|
|
mask_sliced = mask;
|
|
} else if (ggml_model_decoder.is_stateful()) {
|
|
auto zero_2d = ov::op::v0::Constant::create(ov::element::i64, {2}, {0,0});
|
|
auto one_2d = ov::op::v0::Constant::create(ov::element::i64, {2}, {1,1});
|
|
auto zero_1d = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
|
|
auto three_1d = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});
|
|
auto neg_one_1d = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
|
|
auto axes = ov::op::v0::Constant::create(ov::element::i64, {2}, {-2,-1});
|
|
auto inp_pos = tensor_map.at("inp_pos").get_node_shared_ptr();
|
|
auto gather_inp_pos = std::make_shared<ov::op::v8::Gather>(inp_pos, neg_one_1d, three_1d);
|
|
auto reshaped_inp_pos = std::make_shared<ov::op::v1::Reshape>(gather_inp_pos, ov::op::v0::Constant::create(ov::element::i64, {1}, {1}), false);
|
|
auto inp_pos_incremented = std::make_shared<ov::op::v1::Add>(reshaped_inp_pos, ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}));
|
|
auto stop = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{token_len_per_seq, std::make_shared<v1::ConvertLike>(inp_pos_incremented, token_len_per_seq)}, 0);
|
|
mask_sliced =
|
|
std::make_shared<ov::op::v8::Slice>(mask, zero_2d, stop, one_2d, axes);
|
|
mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, ov::element::f16);
|
|
mask_sliced->set_friendly_name(sliced_name);
|
|
} else {
|
|
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 two = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});
|
|
mask_sliced = std::make_shared<ov::op::v8::Slice>(mask, zero, token_len_per_seq, one, two);
|
|
mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, ov::element::f16);
|
|
mask_sliced->set_friendly_name(sliced_name);
|
|
}
|
|
tensor_map.insert({sliced_name, mask_sliced->output(0)});
|
|
}
|
|
};
|
|
|
|
create_sliced_mask("self_kq_mask", "KQ_mask_sliced", ggml_model_decoder.is_static());
|
|
create_sliced_mask("self_kq_mask_swa", "KQ_mask_swa_sliced", ggml_model_decoder.is_static());
|
|
}
|
|
|
|
void add_rope_sin_cos(TensorMap & tensor_map, GgmlDecoder & ggml_model_decoder) {
|
|
int32_t * rope_params = ggml_model_decoder.get_rope_params();
|
|
if (tensor_map.find("inp_pos") == tensor_map.end() || rope_params == nullptr) {
|
|
return;
|
|
}
|
|
auto inp_pos = tensor_map.at("inp_pos").get_node_shared_ptr();
|
|
std::shared_ptr<ov::Node> rope_freqs_weight;
|
|
if (tensor_map.find("rope_freqs.weight") != tensor_map.end()) {
|
|
rope_freqs_weight = tensor_map.at("rope_freqs.weight").get_node_shared_ptr();
|
|
}
|
|
|
|
auto sin_cos = make_sin_cos(rope_params, inp_pos, rope_freqs_weight);
|
|
auto sin_theta = sin_cos.first;
|
|
auto cos_theta = sin_cos.second;
|
|
|
|
cos_theta.get_node_shared_ptr()->set_friendly_name("rope_cos");
|
|
sin_theta.get_node_shared_ptr()->set_friendly_name("rope_sin");
|
|
tensor_map.insert({"rope_cos", cos_theta});
|
|
tensor_map.insert({"rope_sin", sin_theta});
|
|
}
|
|
|
|
// Create common patterns
|
|
void preprocess(TensorMap & tensor_map, GgmlDecoder & ggml_model_decoder) {
|
|
add_sliced_mask(tensor_map, ggml_model_decoder);
|
|
add_rope_sin_cos(tensor_map, ggml_model_decoder);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TranslateSession::TranslateSession(const frontend::InputModel::Ptr & input_model,
|
|
const std::unordered_map<std::string, CreatorFunction> & translator_map,
|
|
bool naive) :
|
|
m_input_model(input_model),
|
|
m_translator_map(translator_map),
|
|
m_ov_model(nullptr),
|
|
m_naive(naive) {}
|
|
|
|
std::shared_ptr<Model> TranslateSession::get_converted_model() {
|
|
if (m_ov_model) {
|
|
return m_ov_model;
|
|
}
|
|
m_ov_model = translate_graph(m_input_model);
|
|
return m_ov_model;
|
|
}
|
|
|
|
std::shared_ptr<Model> TranslateSession::translate_graph(const frontend::InputModel::Ptr & input_model) {
|
|
ov::ParameterVector params;
|
|
ov::ResultVector results;
|
|
auto tensor_map = std::make_shared<TensorMap>();
|
|
std::shared_ptr<Model> resulting_model;
|
|
|
|
const auto & ggml_model = std::dynamic_pointer_cast<InputModel>(input_model);
|
|
std::shared_ptr<GgmlDecoder> ggml_model_decoder = ggml_model->get_model_decoder();
|
|
|
|
for (const auto & it : ggml_model_decoder->get_model_inputs()) {
|
|
params.push_back(std::dynamic_pointer_cast<ov::op::v0::Parameter>(it.second));
|
|
(*tensor_map)[it.first] = it.second;
|
|
}
|
|
|
|
for (const auto & it : ggml_model_decoder->get_model_extra_inputs()) {
|
|
if (std::dynamic_pointer_cast<ov::op::v0::Parameter>(it.second)) {
|
|
params.push_back(std::dynamic_pointer_cast<ov::op::v0::Parameter>(it.second));
|
|
}
|
|
(*tensor_map)[it.first] = it.second;
|
|
}
|
|
|
|
for (const auto & it : ggml_model_decoder->get_model_weights()) {
|
|
(*tensor_map)[it.first] = it.second;
|
|
}
|
|
|
|
auto node_visitor = [&](std::shared_ptr<GgmlDecoder> decoder, int node_idx) {
|
|
auto operation_type = decoder->get_op_type(node_idx);
|
|
if (operation_type == "GGML_OP_NONE") {
|
|
return;
|
|
}
|
|
|
|
ov::OutputVector converted_outputs;
|
|
auto it = m_translator_map.find(operation_type);
|
|
FRONT_END_OP_CONVERSION_CHECK(it != m_translator_map.end(), "Translation for operation type ", operation_type,
|
|
" is not implemented.");
|
|
NodeContext node_context(decoder, tensor_map, node_idx, this);
|
|
converted_outputs = it->second(node_context);
|
|
|
|
const auto & node_output_names = decoder->get_output_names(node_idx);
|
|
FRONT_END_OP_CONVERSION_CHECK(node_output_names.size() == converted_outputs.size(), "Number of ",
|
|
operation_type, " outputs greater than number of converted outputs, which are ",
|
|
node_output_names.size(), " and ", converted_outputs.size(), " respectively.");
|
|
|
|
for (size_t i = 0; i < node_output_names.size(); ++i) {
|
|
auto output_name = node_output_names[i];
|
|
if (i < converted_outputs.size() && converted_outputs[i].get_node_shared_ptr() != nullptr) {
|
|
(*tensor_map)[output_name] = converted_outputs[i];
|
|
}
|
|
}
|
|
};
|
|
|
|
if (!m_naive) {
|
|
preprocess(*tensor_map, *ggml_model_decoder);
|
|
}
|
|
ggml_model_decoder->visit_subgraph(node_visitor);
|
|
|
|
for (const auto & name : ggml_model_decoder->get_model_output_names()) {
|
|
FRONT_END_GENERAL_CHECK(tensor_map->find(name) != tensor_map->end(),
|
|
"Output name not found in tensor map: ", name);
|
|
auto result = std::make_shared<v0::Result>(tensor_map->at(name));
|
|
result->set_friendly_name(name);
|
|
results.push_back(result);
|
|
}
|
|
|
|
ov::ParameterVector used_params;
|
|
for (const auto & param : params) {
|
|
if (!param->output(0).get_target_inputs().empty()) {
|
|
used_params.push_back(param);
|
|
}
|
|
}
|
|
// if (auto diff = params.size() - used_params.size()) {
|
|
// GGML_LOG_INFO("%zu parameters are not used in the model.", diff);
|
|
// }
|
|
resulting_model = std::make_shared<Model>(results, used_params);
|
|
|
|
apply_transformations(resulting_model);
|
|
return resulting_model;
|
|
}
|
|
|
|
std::shared_ptr<Model> TranslateSession::apply_transformations(std::shared_ptr<Model> model) {
|
|
auto ggml_model_decoder = std::dynamic_pointer_cast<InputModel>(m_input_model)->get_model_decoder();
|
|
{
|
|
ov::pass::Manager manager;
|
|
manager.set_per_pass_validation(true);
|
|
manager.register_pass<ov::pass::MarkCompressedFloatConstants>();
|
|
|
|
if (ggml_model_decoder->is_stateful()) {
|
|
const auto kv_param_res_names = ggml_model_decoder->get_kv_param_res_names();
|
|
const auto kv_param_res_pairs = get_kv_param_res_pairs(model, kv_param_res_names);
|
|
manager.register_pass<ov::pass::MakeStateful>(kv_param_res_pairs);
|
|
}
|
|
|
|
if (ggml_model_decoder->is_static()) {
|
|
manager.register_pass<pass::EliminateZeroPoints>();
|
|
manager.register_pass<pass::SqueezeMatmul>();
|
|
}
|
|
manager.run_passes(model);
|
|
if (ggml_model_decoder->is_stateful()) {
|
|
auto output_names = ggml_model_decoder->get_model_output_names();
|
|
std::map<std::string, int> model_output_indexes;
|
|
for (size_t i=0; i<output_names.size(); i++) {
|
|
model_output_indexes.insert(std::make_pair(output_names[i], i));
|
|
}
|
|
ov::preprocess::PrePostProcessor ppp(model);
|
|
for (size_t i=0; i<model->get_output_size(); i++) {
|
|
auto output_friendly_name = model->output(i).get_node_shared_ptr()->get_friendly_name();
|
|
auto output_id = model_output_indexes[output_friendly_name];
|
|
auto model_output_shape = model->output(i).get_partial_shape();
|
|
auto decoder_output_shape = ggml_model_decoder->get_output_shape(output_id);
|
|
if (model_output_shape.rank().is_static() && decoder_output_shape.rank().is_static()
|
|
&& model_output_shape.rank().get_length() + 1 == decoder_output_shape.rank().get_length()
|
|
&& decoder_output_shape[0].is_static() && decoder_output_shape[0].get_length() == 1) {
|
|
ppp.output(i).postprocess().custom([](const ov::Output<ov::Node>& node) {
|
|
auto axes = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {0});
|
|
return std::make_shared<ov::op::v0::Unsqueeze>(node, axes);
|
|
});
|
|
}
|
|
}
|
|
model = ppp.build();
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
|
|
} // namespace ggml
|
|
} // namespace frontend
|
|
} // namespace ov
|