-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add BAdam algorithm #3287
Merged
Merged
Conversation
This file contains 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
hiyouga
requested changes
Apr 15, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding this brilliant algorithm to LLaMA Factory, please take a look at my comments, especially the implementation of gradient checkpointing.
hiyouga
approved these changes
Apr 16, 2024
hiyouga
approved these changes
Apr 16, 2024
Some necessary changes are made, it can be merged now |
hiyouga
added
solved
This problem has been already solved
and removed
pending
This problem is yet to be addressed
labels
Apr 16, 2024
How to select Badam in the web interface, instead of the command line? |
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.
What does this PR do?
This PR incorporates the BAdam algorithm to the repository. One can now use BAdam by setting argument "--use_badam". It enables the full parameter finetuning of Llama 2-7b within 24GB RAM under mixed precision training, while using only half time compared with LoRA.
A sample running script is available at "examples/extras/badam/sft.sh". The script attains 0.8591 eval_loss after 900 steps within training time of 3 hours (including evaluation time) on a single RTX-3090. Note that one needs to run
pip install badam
before running the script.Notes
gradient_checkpointing_enable
in "llmtuner/model/patcher.py" is modified to check if any parameter of the checkpointed layer is trainable. If so, it sets the input'srequires_grad
to beTrue
. The modification enables checkpointed layer to be trainable when the input'srequires_grad
isFalse
. Such a modification is essential for the acceleration of BAdam (otherwise, the backward will always go to the first layer, due tomodel.enable_input_require_grads()
, which reduces the training time by half.badam
.Before submitting