Flux followup (#9074) · scornflake/diffusers@c291617 · GitHub
Skip to content

Commit c291617

Browse files
yiyixuxusayakpauljsmidt
authored
Flux followup (huggingface#9074)
* refactor rotary embeds * adding jsmidt as co-author of this PR for huggingface#9133 --------- Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Joseph Smidt <josephsmidt@gmail.com>
1 parent 9003d75 commit c291617

8 files changed

Lines changed: 159 additions & 202 deletions

File tree

‎src/diffusers/models/attention_processor.py‎

Lines changed: 53 additions & 127 deletions

‎src/diffusers/models/controlnet_flux.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from ..models.modeling_utils import ModelMixin
2525
from ..utils import USE_PEFT_BACKEND, is_torch_version, logging, scale_lora_layers, unscale_lora_layers
2626
from .controlnet import BaseOutput, zero_module
27-
from .embeddings import CombinedTimestepGuidanceTextProjEmbeddings, CombinedTimestepTextProjEmbeddings
27+
from .embeddings import CombinedTimestepGuidanceTextProjEmbeddings, CombinedTimestepTextProjEmbeddings, FluxPosEmbed
2828
from .modeling_outputs import Transformer2DModelOutput
29-
from .transformers.transformer_flux import EmbedND, FluxSingleTransformerBlock, FluxTransformerBlock
29+
from .transformers.transformer_flux import FluxSingleTransformerBlock, FluxTransformerBlock
3030

3131

3232
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -59,7 +59,7 @@ def __init__(
5959
self.out_channels = in_channels
6060
self.inner_dim = num_attention_heads * attention_head_dim
6161

62-
self.pos_embed = EmbedND(dim=self.inner_dim, theta=10000, axes_dim=axes_dims_rope)
62+
self.pos_embed = FluxPosEmbed(theta=10000, axes_dim=axes_dims_rope)
6363
text_time_guidance_cls = (
6464
CombinedTimestepGuidanceTextProjEmbeddings if guidance_embeds else CombinedTimestepTextProjEmbeddings
6565
)
@@ -272,8 +272,20 @@ def forward(
272272
)
273273
encoder_hidden_states = self.context_embedder(encoder_hidden_states)
274274

275-
txt_ids = txt_ids.expand(img_ids.size(0), -1, -1)
276-
ids = torch.cat((txt_ids, img_ids), dim=1)
275+
if txt_ids.ndim == 3:
276+
logger.warning(
277+
"Passing `txt_ids` 3d torch.Tensor is deprecated."
278+
"Please remove the batch dimension and pass it as a 2d torch Tensor"
279+
)
280+
txt_ids = txt_ids[0]
281+
if img_ids.ndim == 3:
282+
logger.warning(
283+
"Passing `img_ids` 3d torch.Tensor is deprecated."
284+
"Please remove the batch dimension and pass it as a 2d torch Tensor"
285+
)
286+
img_ids = img_ids[0]
287+
288+
ids = torch.cat((txt_ids, img_ids), dim=0)
277289
image_rotary_emb = self.pos_embed(ids)
278290

279291
block_samples = ()

‎src/diffusers/models/embeddings.py‎

Lines changed: 35 additions & 7 deletions

0 commit comments

Comments
 (0)