Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/source/en/api/pipelines/bria_fibo_edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ Fibo Edit is an 8B parameter image-to-image model that introduces a new paradigm
Featuring native masking for granular precision, it moves beyond simple prompt-based diffusion to offer explicit, interpretable control optimized for production environments.
Its lightweight architecture is designed for deep customization, empowering researchers to build specialized "Edit" models for domain-specific tasks while delivering top-tier aesthetic quality

Refer to the Bria Fibo Edit Hugging Face [page](https://huggingface.co/briaai/Fibo-Edit-1.5-base) to learn more. A distilled checkpoint is available at [Fibo-Edit-1.5-turbo](https://huggingface.co/briaai/Fibo-Edit-1.5-turbo).

## Usage
_As the model is gated, before using it with diffusers you first need to go to the [Bria Fibo Hugging Face page](https://huggingface.co/briaai/Fibo-Edit), fill in the form and accept the gate. Once you are in, you need to login so that your system knows you’ve accepted the gate._

_As the model is gated, before using it with diffusers you first need to go to the [Bria Fibo Edit Hugging Face page](https://huggingface.co/briaai/Fibo-Edit-1.5-base), fill in the form and accept the gate. Once you are in, you need to login so that your system knows you’ve accepted the gate._

Use the command below to log in:

```bash
hf auth login
```


## BriaFiboEditPipeline

[[autodoc]] BriaFiboEditPipeline
- all
- __call__
- __call__
1 change: 1 addition & 0 deletions src/diffusers/models/transformers/transformer_bria_fibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class BriaFiboTransformer2DModel(ModelMixin, ConfigMixin, PeftAdapterMixin, From
"""

_supports_gradient_checkpointing = True
_repeated_blocks = ["BriaFiboTransformerBlock", "BriaFiboSingleTransformerBlock"]

@register_to_config
def __init__(
Expand Down
24 changes: 8 additions & 16 deletions src/diffusers/pipelines/bria_fibo/pipeline_bria_fibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,6 @@ def prepare_latents(

return latents, latent_image_ids

@staticmethod
def _prepare_attention_mask(attention_mask):
attention_matrix = torch.einsum("bi,bj->bij", attention_mask, attention_mask)

# convert to 0 - keep, -inf ignore
attention_matrix = torch.where(
attention_matrix == 1, 0.0, -torch.inf
) # Apply -inf to ignored tokens for nulling softmax score
return attention_matrix

@torch.no_grad()
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
Expand Down Expand Up @@ -615,13 +605,15 @@ def __call__(
if guidance_scale > 1:
latent_attention_mask = latent_attention_mask.repeat(2, 1)

attention_mask = torch.cat([prompt_attention_mask, latent_attention_mask], dim=1)
attention_mask = self._prepare_attention_mask(attention_mask) # batch, seq => batch, seq, seq
attention_mask = attention_mask.unsqueeze(dim=1).to(dtype=self.transformer.dtype) # for head broadcasting
attention_mask = torch.cat([prompt_attention_mask, latent_attention_mask], dim=1).bool()

if self._joint_attention_kwargs is None:
self._joint_attention_kwargs = {}
self._joint_attention_kwargs["attention_mask"] = attention_mask
if not attention_mask.all():
# Bool key-padding mask (batch, 1, 1, seq): every real query attends to the same keys as
# with a full (seq, seq) matrix, and varlen backends require bool. When nothing is padded
# the mask is a no-op, and omitting it keeps backends without mask support usable.
self._joint_attention_kwargs["attention_mask"] = attention_mask[:, None, None, :]

# Adapt scheduler to dynamic shifting (resolution dependent)

Expand All @@ -630,7 +622,7 @@ def __call__(
else:
seq_len = (height // self.vae_scale_factor) * (width // self.vae_scale_factor)

sigmas = np.linspace(1.0, 1 / num_inference_steps, num_inference_steps)
sigmas = None if timesteps is not None else np.linspace(1.0, 1 / num_inference_steps, num_inference_steps)

mu = calculate_shift(
seq_len,
Expand All @@ -646,7 +638,7 @@ def __call__(
self.scheduler,
num_inference_steps=num_inference_steps,
device=device,
timesteps=None,
timesteps=timesteps,
sigmas=sigmas,
mu=mu,
)
Expand Down
Loading
Loading