kohya-ss / kohya-ss/sd-scripts
[Clarification] leftover images when the bucket size is indivisible by batch size
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Thanks for the great work.
I read the Novel AI's implementation of bucketing and noticed that the current implementation treats leftover images differently which happens when bucket size is indivisible by batch size. I'd like to confirm my understanding of the issue.
When the bucket is indivisible by the batch size, the current implementation effectively treats the leftover images in a new batch in the same bucket. This will lead to a smaller batch size and cause potential bias. For example, if the bucket size is 13 and the batch size is 4, the 1 image is treated as its own batch. This may cause bias.
https://github.com/kohya-ss/sd-scripts/blob/bc803e01c7028471efc8db5bc9aa183fde06080c/library/train_util.py#L666
Novel AI's implementation will group the leftovers into a "leftover batch" and use the default reso i.e. 512*512 to train them. They ensure the total image counts are divisible so there will not be any further leftovers. Details (lines 148-153):
https://github.com/NovelAI/novelai-aspect-ratio-bucketing/blob/6e977c5475c0fbe0768aaa3da41906e02628ed3b/bucketmanager.py#L148
Do I understand correctly?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading library/train_util.py around line 666 and compare it with NovelAI's bucketmanager.py at lines 148-153. Reproduce the indivisible bucket and batch case described with sizes 13 and 4, then confirm the intended handling and document the expected behavior or requested change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100