Skip to content

Commit

Permalink
Allow overriding eos_token_id (#1654)
Browse files Browse the repository at this point in the history
Phi3_V eos_token_id has different values for GenerationConfig and
Tokenizer. It's required to allow overriding the token_id to align with
the sample from model cards.

My patches to the original models are ignored:
1.
https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/discussions/68
2.
https://huggingface.co/microsoft/Phi-3.5-vision-instruct/discussions/35
  • Loading branch information
Wovchena authored Jan 31, 2025
1 parent d1eb4b2 commit 3b13a40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/cpp/src/generation_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,7 @@ GenerationConfig::GenerationConfig(const std::filesystem::path& json_path) {
}

void GenerationConfig::set_eos_token_id(size_t tokenizer_eos_token_id) {
if (eos_token_id < 0) {
eos_token_id = tokenizer_eos_token_id;
} else {
OPENVINO_ASSERT(eos_token_id == tokenizer_eos_token_id,
"EOS token ID is different in generation config (", eos_token_id, ") and tokenizer (",
tokenizer_eos_token_id, ")");
}
// Merge user defined stop tokens with model EOS token
eos_token_id = tokenizer_eos_token_id;
stop_token_ids.insert(eos_token_id);
}

Expand Down
6 changes: 4 additions & 2 deletions tests/python_tests/test_vlm_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def streamer(word: str) -> bool:
return False

models_path = get_ov_model(model_id, cache)
generation_config = GenerationConfig(max_new_tokens=30)
ov_pipe = VLMPipeline(models_path, "CPU")
generation_config = ov_pipe.get_generation_config()
generation_config.max_new_tokens = 30
generation_config.set_eos_token_id(ov_pipe.get_tokenizer().get_eos_token_id())

for links in image_links_for_testing:
images = []
for link in links:
images.append(get_image_by_link(link))

ov_pipe = VLMPipeline(models_path, "CPU")
ov_pipe.start_chat()

result_from_streamer = []
Expand Down

0 comments on commit 3b13a40

Please sign in to comment.