Skip to content

Commit bc73e62

Browse files
VLM: add get_tokenizer() (#977)
Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
1 parent 2d144b1 commit bc73e62

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/cpp/include/openvino/genai/visual_language/pipeline.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
8989
/// model chat_template.
9090
/// @param new_template A new template to override with.
9191
void set_chat_template(const std::string& new_template);
92+
/// @brief Get a Tokenizer used to tokenize input and detokenize
93+
/// output.
94+
ov::genai::Tokenizer get_tokenizer() const;
9295
/// @brief Extract GenerationConfig used to get default values.
9396
/// @return Default values used.
9497
GenerationConfig get_generation_config() const;

src/cpp/src/visual_language/pipeline.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ class ov::genai::VLMPipeline::VLMPipelineImpl {
527527

528528
void finish_chat() {m_is_chat_conversation = false;}
529529

530+
Tokenizer get_tokenizer() const {
531+
return m_tokenizer;
532+
}
533+
530534
void set_chat_template(const std::string& new_template) {
531535
m_tokenizer.set_chat_template(new_template);
532536
}
@@ -773,6 +777,10 @@ void VLMPipeline::set_chat_template(const std::string& new_template) {
773777
m_pimpl->set_chat_template(new_template);
774778
}
775779

780+
Tokenizer VLMPipeline::get_tokenizer() const {
781+
return m_pimpl->get_tokenizer();
782+
}
783+
776784
GenerationConfig VLMPipeline::get_generation_config() const {
777785
return m_pimpl->get_generation_config();
778786
}

src/python/py_vlm_pipeline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void init_vlm_pipeline(py::module_& m) {
120120

121121
.def("start_chat", &ov::genai::VLMPipeline::start_chat, py::arg("system_message") = "")
122122
.def("finish_chat", &ov::genai::VLMPipeline::finish_chat)
123+
.def("get_tokenizer", &ov::genai::VLMPipeline::get_tokenizer)
123124
.def("get_generation_config", &ov::genai::VLMPipeline::get_generation_config)
124125
.def("set_generation_config", &ov::genai::VLMPipeline::set_generation_config)
125126
.def(

tests/python_tests/test_vlm_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def streamer(word: str) -> bool:
105105

106106
pipe.finish_chat()
107107
gc.collect()
108+
tokenizer = pipe.get_tokenizer()
109+
tokenizer.encode("")
108110
del pipe
109111
gc.collect()
110112

0 commit comments

Comments
 (0)