Skip norm weight/bias gradients when frozen (LoRA/PEFT optimization)#1068
Open
yukiu00 wants to merge 1 commit intolinkedin:mainfrom
Open
Skip norm weight/bias gradients when frozen (LoRA/PEFT optimization)#1068yukiu00 wants to merge 1 commit intolinkedin:mainfrom
yukiu00 wants to merge 1 commit intolinkedin:mainfrom
Conversation
When using LoRA/PEFT, normalization weights are typically frozen but gradients were still being computed. This PR skips dW/dB computation when parameters have requires_grad=False, providing significant speedups at larger hidden sizes (up to 3x faster backward pass at H=32768). Changes: - Add compute_dW/compute_dB flags to backward kernels (tl.constexpr) - Skip gradient buffer allocation when not needed - Check ctx.needs_input_grad in all norm backward passes - Add frozen weight/bias test coverage for all norm ops - Add mixed RMSNorm+LoRA benchmark - Fix dS_out None check in fused_add_rms_norm_backward Affected ops: RMSNorm, FusedAddRMSNorm, LayerNorm, GroupNorm, PolyNorm No public API changes.
23a0db5 to
8777c9f
Compare
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.
Summary
This PR optimizes norm backward passes for LoRA/PEFT training by skipping weight/bias gradient computation when parameters are frozen (
requires_grad=False).Closes #1067
Motivation
When using LoRA/PEFT, normalization weights are typically frozen but Liger was still computing their gradients. This wastes computation and memory, especially at large hidden sizes common in modern LLMs. See the linked issue for detailed motivation and benchmarks.
Changes
Kernel optimizations:
compute_dW/compute_dBflags to backward kernels (astl.constexprfor dead code elimination)ctx.needs_input_gradin all norm backward passesAffected ops:
Tests:
Benchmarks:
freeze_weightoption to RMSNorm benchmarkBug fixes:
dS_outNone check infused_add_rms_norm_backwardBenchmark Results
RTX 3090, bf16, M=2048
API Impact
*_backwardhelpers now acceptcompute_dW/compute_dBflagsTest Plan