-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept buffer in LLMPipeline ctor #1262
Merged
andrei-kochin
merged 22 commits into
openvinotoolkit:releases/2024/5
from
pavel-esir:add_new_ctors
Dec 5, 2024
Merged
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
624d9f5
initial
pavel-esir 9ed8f6e
use string and ov::Tensor instead of a raw buffer
pavel-esir dd69db2
continuous batching ctor with model from buffer
pavel-esir 3856770
revert chat sample
pavel-esir 2cdf0d3
add CTOR with model_str and ov::Tensor buffers to NPU/StaticLLMPipeline
pavel-esir 5b73eb4
fix win build, fix chat template patching
pavel-esir 0f45144
fix speculative decoding
pavel-esir cb7f55e
improve TokenizerImpl
pavel-esir add6268
fix typos
pavel-esir ef736e6
add encryption sample
pavel-esir 44aede3
apply comments 1
pavel-esir a7081c4
Merge remote-tracking branch 'upstream/releases/2024/5' into add_new_…
pavel-esir ab64515
fix chat_sample and tests
pavel-esir 380966d
remove stale todos, fix github actions yml
pavel-esir 4b7c4c2
fix path greedy_causal_lm -> text_generation
pavel-esir 0fc3bbe
update encrypted_model_causal_lm sample, made model_desr setable from…
pavel-esir 62ba450
Merge remote-tracking branch 'upstream/releases/2024/5' into add_new_…
pavel-esir 4a45257
add ctor with Properties
pavel-esir 2457b89
fix "Yoda style" if statements, some other corrections
pavel-esir 9befd0c
simplify a bit TokenizerImpl construction
pavel-esir bbe1b7b
fix plugin_config -> properties for NPY
pavel-esir c05febe
Merge remote-tracking branch 'upstream/releases/2024/5' into add_new_…
pavel-esir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. multinomial_causal_lm, beam_search_causal_lm and chat_sample should also move to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
samples/cpp/text_generation/generate_with_encrypted_model.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2023-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "openvino/genai/llm_pipeline.hpp" | ||
#include <fstream> | ||
|
||
int main(int argc, char* argv[]) try { | ||
if (3 > argc) | ||
throw std::runtime_error(std::string{"Usage: "} + argv[0] + " <MODEL_DIR> \"<PROMPT>\""); | ||
|
||
std::string device = "CPU"; // GPU, NPU can be used as well | ||
std::string models_path = argv[1]; | ||
std::string prompt = argv[2]; | ||
std::string model_path = models_path + "/openvino_model.xml"; | ||
std::string weights_path = models_path + "/openvino_model.bin"; | ||
|
||
std::ifstream model_file(model_path); | ||
std::ifstream weights_file(weights_path, std::ios::binary); | ||
if (!model_file.is_open() || !weights_file.is_open()) { | ||
throw std::runtime_error("Cannot open model or weights file"); | ||
} | ||
|
||
// User can add file decryption of model_file and weights_file in memory here. | ||
pavel-esir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::string model_str((std::istreambuf_iterator<char>(model_file)), std::istreambuf_iterator<char>()); | ||
std::vector<char> weights_buffer((std::istreambuf_iterator<char>(weights_file)), std::istreambuf_iterator<char>()); | ||
auto weights_tensor = ov::Tensor(ov::element::u8, {weights_buffer.size()}, weights_buffer.data()); | ||
|
||
ov::genai::Tokenizer tok(models_path); | ||
ov::genai::LLMPipeline pipe(model_str, weights_tensor, tok, device); | ||
|
||
ov::genai::GenerationConfig config; | ||
config.max_new_tokens = 100; | ||
std::string result = pipe.generate(prompt, config); | ||
pavel-esir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::cout << result << std::endl; | ||
} catch (const std::exception& error) { | ||
try { | ||
std::cerr << error.what() << '\n'; | ||
} catch (const std::ios_base::failure&) {} | ||
return EXIT_FAILURE; | ||
} catch (...) { | ||
try { | ||
std::cerr << "Non-exception object thrown\n"; | ||
} catch (const std::ios_base::failure&) {} | ||
return EXIT_FAILURE; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for the new sample