From da729ba1d61035347d0864fa856a743fb433416a Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Fri, 24 May 2024 08:29:35 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Yaroslav Tarkan Co-authored-by: Xiake Sun Co-authored-by: Ilya Lavrenov --- src/README.md | 12 ++++++------ src/cpp/include/openvino/genai/generation_config.hpp | 3 +-- src/cpp/include/openvino/genai/llm_pipeline.hpp | 6 +++--- src/cpp/include/openvino/genai/streamer_base.hpp | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/README.md b/src/README.md index ad21250989..2f729b8b3c 100644 --- a/src/README.md +++ b/src/README.md @@ -8,7 +8,7 @@ optimum-cli export openvino --model "TinyLlama/TinyLlama-1.1B-Chat-v1.0" --weigh pip install openvino-genai ``` -LLMPipeline is the main object used for decoding. You can initiliza it straigh away from the folder with the converted model. It will automanically load the main model, tokenizer, detokenizer and default generation configuration. +`LLMPipeline` is the main object used for decoding. You can initialize it straight away from the folder with the converted model. It will automatically load the main model, tokenizer, detokenizer and default generation configuration. ### Python @@ -129,7 +129,7 @@ int main(int argc, char* argv[]) { for (size_t i = 0; i < questions.size(); i++) { std::cout << "question:\n"; - cout << prompt << endl; + std::cout << prompt << std::endl; auto answer = pipe(prompt, config, streamer); // no need to print answer, streamer will do that @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) { } ``` -Streaming exapmle with lambda function +Streaming example with lambda function ``` cpp @@ -156,11 +156,11 @@ int main(int argc, char* argv[]) { Streaming with custom class ``` cpp -#include +#include "openvino/genai/streamer_base.hpp" #include "openvino/genai/llm_pipeline.hpp" #include -class CustomStreamer: publict StreamerBase { +class CustomStreamer: public ov::StreamerBase { public: void put(int64_t token) { /* custom decoding/tokens processing code @@ -180,6 +180,6 @@ int main(int argc, char* argv[]) { std::string model_path = argv[1]; ov::LLMPipeline pipe(model_path, "CPU"); - cout << pipe.generate("The Sun is yellow bacause", custom_streamer); + std::cout << pipe.generate("The Sun is yellow bacause", custom_streamer); } ``` diff --git a/src/cpp/include/openvino/genai/generation_config.hpp b/src/cpp/include/openvino/genai/generation_config.hpp index 837fae21ad..879f802ae7 100644 --- a/src/cpp/include/openvino/genai/generation_config.hpp +++ b/src/cpp/include/openvino/genai/generation_config.hpp @@ -53,12 +53,11 @@ enum class StopCriteria { early, heuristic, never }; * @param eos_token_id id of token * @param bos_token token string representation * @param eos_token token string representation - * @param draft_model draft model for assitive decoding */ class OPENVINO_GENAI_EXPORTS GenerationConfig { public: GenerationConfig() = default; - GenerationConfig(std::string json_path); + explicit GenerationConfig(std::string json_path); // Generic size_t max_new_tokens = SIZE_MAX; diff --git a/src/cpp/include/openvino/genai/llm_pipeline.hpp b/src/cpp/include/openvino/genai/llm_pipeline.hpp index 3bc8453d4e..48f9292b02 100644 --- a/src/cpp/include/openvino/genai/llm_pipeline.hpp +++ b/src/cpp/include/openvino/genai/llm_pipeline.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include "openvino/core/any.hpp" #include "openvino/genai/generation_config.hpp" #include "openvino/genai/tokenizer.hpp" #include "openvino/genai/streamer_base.hpp" @@ -174,10 +174,10 @@ class OPENVINO_GENAI_EXPORTS LLMPipeline { }; /* - * utils that allow to use generate and operarator() in the folllowing way: + * utils that allow to use generate and operator() in the following way: * pipe.generate(input_ids, ov::max_new_tokens(200), ov::temperature(1.0f),...) * pipe(text, ov::max_new_tokens(200), ov::temperature(1.0f),...) - * All names match to names in cofnig except streamer. + * All names match to names in config except streamer. */ static constexpr ov::Property max_new_tokens{"max_new_tokens"}; static constexpr ov::Property max_length{"max_length"}; diff --git a/src/cpp/include/openvino/genai/streamer_base.hpp b/src/cpp/include/openvino/genai/streamer_base.hpp index 3f0879d702..385cb2bf1e 100644 --- a/src/cpp/include/openvino/genai/streamer_base.hpp +++ b/src/cpp/include/openvino/genai/streamer_base.hpp @@ -15,7 +15,7 @@ namespace ov { class StreamerBase { public: Tokenizer m_tokenizer; - StreamerBase(Tokenizer tokenizer): m_tokenizer(tokenizer) {}; + explicit StreamerBase(Tokenizer tokenizer): m_tokenizer(tokenizer) {} StreamerBase() = default; /// @brief put is called every time new token is decoded