Revert hack that leads to OOM during fine-tuning #3858
Merged
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.
A few weeks ago, we merged #3830 to temporarily get around an issue of fine-tuning with gradient checkpointing that was introduced with Transformers 4.36. The original issue can be seen here: huggingface/transformers#28023
Since then, they've released a patch release (Transformers 4.36.2) that fixes the original issue for all model types, including Llama-2, Mixtral, Phi etc. However, it seems like the overall interaction between the new transformers version and our hacky fix leads to memory ballooning because we manually map each module to the correct mode, and in the process, set some modules to train mode when they shouldn't be which causes the memory to balloon.
This PR is no longer needed if transformers is set to use 4.36.2 since it has the patch release. I've pinned the minimum version of transformers to this version as part of this PR.