Skip to content

Commit

Permalink
updated to latest of master
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzintel committed Jul 31, 2024
2 parents ea218b1 + 4228131 commit 95af9be
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions samples/cpp/chat_sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ UnicodeEncodeError: 'charmap' codec can't encode character '\u25aa' in position
If you encounter the error described in the example when sample is printing output to the Windows console, it is likely due to the default Windows encoding not supporting certain Unicode characters. To resolve this:
1. Enable Unicode characters for Windows cmd - open `Region` settings from `Control panel`. `Administrative`->`Change system locale`->`Beta: Use Unicode UTF-8 for worldwide language support`->`OK`. Reboot.
2. Enable UTF-8 mode by setting environment variable `PYTHONIOENCODING="utf8"`.

#### Missing chat template

If you encounter an exception indicating a missing "chat template" when launching the `ov::genai::LLMPipeline` in chat mode, it likely means the model was not tuned for chat functionality. To work this around, manually add the chat template to tokenizer_config.json of your model.
The following template can be used as a default, but it may not work properly with every model:
```
"chat_template": "{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|im_start|>user\n' + message['content'] + '<|im_end|>\n<|im_start|>assistant\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|im_end|>\n'}}{% endif %}{% endfor %}",
```
10 changes: 10 additions & 0 deletions samples/python/chat_sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ To enable Unicode characters for Windows cmd open `Region` settings from `Contro
Discrete GPUs (dGPUs) usually provide better performance compared to CPUs. It is recommended to run larger models on a dGPU with 32GB+ RAM. For example, the model meta-llama/Llama-2-13b-chat-hf can benefit from being run on a dGPU. Modify the source code to change the device for inference to the GPU.

See https://github.com/openvinotoolkit/openvino.genai/blob/master/src/README.md#supported-models for the list of supported models.


## Troubleshooting
### Missing chat template

If you encounter an exception indicating a missing "chat template" when launching the `ov::genai::LLMPipeline` in chat mode, it likely means the model was not tuned for chat functionality. To work this around, manually add the chat template to tokenizer_config.json of your model.
The following template can be used as a default, but it may not work properly with every model:
```
"chat_template": "{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|im_start|>user\n' + message['content'] + '<|im_end|>\n<|im_start|>assistant\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|im_end|>\n'}}{% endif %}{% endfor %}",
```
1 change: 0 additions & 1 deletion src/cpp/src/block_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class BlockManager {
}
phisical_blocks_released += released_count;
}
phisical_blocks_released = phisical_blocks_released;
return num_required_blocks <= phisical_blocks_released;
}

Expand Down
1 change: 1 addition & 0 deletions src/cpp/src/llm_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class StatefulLLMPipeline final : public LLMPipelineImplBase {

m_history.push_back({{"role", "system"}, {"content", system_message}});
constexpr bool add_generation_prompt = false;

m_templated_chat_history = m_tokenizer.apply_chat_template(m_history, add_generation_prompt);
}

Expand Down
7 changes: 5 additions & 2 deletions src/cpp/src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ class Tokenizer::TokenizerImpl {
bool add_generation_prompt,
const std::string& chat_template) const {
auto chat_tpl = chat_template.empty() ? m_chat_template : chat_template;
OPENVINO_ASSERT(!chat_tpl.empty(),
"Chat template wasn't found. This may indicate that the model wasn't trained for chat scenario."
" Please add 'chat_template' to tokenizer_config.json to use the model in chat scenario."
" For more information see the section Troubleshooting in README.md");

// Jinja2Cpp does not support slicing, e.g. [1:].
// In templates slicing is used typically in the header to find system prompt.
// If header containts that typical expression we update template and
Expand Down Expand Up @@ -433,8 +438,6 @@ class Tokenizer::TokenizerImpl {
"For exmaple: <start_of_turn>user{user_prompt}<end_of_turn><start_of_turn>model");
}
}


};

Tokenizer::Tokenizer(const std::string& tokenizer_path, const ov::AnyMap& plugin_config) {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/src/tokenizers_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::filesystem::path tokenizers_relative_to_genai() {
// was already defined.
class ScopedVar {
public:
bool was_already_set;
bool was_already_set{false};
static constexpr char ENVIRONMENT_VARIABLE_NAME[] = "OPENVINO_TOKENIZERS_PATH_GENAI";
explicit ScopedVar(const std::string& environment_variable_value) {
#ifdef _WIN32
Expand Down

0 comments on commit 95af9be

Please sign in to comment.