You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] train_dreambooth_lora_qwen_image.py crashes with --with_prior_preservation due to tensor concatenation errors #13386
When running the train_dreambooth_lora_qwen_image.py script with the --with_prior_preservation flag, the training crashes during the text embedding extraction phase. There are two distinct bugs related to tensor concatenation at L1323 and L1324.
Bug 1: Shape mismatch for prompt_embeds (L1323)
RuntimeError: Sizes of tensors must match except in dimension 0.
QwenImage's _get_qwen_prompt_embeds() pads sequences dynamically to the longest prompt in the current call, rather than a fixed global maximum length. If the instance_prompt (e.g., "sks stuffed animal") and class_prompt (e.g., "photo of a stuffed animal") are encoded separately, their resulting prompt_embeds can have different sequence lengths (e.g., dimension 1 is 9 vs. 12). Directly using torch.cat([prompt_embeds, class_prompt_embeds], dim=0) causes a dimension mismatch.
Bug 2: NoneType concatenation for prompt_embeds_mask (L1324)
TypeError: expected Tensor as element 0 in argument 0, but got NoneType
During encoding, if the attention mask consists entirely of 1s (meaning all text tokens are valid and no explicit masking is required), the QwenImage pipeline actively folds the mask into None (see pipeline_qwenimage.py:253). Consequently, both prompt_embeds_mask and class_prompt_embeds_mask are returned as None. Passing a list of None types to torch.cat throws a TypeError.
**Traceback for Bug 1 (Sequence Length Mismatch):**
[rank0]: Traceback (most recent call last):
[rank0]: File "train_dreambooth_lora_qwen_image.py", line 1704, in<module>
[rank0]: main(args)
[rank0]: File "train_dreambooth_lora_qwen_image.py", line 1323, in main
[rank0]: prompt_embeds = torch.cat([prompt_embeds, class_prompt_embeds], dim=0)
[rank0]: RuntimeError: Sizes of tensors must match except in dimension 0. Expected size 9 but got size 12 fortensor number 1in the list.
**Traceback for Bug 2 (NoneType Concatenation):**
_(Note: If you patch Bug 1 to pad the tensors, the script will immediately hit this second error)_
[rank0]: Traceback (most recent call last):
[rank0]: File "train_dreambooth_lora_qwen_image.py", line 1713, in<module>
[rank0]: main(args)
[rank0]: File "train_dreambooth_lora_qwen_image.py", line 1333, in main
[rank0]: prompt_embeds_mask = torch.cat([prompt_embeds_mask, class_prompt_embeds_mask], dim=0)
[rank0]: TypeError: expected Tensor as element 0 in argument 0, but got NoneType
changed the title [-]`train_dreambooth_lora_qwen_image.py` crashes with `--with_prior_preservation` due to tensor concatenation errors[/-][+][Bug] `train_dreambooth_lora_qwen_image.py` crashes with `--with_prior_preservation` due to tensor concatenation errors[/+]on Apr 2, 2026
Activity
[-]`train_dreambooth_lora_qwen_image.py` crashes with `--with_prior_preservation` due to tensor concatenation errors[/-][+][Bug] `train_dreambooth_lora_qwen_image.py` crashes with `--with_prior_preservation` due to tensor concatenation errors[/+]