Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
echarlaix committed Nov 2, 2023
1 parent 8983274 commit d6cdc10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,27 @@ def forward(

inputs["input_ids"] = np.array(input_ids)
# Add the attention_mask inputs when needed
if "attention_mask" in self.input_names:
if "attention_mask" in self.input_names or "position_ids" in self.input_names:
if attention_mask is not None:
inputs["attention_mask"] = np.array(attention_mask)
attention_mask = np.array(attention_mask)
else:
inputs["attention_mask"] = np.ones(
attention_mask = np.ones(
(input_ids.shape[0], input_ids.shape[1] + past_len), dtype=inputs["input_ids"].dtype
)

# Add the attention_mask inputs when needed
if "position_ids" in self.input_names and position_ids is not None:
inputs["position_ids"] = np.array(position_ids)
if "attention_mask" in self.input_names:
inputs["attention_mask"] = attention_mask

if "position_ids" in self.input_names:
if position_ids is not None:
position_ids = np.array(position_ids)
else:
position_ids = np.cumsum(attention_mask, axis=1) - 1
position_ids[attention_mask == 0] = 1
if past_key_values:
position_ids = np.expand_dims(position_ids[:, -1], axis=-1)

inputs["position_ids"] = position_ids

# Run inference
self.request.start_async(inputs, shared_memory=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from transformers.onnx.utils import get_preprocessor
from utils_tests import MODEL_NAMES

from optimum.exporters.onnx import MODEL_TYPES_REQUIRING_POSITION_IDS
from optimum.intel import (
OVModelForAudioClassification,
OVModelForAudioFrameClassification,
Expand All @@ -77,7 +78,6 @@
DIFFUSION_MODEL_VAE_ENCODER_SUBFOLDER,
)
from optimum.utils.testing_utils import require_diffusers
from optimum.exporters.onnx import MODEL_TYPES_REQUIRING_POSITION_IDS


TENSOR_ALIAS_TO_TYPE = {
Expand Down

0 comments on commit d6cdc10

Please sign in to comment.