Instructions to use diffusers-modular/krea2-edit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers-modular/krea2-edit with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers-modular/krea2-edit", torch_dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Drop all-True attention mask -> flash SDPA (memory fits on MIG)
Browse files- 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:
|