linoyts HF Staff commited on
Commit
a41102e
·
verified ·
1 Parent(s): dad256a

Drop all-True attention mask -> flash SDPA (memory fits on MIG)

Browse files
Files changed (1) hide show
  1. transformer_krea2.py +5 -0
transformer_krea2.py CHANGED
@@ -525,6 +525,11 @@ class Krea2Transformer2DModel(ModelMixin, ConfigMixin, AttentionMixin, PeftAdapt
525
  ref_temb_mod = self.time_mod_proj(F.gelu(temb_zero, approximate="tanh"))
526
  block_temb = (temb_mod, ref_temb_mod, text_seq_len + image_seq_len - ref_seq_len)
527
 
 
 
 
 
 
528
  text_attention_mask = None
529
  attention_mask = None
530
  if encoder_attention_mask is not None:
 
525
  ref_temb_mod = self.time_mod_proj(F.gelu(temb_zero, approximate="tanh"))
526
  block_temb = (temb_mod, ref_temb_mod, text_seq_len + image_seq_len - ref_seq_len)
527
 
528
+ # An all-True mask is equivalent to no mask; passing None keeps SDPA on its fast, low-memory (flash)
529
+ # path instead of the mask-materializing math fallback — critical on small / MIG GPUs.
530
+ if encoder_attention_mask is not None and bool(encoder_attention_mask.all()):
531
+ encoder_attention_mask = None
532
+
533
  text_attention_mask = None
534
  attention_mask = None
535
  if encoder_attention_mask is not None: