Skip to content

Commit

Permalink
Gemma2: fix FA2 generation (huggingface#32553)
Browse files Browse the repository at this point in the history
fix FA2
  • Loading branch information
zucchini-nlp authored and stevhliu committed Aug 21, 2024
1 parent 007eae2 commit b144a4d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transformers/models/gemma2/modeling_gemma2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,11 @@ def prepare_inputs_for_generation(
# The clone here is for the same reason as for `position_ids`.
model_inputs = {"input_ids": input_ids.clone(memory_format=torch.contiguous_format), "inputs_embeds": None}

if isinstance(past_key_values, HybridCache) and attention_mask.ndim == 2:
if (
isinstance(past_key_values, HybridCache)
and attention_mask.ndim == 2
and not self.config._attn_implementation == "flash_attention_2"
):
if model_inputs["inputs_embeds"] is not None:
batch_size, sequence_length, _ = model_inputs["inputs_embeds"].shape
device = model_inputs["inputs_embeds"].device
Expand Down

0 comments on commit b144a4d

Please sign in to comment.