Joshuant commited on
Commit
ccf94ef
·
verified ·
1 Parent(s): c61f53d

fix: gracefully fall back flash_attention_2 -> sdpa when flash_attn not installed

Browse files
Files changed (1) hide show
  1. gpt2_decoder.py +4 -0
gpt2_decoder.py CHANGED
@@ -99,6 +99,8 @@ class MossTTSNanoGPT2Attention(nn.Module):
99
  self.head_dim = hidden_size // num_heads
100
  self.embed_dim = hidden_size
101
  self.layer_idx = layer_idx
 
 
102
  self.attn_implementation = attn_implementation
103
  self.attn_dropout = float(config.attn_pdrop)
104
  self.resid_dropout = nn.Dropout(config.resid_pdrop)
@@ -388,6 +390,8 @@ class MossTTSNanoGPT2Model(nn.Module):
388
  def __init__(self, config: GPT2Config, attn_implementation: str = "eager") -> None:
389
  super().__init__()
390
  self.config = config
 
 
391
  self.attn_implementation = attn_implementation
392
  self.position_embedding_type = str(getattr(config, "position_embedding_type", "absolute")).lower()
393
  if self.position_embedding_type not in {"absolute", "rope"}:
 
99
  self.head_dim = hidden_size // num_heads
100
  self.embed_dim = hidden_size
101
  self.layer_idx = layer_idx
102
+ if attn_implementation == "flash_attention_2" and not _FLASH_ATTN_AVAILABLE:
103
+ attn_implementation = "sdpa" # graceful fallback when flash_attn isn't installed
104
  self.attn_implementation = attn_implementation
105
  self.attn_dropout = float(config.attn_pdrop)
106
  self.resid_dropout = nn.Dropout(config.resid_pdrop)
 
390
  def __init__(self, config: GPT2Config, attn_implementation: str = "eager") -> None:
391
  super().__init__()
392
  self.config = config
393
+ if attn_implementation == "flash_attention_2" and not _FLASH_ATTN_AVAILABLE:
394
+ attn_implementation = "sdpa" # graceful fallback when flash_attn isn't installed
395
  self.attn_implementation = attn_implementation
396
  self.position_embedding_type = str(getattr(config, "position_embedding_type", "absolute")).lower()
397
  if self.position_embedding_type not in {"absolute", "rope"}: