Skip to content
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

add token_type_ids in lm forward signature #964

Merged
merged 8 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,11 @@ def forward(
attention_mask: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
position_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
**kwargs,
) -> CausalLMOutputWithPast:
self.compile()
kwargs["token_type_ids"] = token_type_ids
echarlaix marked this conversation as resolved.
Show resolved Hide resolved

inputs = self.prepare_inputs(
input_ids=input_ids,
Expand Down
9 changes: 5 additions & 4 deletions tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ def test_compare_to_transformers(self, model_arch):
self.assertTrue(ov_model.use_cache)
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS)
tokens = tokenizer("This is a sample output", return_tensors="pt")
tokens.pop("token_type_ids", None)

ov_outputs = ov_model(**tokens)
self.assertTrue("logits" in ov_outputs)
Expand Down Expand Up @@ -909,7 +908,6 @@ def test_compare_to_transformers(self, model_arch):
# Compare batched generation
tokenizer.padding_side = "left"
tokens = tokenizer(["Today is a nice day and I am longer", "This is me"], return_tensors="pt", padding=True)
tokens.pop("token_type_ids", None)
ov_model.generation_config.eos_token_id = None
transformers_model.generation_config.eos_token_id = None
ov_model.config.eos_token_id = None
Expand All @@ -933,7 +931,10 @@ def test_compare_to_transformers(self, model_arch):

additional_inputs = {"past_key_values": DynamicCache()}
transformers_outputs = transformers_model.generate(**tokens, generation_config=gen_config, **additional_inputs)
self.assertTrue(torch.allclose(ov_outputs, transformers_outputs))
self.assertTrue(
torch.allclose(ov_outputs, transformers_outputs),
"OV output {ov_outputs}\nTransofrmers output {transformers_output}",
echarlaix marked this conversation as resolved.
Show resolved Hide resolved
)

del transformers_model
del ov_model
Expand Down Expand Up @@ -1102,6 +1103,7 @@ def test_beam_search(self, model_arch):
# starting from transformers 4.45.0 gemma2 uses eager attention by default, while ov - sdpa
if model_arch == "gemma2" and is_transformers_version(">=", "4.45.0"):
model_kwargs["attn_implementation"] = "sdpa"

# Qwen tokenizer does not support padding, chatglm, glm4 testing models produce nan that incompatible with beam search
if model_arch in ["qwen", "chatglm", "glm4"]:
return
Expand Down Expand Up @@ -1177,7 +1179,6 @@ def test_beam_search(self, model_arch):
from transformers.cache_utils import DynamicCache
tokenizer.pad_token_id = tokenizer.eos_token_id
tokens = tokenizer(["Today is a nice day and I am longer", "This is me"], return_tensors="pt", padding=True)
tokens.pop("token_type_ids", None)
ov_model_stateful.generation_config.eos_token_id = None
ov_model_stateless.generation_config.eos_token_id = None
transformers_model.generation_config.eos_token_id = None
Expand Down
Loading