Skip norm weight/bias gradients when frozen (LoRA/PEFT optimization) #1068
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