kohya-ss / kohya-ss/sd-scripts
SDXL 1024 training - images assigned to wrong buckets
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
I'm training a SDXL Lora and I don't understand why some of my images end up in the 960x960 bucket. Shouldn't the square and square like images go to the 1024x1024 bucket, provided the img resolution is high enough? This might be a problem with the script or perhaps I'm misunderstanding how images are assigned to buckets.... Can anyone shed some light on this?
I've got 27 high-res images (see below). As you can see there is only a single image with width < 1024, but it's 988x1756 so it should go to one of the tall portrait buckets, right?
And this is how the buckets are reported (img repeat is set to 5), so 2 images are assigned to the 960x960 bucket:
> bucket 0: resolution (768, 1216), count: 5
> bucket 1: resolution (768, 1344), count: 5
> bucket 2: resolution (832, 1088), count: 5
> bucket 3: resolution (896, 1024), count: 10
> bucket 4: resolution (896, 1088), count: 5
> **bucket 5: resolution (960, 960), count: 10**
> bucket 6: resolution (960, 1024), count: 20
> bucket 7: resolution (960, 1088), count: 10
> bucket 8: resolution (1024, 896), count: 5
> bucket 9: resolution (1024, 960), count: 20
> bucket 10: resolution (1088, 832), count: 5
> bucket 11: resolution (1152, 832), count: 10
> bucket 12: resolution (1152, 896), count: 10
> bucket 13: resolution (1216, 832), count: 5
> bucket 14: resolution (1280, 768), count: 5
> bucket 15: resolution (1344, 768), count: 5
Below is my training command. The training resolution is 1024x1024, buckets are enabled, bucket upscale is disabled, bucket resolution is 64.
> accelerate launch --num_cpu_threads_per_process=2 "./sdxl_train_network.py" **--enable_bucket**
> --min_bucket_reso=512 --max_bucket_reso=2048
> --pretrained_model_name_or_path="E:/Automatic1111/stable-diffusion-webui/models/Stable-diffusio
> n/sd/sdXL_v10VAEFix.safetensors" --train_data_dir="E:/Automatic1111/datasets/mona/train_v2"
> **--resolution="1024,1024"** --output_dir="E:/Automatic1111/datasets/mona/output"
> --logging_dir="E:/Automatic1111/datasets/mona/logs" --network_alpha="1"
> --training_comment="mona" --save_model_as=safetensors --network_module=networks.lora
> --text_encoder_lr=0.0003 --unet_lr=0.0003 --network_dim=32 --output_name="sdxl_mona3"
> --lr_scheduler_num_cycles="10" --cache_text_encoder_outputs --no_half_vae --full_bf16
> --learning_rate="0.00035" --lr_scheduler="constant" --train_batch_size="1"
> --max_train_steps="1350" --save_every_n_epochs="1" --mixed_precision="bf16"
> --save_precision="bf16" --caption_extension="txt" --cache_latents --cache_latents_to_disk
> --optimizer_type="Adafactor" --optimizer_args scale_parameter=False relative_step=False
> warmup_init=False --max_data_loader_n_workers="0" **--bucket_reso_steps=64** --flip_aug --xformers
> **--bucket_no_upscale** --noise_offset=0.0357 --network_train_unet_only --sample_sampler=k_dpm_2
> --sample_prompts="E:/Automatic1111/datasets/mona/output\sample\prompt.txt"
> --sample_every_n_epochs="1"
I'm using kohya_gui on windows. I have already posted this issue a week ago [there](https://github.com/bmaltais/kohya_ss/issues/1299), but I didn't receive any answer, except someone else reporting similar issues. I believe kohya gui was synchronized with kohya scripts two days ago and the issue is still there.
Also, when testing on a larger dataset with 160+ images, and the same bucket/resolution settings, I get proper assignment and the square bucket is 1024x1024. I have no idea what makes this smaller dataset create such small buckets. Other than the buckets being wrong, everything else seems to be working fine but of course I'm worried that I'm training in suboptimal resolution.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with sdxl_train_network.py and reproduce the reported command using --enable_bucket, --resolution="1024,1024", --bucket_reso_steps=64, and --bucket_no_upscale. Trace the bucket assignment output for the 27-image dataset and compare it with the larger dataset; done means the assignment behavior is explained and any discrepancy is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100