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
)
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: