fix: disable use_cache during unsloth training to recover v0.8.x VRAM#65
Open
fix: disable use_cache during unsloth training to recover v0.8.x VRAM#65
Conversation
The v0.9 rewrite of the response-only SFT path swapped trl.SFTTrainer for plain transformers.Trainer. SFTTrainer silently sets model.config.use_cache = False in its __init__; plain Trainer does not. Left enabled, the KV cache is materialised through every training forward, inflating VRAM significantly on large-vocab / long-context models (Qwen 3.x, etc.) and breaking jobs that fit comfortably on v0.8.2. This adds apply_training_runtime_fixes(model) right after get_peft_model in the unsloth training entrypoint. It logs use_cache, _attn_implementation, and is_gradient_checkpointing so future runtime regressions are visible in worker logs, and flips use_cache to False when needed. The weighted_sft job already disables use_cache explicitly, so no change is required there. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
The v0.9 rewrite of the response-only SFT path swapped trl.SFTTrainer for plain transformers.Trainer. SFTTrainer silently sets model.config.use_cache = False in its init; plain Trainer does not. Left enabled, the KV cache is materialised through every training forward, inflating VRAM significantly on large-vocab / long-context models (Qwen 3.x, etc.) and breaking jobs that fit comfortably on v0.8.2.
This adds apply_training_runtime_fixes(model) right after get_peft_model in the unsloth training entrypoint. It logs use_cache, _attn_implementation, and is_gradient_checkpointing so future runtime regressions are visible in worker logs, and flips use_cache to False when needed.
The weighted_sft job already disables use_cache explicitly, so no change is required there.