Skip to content

Inpainting cleanup: misc fixes following PR #2309 review#2321

Merged
kohya-ss merged 1 commit intodevfrom
cleanup/inpainting-misc
May 6, 2026
Merged

Inpainting cleanup: misc fixes following PR #2309 review#2321
kohya-ss merged 1 commit intodevfrom
cleanup/inpainting-misc

Conversation

@kohya-ss
Copy link
Copy Markdown
Owner

@kohya-ss kohya-ss commented May 6, 2026

Summary

Final cleanup PR for the inpainting feature merged in #2309 (#2319, #2320 covered earlier follow-ups). Bundles six small, independent items:

  • sdxl_train.py — drop leftover .reshape(batch[\"images\"].shape) no-op in the masked-image VAE encode path. Dead since the ff7945d batched-mask fix.
  • model_util.expand_unet_to_inpainting — replace the isinstance(unet.config, dict) guard with unet.register_to_config(in_channels=9) so the diffusers FrozenDict actually gets updated. No functional impact (downstream reads unet.in_channels), but the config attribute is now consistent.
  • sample_image_inference — branch the resolution rounding by pipeline class: SDXL has 2 downsamples (latent /4 → image /32), SD1.5/2.x has 3 (latent /8 → image /64). Also fixes the inaccurate "SDXL requires latents divisible by 8" comment.
  • inpainting_minimal_inference.py — remove the unused denoise() function (actual loop is inlined in main()).
  • BaseDataset.random_mask — drop unused ratio / mask_full_image parameters and the now-dead cloud_mask import; update the single caller.
  • --img--i — rename the per-prompt directive for consistency with Musubi Tuner, which already uses --i alongside the shared w/h/l/d/s directives. Updates docs (EN/JA), the parser, the warning string, and the comment.
    • Bonus fix: when --train_inpainting is set but the prompt has no --i, the code previously warned and fell through to the standard pipeline, which crashes the 9-channel UNet on 4-channel input. Now warns and skips the sample, matching the existing missing-file skip behaviour.

Items #10 and #11 from the original review notes were dropped: #10's described problem doesn't actually exist (the script already splits vae_dtype/weight_dtype correctly), and the gen_img.py --i precedent referenced in the original #11 came from a sibling repo (Musubi Tuner) — the rename is still useful for cross-repo consistency.

Test plan

  • # 4 — sdxl_train inpainting training step runs
  • # 6 — training with diffusers UNet path runs (config update no longer raises)
  • # 7' — verified resolution gets rounded as expected
  • # 8 — inpainting_minimal_inference.py still runs end-to-end
  • # 9 — training with --train_inpainting runs (caller path exercised)
  • # 11 — --i works; --img is silently ignored; missing --i now warns + skips instead of crashing the 9ch UNet

🤖 Generated with Claude Code

- sdxl_train: drop leftover .reshape(batch["images"].shape) no-op in
  masked-image VAE encode (dead since the ff7945d batched-mask fix).
- model_util.expand_unet_to_inpainting: use unet.register_to_config(in_channels=9)
  so the diffusers FrozenDict stays in sync (the previous isinstance(..., dict)
  guard either silently skipped or raised, depending on diffusers version).
- sample_image_inference: round resolution to mod-32 for SDXL (2 downsamples,
  latent /4) and mod-64 for SD1.5/2.x (3 downsamples, latent /8); fix the
  inaccurate "SDXL requires latents divisible by 8" comment.
- inpainting_minimal_inference: remove unused denoise() — the actual loop is
  inlined in main().
- BaseDataset.random_mask: drop unused ratio / mask_full_image parameters and
  the dead cloud_mask import.
- Rename per-prompt --img directive to --i for consistency with Musubi Tuner
  (which already uses --i alongside the shared w/h/l/d/s directives).
- When --train_inpainting is set but the prompt has no --i, warn and skip the
  sample instead of falling through to the standard pipeline (which would
  crash the 9-channel UNet on 4-channel input). Matches the existing
  missing-file skip behaviour.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@kohya-ss kohya-ss merged commit 0030aa9 into dev May 6, 2026
3 checks passed
@kohya-ss kohya-ss deleted the cleanup/inpainting-misc branch May 6, 2026 02:22
kohya-ss added a commit that referenced this pull request May 6, 2026
…tional

PR #2321 changed sample_image_inference to return early when
--train_inpainting is set and a prompt line has no --i directive.
The doc still described the previous behavior.
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.

1 participant