Declare gradient accumulation loss scaling with loss_is_scaled_for_ga - #7508
Draft
qgallouedec wants to merge 3 commits into
Draft
qgallouedec wants to merge 3 commits into
qgallouedec wants to merge 3 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses
Trainer.loss_is_scaled_for_ga(huggingface/transformers#49240) to say whethercompute_lossalready scales for gradient accumulation, instead of steering it throughmodel_accepts_loss_kwargsandcompute_loss_func.loss_is_scaled_for_ga = False(Trainer divides by GA steps): DPO, KTO, RLOO, Reward, CPO, ORPO. Replacesself.model_accepts_loss_kwargs = False.loss_is_scaled_for_ga = True(trainer normalizes over the accumulated batch itself): GRPO, Distillation, AsyncGRPO, AsyncDistillation, SDFT, SDPO, SSD. Replacescompute_loss_func="non-None value to disable scaling"plusself.model_accepts_loss_kwargs = False.None.For transformers < 5.19,
_BaseTrainer.__init__maps the flag back to the two attributes, so behaviour there is unchanged. That block goes away when the floor reaches 5.19.Step-1
grad_normfor DPO, Reward and GRPO, batch 4 x GA 1 and batch 2 x GA 2: identical to main on transformers 5.18 and on transformers with #49240.Merge after huggingface/transformers#49240.