sd-scripts icon indicating copy to clipboard operation
sd-scripts copied to clipboard

[Bug] TypeError in prepare_buckets_latents.py with --skip_existing due to missing alpha_mask argument

Open ja1496 opened this issue 6 months ago • 0 comments

Hello! I've identified a bug in finetune/prepare_buckets_latents.py that causes a crash when using the --skip_existing flag. Bug Description When running prepare_buckets_latents.py, if the --skip_existing argument is used, the script fails with a TypeError. This happens because the call to train_util.is_disk_cached_latents_is_expected is missing the required alpha_mask argument. The script works correctly if --skip_existing is not used, as the problematic line of code is not executed in that case. To Reproduce Run the prepare_buckets_latents.py script. Include the --skip_existing flag in the arguments. The script will crash when it checks for an existing .npz file. Actual Behavior (Error Log)

Generated code Traceback (most recent call last): File "I:\SDtrain\sd-scripts\ceshi\buckets_latents.py", line 67, in main(args) File "I:\SDtrain\sd-scripts\finetune\prepare_buckets_latents.py", line 178, in main if train_util.is_disk_cached_latents_is_expected(reso, npz_file_name, args.flip_aug): TypeError: is_disk_cached_latents_is_expected() missing 1 required positional argument: 'alpha_mask'

Root Cause Analysis The function signature for is_disk_cached_latents_is_expected in library/train_util.py was updated in a previous commit to require a new alpha_mask parameter: def is_disk_cached_latents_is_expected(reso, npz_path: str, flip_aug: bool, alpha_mask: bool): # ...

However, the corresponding function call in finetune/prepare_buckets_latents.py was not updated to include this new argument. Proposed Fix The fix is straightforward: pass the args.alpha_mask to the function call. File: finetune/prepare_buckets_latents.py Line: around 178 Change from:

if train_util.is_disk_cached_latents_is_expected(reso, npz_file_name, args.flip_aug):

Change to:

if train_util.is_disk_cached_latents_is_expected(reso, npz_file_name, args.flip_aug, args.alpha_mask):

his small change resolves the crash and aligns the script with the current library's function signature. Thanks for your great work on this project! Hope this helps.

ja1496 avatar Jun 19 '25 14:06 ja1496