Skip to content

Commit

Permalink
VLM: add get_tokenizer() (openvinotoolkit#977)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilya Lavrenov <[email protected]>
  • Loading branch information
Wovchena and ilya-lavrenov authored Oct 15, 2024
1 parent 2d144b1 commit bc73e62
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cpp/include/openvino/genai/visual_language/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
/// model chat_template.
/// @param new_template A new template to override with.
void set_chat_template(const std::string& new_template);
/// @brief Get a Tokenizer used to tokenize input and detokenize
/// output.
ov::genai::Tokenizer get_tokenizer() const;
/// @brief Extract GenerationConfig used to get default values.
/// @return Default values used.
GenerationConfig get_generation_config() const;
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/src/visual_language/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ class ov::genai::VLMPipeline::VLMPipelineImpl {

void finish_chat() {m_is_chat_conversation = false;}

Tokenizer get_tokenizer() const {
return m_tokenizer;
}

void set_chat_template(const std::string& new_template) {
m_tokenizer.set_chat_template(new_template);
}
Expand Down Expand Up @@ -773,6 +777,10 @@ void VLMPipeline::set_chat_template(const std::string& new_template) {
m_pimpl->set_chat_template(new_template);
}

Tokenizer VLMPipeline::get_tokenizer() const {
return m_pimpl->get_tokenizer();
}

GenerationConfig VLMPipeline::get_generation_config() const {
return m_pimpl->get_generation_config();
}
Expand Down
1 change: 1 addition & 0 deletions src/python/py_vlm_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void init_vlm_pipeline(py::module_& m) {

.def("start_chat", &ov::genai::VLMPipeline::start_chat, py::arg("system_message") = "")
.def("finish_chat", &ov::genai::VLMPipeline::finish_chat)
.def("get_tokenizer", &ov::genai::VLMPipeline::get_tokenizer)
.def("get_generation_config", &ov::genai::VLMPipeline::get_generation_config)
.def("set_generation_config", &ov::genai::VLMPipeline::set_generation_config)
.def(
Expand Down
2 changes: 2 additions & 0 deletions tests/python_tests/test_vlm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def streamer(word: str) -> bool:

pipe.finish_chat()
gc.collect()
tokenizer = pipe.get_tokenizer()
tokenizer.encode("")
del pipe
gc.collect()

Expand Down

0 comments on commit bc73e62

Please sign in to comment.