Fix train loss to be normal regardless of num_items_in_batch - #35527
Fix train loss to be normal regardless of num_items_in_batch#35527petil777 wants to merge 1 commit into
Conversation
- Currently num_items_in_batch is calculated by sum of labels having no IGNORE_INDEX - In case labels having some no IGNORE_INDEX, num_items_in_batch is not None, leading to grad_acc not applied
Thanks for the reply. Due to lack of resource, I couldn't fully experiment (Still hard to experiment...). Seems like the code snippet in #35438 may have loss error as you pasted.(Which is kind of default training code, no need to set labels IGNORE_INDEX selectively). |
|
@petil777 No, we didn't use the code from #35438, instead, we performed experiments based this PR (#35527 ). We just want to validate that the code based on this PR is incorrect. |


What does this PR do?
This PR tries to fix train loss scale bug.
Currently, num_items_in_batch is calculated by sum of labels having no IGNORE_INDEX.
In case labels having some no IGNORE_INDEX, num_items_in_batch will be not None, leading to grad_acc not applied.
(Ex. Any kinds of generative loss training having labels to be trained to remember some format)
#35438 also pointed out that this num_items_in_batch can make train loss weird.
Also, #35203 says grad_norm should be fixed by manipulating num_items_in_batch.
I'll close this PR if there is any better fixing logic or this can affect other side effects.
Please fix train loss scale bug in no time.
+) Current code also makes accelerator backward loss bigger if accumulation step is larger with same global_batch settings.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@muellerzr and @SunMarc