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

Bump transformers version #682

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 16 additions & 4 deletions optimum/exporters/openvino/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,17 @@ def __exit__(self, exc_type, exc_value, traceback):
# adopted from
# https://github.com/huggingface/transformers/blob/v4.39.3/src/transformers/models/gemma/modeling_gemma.py#L965
# https://github.com/huggingface/transformers/blob/v4.39.3/src/transformers/models/llama/modeling_llama.py#L1058
def _llama_gemma_update_causal_mask(self, attention_mask, input_tensor, cache_position, **kwargs):
def _llama_gemma_update_causal_mask(self, attention_mask, input_tensor, cache_position, past_seen_tokens=None):
from transformers.modeling_attn_mask_utils import AttentionMaskConverter

# for compatibility with https://github.com/huggingface/transformers/pull/30047
current_length = kwargs.get("current_length", cache_position[-1])
if self.config._attn_implementation == "sdpa" and past_seen_tokens is not None:
# For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument,
# in order to dispatch on Flash Attention 2.
if AttentionMaskConverter._ignore_causal_mask_sdpa(
attention_mask, inputs_embeds=input_tensor, past_key_values_length=past_seen_tokens
):
return None

dtype, device = input_tensor.dtype, input_tensor.device

# using minimum from dtype with larger bandwith (floa32) may lead to overflow
Expand All @@ -305,7 +311,13 @@ def _llama_gemma_update_causal_mask(self, attention_mask, input_tensor, cache_po
if hasattr(getattr(self.layers[0], "self_attn", {}), "past_key_value"): # static cache
target_length = self.config.max_position_embeddings
else: # dynamic cache
target_length = attention_mask.shape[-1] if isinstance(attention_mask, torch.Tensor) else current_length + 1
if past_seen_tokens is not None:
current_length = past_seen_tokens + sequence_length + 1
# TODO : remove after support of transformers >= v4.40.0
else:
current_length = cache_position[-1] + 1

target_length = attention_mask.shape[-1] if isinstance(attention_mask, torch.Tensor) else current_length

causal_mask = torch.full((sequence_length, target_length), fill_value=1, dtype=dtype, device=device) * min_dtype
if sequence_length != 1:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

INSTALL_REQUIRE = [
"torch>=1.11",
"transformers>=4.36.0,<4.40.0",
"transformers>=4.36.0,<4.41.0",
"optimum~=1.19",
"datasets>=1.4.0",
"sentencepiece",
Expand Down
Loading