Skip to content

feat: backward compatibility for SD/SDXL latent cache#2276

Merged
kohya-ss merged 2 commits intosd3from
feat-make-multi-reso-sd-sdxl-fallback-backward-compatible
Feb 23, 2026
Merged

feat: backward compatibility for SD/SDXL latent cache#2276
kohya-ss merged 2 commits intosd3from
feat-make-multi-reso-sd-sdxl-fallback-backward-compatible

Conversation

@kohya-ss
Copy link
Copy Markdown
Owner

Prior to #2269, no error was raised if a latent without a resolution suffix differed from the expected latent shape (which occurs when the user defines multiple resolution datasets in the same cache directory). This PR implements that behavior for backward compatibility.

@woct0rdho
Copy link
Copy Markdown
Contributor

woct0rdho commented Feb 23, 2026

In #2269, if the user sets a resolution (for example 512) and the cached latent without resolution suffix is different (for example 768), then LatentsCachingStrategy._default_is_disk_cached_latents_expected will return False, and the training script will compute the new latent and add it to the npz file with suffix 512/8.

I think this is a good default behavior and we don't need to show error or warning in this case. Just like the case if the user sets resolution 512 and the cached latent has resolution suffix 768/8 , then we compute the new latent and add it to the npz file with suffix 512/8, without error or warning.

The old latent will not be removed, and it will be used when the user wants to train again with resolution 768. If the user feels out of disk space, they can manually remove the npz files.

After this PR, the training script shows a warning and loads the latent 768 (not 512). Is it what you intend to do?

@kohya-ss
Copy link
Copy Markdown
Owner Author

Thank you, you have a point. However, I would like to avoid behavior changes when applying a PR.

Before #2269 was applied, if the user set a resolution (e.g., 512) and the cached latent (without the resolution suffix) were different (e.g., 768), LatentsCachingStrategy._default_is_disk_cached_latents_expected would return True and the training script would use variables different from the resolution. This PR reproduces that.

However, this is probably not what you want, so we're displaying a warning.

In any case, this use of a different size latent only occurs in the rare case of a mismatch between the cached latent size and the latent size derived from the current dataset, so it seems simpler to just reproduce the previous behavior rather than checking the size using npz's internal API.

@woct0rdho
Copy link
Copy Markdown
Contributor

I see, now this PR looks good to me.

@kohya-ss
Copy link
Copy Markdown
Owner Author

Thank you for your understanding and for your review! And many thanks again for submitting the original PR.

@kohya-ss kohya-ss merged commit f90fa1a into sd3 Feb 23, 2026
3 checks passed
@kohya-ss kohya-ss deleted the feat-make-multi-reso-sd-sdxl-fallback-backward-compatible branch February 23, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants