Repository navigation
Fused LoRA: run PEFT for a partially merged block whose input needs no grad - #14748
Merged
Merged
Conversation
…ckpropagates get_lora_parameters gives the fused QKV / O / MLP Functions no LoRA weights for a disabled or merged projection, and their backward reads them unconditionally, so any backward through such a projection raised AttributeError: 'NoneType' object has no attribute 'to'. Route those passes to PEFT (the base layer alone); no_grad reference passes keep the fused base-only route.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
… input needs no grad main (#14806) already falls back to PEFT for disabled or merged adapters when X or the base weight requires grad. What it misses: X without grad (frozen embeddings, no input-grad hook) and some projections merged while the block's other adapters train. Add that check and a regression test; drop the PR's tests that #14806's suite now covers. [skip ci]
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Problem
#14806 (merged) made the fused LoRA routing fall back to PEFT for a disabled or merged projection when a gradient is needed. It decides "gradient needed" from the input and the projection's base weight:
X.requires_grad or base_weight.requires_grad. One case gets past that check. X does not require grad (frozen embeddings with no input-grad hook, for example layer 0 without gradient checkpointing), some projections in the block are merged, and the block's other adapters still train. The block then runs fused, autograd calls the fused backward for the trainable adapters, and the backward reads the missing LoRA weights of the merged projection:Reproduced on current main with real PEFT layers on CPU (QKV path,
lora_dropout0.0 and 0.3,k_projmerged).Change
The disabled / merged branch of
_lora_dropout_and_biasalso hands the block to PEFT when grad mode is on and any active adapter in the block has a trainable LoRA weight (_active_lora_requires_grad). The extra check only runs on that branch, after grad mode, the input and the base weight have been checked, so:This PR originally carried the whole disabled / merged fallback. #14806 landed the same fix first, so this PR was merged with main and cut down to the remaining case. Its earlier tests are covered by
tests/test_fused_lora_peft_fallbacks.pyand were dropped.Tests
test_partially_merged_block_with_frozen_input_matches_peftintests/test_fused_lora_peft_fallbacks.py(qkv on CPU, qkv and mlp on CUDA; dropout 0.0 / 0.3). It checks that no fused Function runs, and that outputs and every LoRA grad match PEFT bitwise. It fails on main and passes here.tests/test_fused_lora_peft_fallbacks.py+tests/test_fused_lora_dropout_bias.pyon CPU: 104 passed, 60 skipped (CUDA only).test_routing_compiles_without_graph_breaks, plus a partially merged block undertorch.compile(fullgraph=True)with backward: both pass on CPU (torch 2.13).