|
| 1 | +// Copyright (C) 2024 Intel Corporation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#ifndef LLAMA_CPP_COMPILED_MODEL_HPP |
| 5 | +#define LLAMA_CPP_COMPILED_MODEL_HPP |
| 6 | + |
| 7 | +#include "llama.h" |
| 8 | +#include "openvino/runtime/icompiled_model.hpp" |
| 9 | +#include "openvino/runtime/isync_infer_request.hpp" |
| 10 | + |
| 11 | +namespace ov { |
| 12 | +namespace llama_cpp_plugin { |
| 13 | +class LlamaCppSyncInferRequest; |
| 14 | +class LlamaCppPlugin; |
| 15 | +class LlamaCppState; |
| 16 | +class LlamaCppModel : public ICompiledModel { |
| 17 | +public: |
| 18 | + LlamaCppModel(const std::string& gguf_fname, const std::shared_ptr<const IPlugin>& plugin, size_t num_threads = 0); |
| 19 | + /** |
| 20 | + * @brief Export compiled model to stream |
| 21 | + * |
| 22 | + * @param model output stream |
| 23 | + */ |
| 24 | + virtual void export_model(std::ostream& model) const override; |
| 25 | + |
| 26 | + /** |
| 27 | + * @brief Returns runtime model |
| 28 | + * |
| 29 | + * @return OpenVINO Model which represents runtime graph |
| 30 | + */ |
| 31 | + virtual std::shared_ptr<const ov::Model> get_runtime_model() const override; |
| 32 | + |
| 33 | + /** |
| 34 | + * @brief Allows to set property |
| 35 | + * |
| 36 | + * @param properties new plugin properties |
| 37 | + */ |
| 38 | + virtual void set_property(const ov::AnyMap& properties) override; |
| 39 | + |
| 40 | + /** |
| 41 | + * @brief Returns property |
| 42 | + * |
| 43 | + * @param name Property name |
| 44 | + * |
| 45 | + * @return Property value |
| 46 | + * virtual std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override; |
| 47 | + **/ |
| 48 | + virtual ov::Any get_property(const std::string& name) const override; |
| 49 | + virtual const std::vector<ov::Output<const ov::Node>>& inputs() const override; |
| 50 | + virtual const std::vector<ov::Output<const ov::Node>>& outputs() const override; |
| 51 | + virtual ~LlamaCppModel(); |
| 52 | + |
| 53 | +protected: |
| 54 | + /** |
| 55 | + * @brief Method creates infer request implementation |
| 56 | + * |
| 57 | + * @return Sync infer request |
| 58 | + */ |
| 59 | + virtual std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override; |
| 60 | + |
| 61 | +private: |
| 62 | + gguf_context* m_gguf_ctx = nullptr; |
| 63 | + std::string m_gguf_fname; |
| 64 | + |
| 65 | + llama_model* m_llama_model_ptr = nullptr; |
| 66 | + llama_context* m_llama_ctx = nullptr; |
| 67 | + std::shared_ptr<ov::Model> m_fake_model; |
| 68 | + |
| 69 | + std::vector<ov::Output<const ov::Node>> m_fake_inputs; |
| 70 | + std::vector<ov::Output<const ov::Node>> m_fake_outputs; |
| 71 | + |
| 72 | + friend class ov::llama_cpp_plugin::LlamaCppSyncInferRequest; |
| 73 | + friend class ov::llama_cpp_plugin::LlamaCppState; |
| 74 | +}; |
| 75 | +} // namespace llama_cpp_plugin |
| 76 | +} // namespace ov |
| 77 | + |
| 78 | +#endif // LLAMA_CPP_COMPILED_MODEL_HPP |
0 commit comments