Skip to content

Commit

Permalink
Fix mllama test (#1569)
Browse files Browse the repository at this point in the history
Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
  • Loading branch information
sywangyi authored Dec 6, 2024
1 parent f6caf85 commit 6f63e17
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion optimum/habana/transformers/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,9 +2407,11 @@ def _sample(
assert "position_ids" not in model_kwargs, "Untested path"

token_idx = model_kwargs.get("token_idx", None)
start_token_idx = cur_len
if token_idx is not None:
# Update cur_len in case of static shapes
cur_len = (token_idx + model_kwargs.get("inputs_embeds_offset", 0)).item()
start_token_idx = token_idx

time_to_first_token_done = False
model_kwargs["pad_done"] = False
Expand Down Expand Up @@ -2617,7 +2619,10 @@ def _sample(
if batch_size > 1 and has_eos_stopping_criteria:
eos_token_id = generation_config.eos_token_id
# Find the positions of the first eos_token_id in each sequence
eos_positions = (input_ids[:, INITIAL_TOKEN_IDX:] == eos_token_id).int().argmax(dim=1) + INITIAL_TOKEN_IDX
eos_positions = (
torch.isin(input_ids[:, start_token_idx:], torch.tensor(eos_token_id)).int().argmax(dim=1)
+ start_token_idx
)
# Create a mask for positions greater than the first eos_token_id
mask = torch.arange(max_length).expand(batch_size, max_length) > eos_positions.unsqueeze(1)
# Apply the mask to set positions greater than the first eos_token_id to pad_token_id
Expand Down

0 comments on commit 6f63e17

Please sign in to comment.