Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix incorrect batch temporal IDs for cond_model_input in Flux2 Klein img2img training#13923

Merged
sayakpaul merged 1 commit into
huggingface:mainfrom
HaozheZhang6:fix/flux2-klein-cond-image-ids
Jun 12, 2026
Merged

Fix incorrect batch temporal IDs for cond_model_input in Flux2 Klein img2img training#13923
sayakpaul merged 1 commit into
huggingface:mainfrom
HaozheZhang6:fix/flux2-klein-cond-image-ids

Conversation

@HaozheZhang6

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #13866

train_dreambooth_lora_flux2_klein_img2img.py builds the conditional-image position ids wrong for a batch:

cond_model_input_list = [cond_model_input[i].unsqueeze(0) for i in range(cond_model_input.shape[0])]
cond_model_input_ids = Flux2KleinPipeline._prepare_image_ids(cond_model_input_list)...

_prepare_image_ids is meant for multiple reference images of one instance — it assigns each list element a different temporal coordinate (T = scale + scale*i → 10, 20, 30, …). But here each batch element is an independent training sample with a single conditional image, so they all get spurious cross-sample temporal offsets instead of the same T.

Fix: generate ids for one sample and expand across the batch, so every sample shares T = 10. This is the Flux2 Klein counterpart of the same bug/fix in train_dreambooth_lora_flux2_img2img.py (#13811).

Verification

Flux2KleinPipeline._prepare_image_ids on a (3, 4, 4, 4) input (CPU, no weights):

OLD T per-batch (unique): [10, 20, 30]   # cross-sample offsets = the bug
NEW T per-batch (unique): [10, 10, 10]   # independent samples share one temporal id
shapes: (3, 16, 4) (3, 16, 4)            # output shape unchanged

Before submitting

Who can review?

@sayakpaul @linoytsaban

…n img2img training

`train_dreambooth_lora_flux2_klein_img2img.py` passed the whole batch to
`Flux2KleinPipeline._prepare_image_ids` as a list of reference images, so each
independent training sample got a different temporal id (T=10, 20, 30, ...) as if
they were multiple references of one instance. Each batch element is an independent
sample with a single conditional image, so they must share the same temporal id.

Generate ids for one sample and expand across the batch. This is the Flux2 Klein
counterpart of the same bug/fix in `train_dreambooth_lora_flux2_img2img.py` (huggingface#13811).

Fixes huggingface#13866
@github-actions github-actions Bot added size/S PR with diff < 50 LOC fixes-issue examples and removed fixes-issue labels Jun 11, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul

Copy link
Copy Markdown
Member

Failing tests are unrelated.

@sayakpaul sayakpaul merged commit bc6e1f2 into huggingface:main Jun 12, 2026
28 of 30 checks passed
DN6 pushed a commit that referenced this pull request Jul 1, 2026
…n img2img training (#13923)

`train_dreambooth_lora_flux2_klein_img2img.py` passed the whole batch to
`Flux2KleinPipeline._prepare_image_ids` as a list of reference images, so each
independent training sample got a different temporal id (T=10, 20, 30, ...) as if
they were multiple references of one instance. Each batch element is an independent
sample with a single conditional image, so they must share the same temporal id.

Generate ids for one sample and expand across the batch. This is the Flux2 Klein
counterpart of the same bug/fix in `train_dreambooth_lora_flux2_img2img.py` (#13811).

Fixes #13866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flux2-klein lora train,bug

3 participants