Skip to content

Commit

Permalink
Fix is_causal being a tensor (#35791)
Browse files Browse the repository at this point in the history
* fix is_causal being a tensor

* convert in sdpa attention only when  jit tracing
  • Loading branch information
IlyasMoutawwakil authored Jan 30, 2025
1 parent 7547f55 commit 19f2ec8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transformers/integrations/sdpa_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def sdpa_attention_forward(
if is_causal is None:
is_causal = causal_mask is None and query.shape[2] > 1

# Shapes (e.g. query.shape[2]) are tensors during jit tracing, resulting in `is_causal` being a tensor.
# We convert it to a bool for the SDPA kernel that only accepts bools.
if torch.jit.is_tracing() and isinstance(is_causal, torch.Tensor):
is_causal = is_causal.item()

attn_output = torch.nn.functional.scaled_dot_product_attention(
query,
key,
Expand Down

0 comments on commit 19f2ec8

Please sign in to comment.