Skip to content

Commit ac34358

Browse files
committed
fix merge
1 parent 6dbc061 commit ac34358

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

examples/instruct_pix2pix/train_instruct_pix2pix_sdxl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ def log_validation(pipeline, args, accelerator, generator, global_step, is_final
8585
os.makedirs(val_save_dir)
8686

8787
original_image = (
88-
lambda image_url_or_path: (
89-
load_image(image_url_or_path)
90-
if urlparse(image_url_or_path).scheme
91-
else Image.open(image_url_or_path).convert("RGB")
92-
)
88+
lambda image_url_or_path: load_image(image_url_or_path)
89+
if urlparse(image_url_or_path).scheme
90+
else Image.open(image_url_or_path).convert("RGB")
9391
)(args.val_image_url_or_path)
9492

9593
if torch.backends.mps.is_available():

src/diffusers/loaders/peft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
logger = logging.get_logger(__name__)
4747

4848
_SET_ADAPTER_SCALE_FN_MAPPING = defaultdict(
49-
lambda: lambda model_cls, weights: weights,
49+
lambda: (lambda model_cls, weights: weights),
5050
{
5151
"UNet2DConditionModel": _maybe_expand_lora_scales,
5252
"UNetMotionModel": _maybe_expand_lora_scales,

src/diffusers/models/attention_dispatch.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,29 +3212,26 @@ def _flash_attention_3_varlen_hub(
32123212
if _parallel_config is not None and _parallel_config.context_parallel_config.ring_degree > 1:
32133213
raise NotImplementedError("`ring_degree > 1` is not yet supported for the _FLASH_3_VARLEN_HUB backend.")
32143214

3215-
lse = None
32163215
batch_size, seq_len_q, _, _ = query.shape
32173216
_, seq_len_kv, _, _ = key.shape
32183217

32193218
if _parallel_config is None:
32203219
if attn_mask is not None:
32213220
attn_mask = _normalize_attn_mask(attn_mask, batch_size, seq_len_kv)
3222-
3223-
(_, seqlens_k), (cu_seqlens_q, cu_seqlens_k), (max_seqlen_q, max_seqlen_k) = (
3224-
_prepare_for_flash_attn_or_sage_varlen(
3225-
batch_size, seq_len_q, seq_len_kv, attn_mask=attn_mask, device=query.device
3221+
(_, _), (cu_seqlens_q, cu_seqlens_k), (max_seqlen_q, max_seqlen_k) = (
3222+
_prepare_for_flash_attn_or_sage_varlen_with_mask(batch_size, seq_len_q, attn_mask, query.device)
32263223
)
3227-
)
3228-
3229-
key_valid, value_valid = [], []
3230-
for b in range(batch_size):
3231-
valid_len = seqlens_k[b]
3232-
key_valid.append(key[b, :valid_len])
3233-
value_valid.append(value[b, :valid_len])
3224+
indices_k = attn_mask.flatten().nonzero(as_tuple=False).flatten()
3225+
key_packed = key.reshape(-1, *key.shape[2:])[indices_k]
3226+
value_packed = value.reshape(-1, *value.shape[2:])[indices_k]
3227+
else:
3228+
(_, _), (cu_seqlens_q, cu_seqlens_k), (max_seqlen_q, max_seqlen_k) = (
3229+
_prepare_for_flash_attn_or_sage_varlen_without_mask(batch_size, seq_len_q, seq_len_kv, query.device)
3230+
)
3231+
key_packed = key.flatten(0, 1)
3232+
value_packed = value.flatten(0, 1)
32343233

32353234
query_packed = query.flatten(0, 1)
3236-
key_packed = torch.cat(key_valid, dim=0)
3237-
value_packed = torch.cat(value_valid, dim=0)
32383235

32393236
func = _HUB_KERNELS_REGISTRY[AttentionBackendName._FLASH_3_VARLEN_HUB].kernel_fn
32403237
result = func(

0 commit comments

Comments
 (0)