[RL] Add fp16 training support#3897
Draft
krammnic wants to merge 1 commit into
Draft
Conversation
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
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.
As discussed with @felipemello1 adding the support of the mixed precision training.
Parameters and optimizer state that are preserved in fp32, while FSDP casts parameters in fp16. For the PR the support is currently limited with Qwen model. Furthermore, the additional changes will be required to support MoE. Several new tests were introduced for the proposed changes.
From the non-trivial parts, I believe the only point which is worth clarification for this PR is a correction that is introduced.
The standard flow which I believed to be correct was quite simple:
loss.backward() ->$\nabla$ G$\nabla$ G / S
scaler.unscale_() ->
Therefore, it was important to introduce the correction:
(loss * S).backward ->$\nabla$ S * G$\nabla$ G
scaler.unscale_() ->
In the second case clipping will be applied to the unscaled gradients and optimization step will be correct!
Why it is still draft?
I haven't conducted the E2E run to verify that everything works correctly.