Skip to content

OPT training with torch.compile decomposes SDPA into Triton kernels due to attention_mask #48924

Description

@msnliu

System Info

Summary

When training OPT with torch.compile, an attention_mask=None input is converted into an all-ones mask for positional embeddings. This makes the model pass an explicit mask to SDPA instead of using is_causal=True, preventing the optimized FlashAttention/oneDNN backward kernel and causing a 20–30% performance regression.

Reproduction

Root Cause

In src/transformers/models/opt/modeling_opt.py:

if attention_mask is None:
    attention_mask = torch.ones(
        (inputs_embeds.shape[0], all_seq_len), dtype=torch.bool, device=inputs_embeds.device
    )

causal_mask = create_causal_mask(
    config=self.config,
    input_tensor=inputs_embeds,
    attention_mask=attention_mask,  # <- passing non-None torch.ones mask
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions