fix(dreambooth): correct batch handling in _prepare_image_ids for flux2 img2img#13821
Open
Jefsky wants to merge 1 commit into
Open
fix(dreambooth): correct batch handling in _prepare_image_ids for flux2 img2img#13821Jefsky wants to merge 1 commit into
Jefsky wants to merge 1 commit into
Conversation
…x2 img2img _prepare_image_ids is designed for multiple reference images within a single sample, assigning different temporal embeddings to distinguish them. However, in the training script, cond_model_input has shape (B, C, H, W) where each batch element is an independent training sample with only one conditional image. The previous implementation split the batch into individual tensors and called _prepare_image_ids on the list, producing different temporal IDs per batch index (T=10, T=20, T=30...). This is incorrect — batch elements are independent and should not have inter-sample temporal relationships. Fix by generating image IDs for a single sample and expanding across the batch dimension, so all samples share the same temporal id. Fixes huggingface#13811
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13811.
In
train_dreambooth_lora_flux2_img2img.py,_prepare_image_idsis called on individual batch elements, which assigns different temporal IDs per sample (T=10, T=20, T=30...). This is incorrect because batch elements are independent training samples with only one conditional image each — they should not have inter-sample temporal relationships.Fix
Generate image IDs for a single sample using
_prepare_image_ids([cond_model_input[0:1]]), then expand across the batch dimension with.expand(batch_size, -1, -1). This ensures all samples share the same temporal id.Why this is correct
_prepare_image_idsis designed for multiple reference images within a single sample, where different temporal embeddings distinguish multiple reference images of the same instance. In the training script, each batch element is an independent sample with one conditional image, so there should be no cross-sample temporal offset.