perf(norm): skip dW/dB calculation when parameters are frozen (#1067) - #1440
Open
piyushumate wants to merge 2 commits into
Open
perf(norm): skip dW/dB calculation when parameters are frozen (#1067)#1440piyushumate wants to merge 2 commits into
piyushumate wants to merge 2 commits into
Conversation
piyushumate
marked this pull request as ready for review
September 4, 2026 04:58
…in#1067) In parameter-efficient fine-tuning (LoRA/PEFT), normalization parameters (weights and biases) are frozen (requires_grad=False). This optimization skips weight and bias gradient computation when parameters are frozen. Key Changes: - Add COMPUTE_DW / COMPUTE_DB compile-time tl.constexpr flags to norm kernels (RMSNorm, LayerNorm, FusedAddRMSNorm) - Skip intermediate reduction buffer allocations (_dW, _DB) and PyTorch .sum(dim=0) reductions - Query ctx.needs_input_grad in autograd backward functions - Pass None for unused gradient pointers - Add comprehensive numerical parity tests across FP32/BF16 Co-authored-by: Yuki Uehara <yukiu00@users.noreply.github.com>
piyushumate
force-pushed
the
perf/lora-skip-norm-dw
branch
from
September 4, 2026 05:57
5282681 to
c33d4b3
Compare
Contributor
Author
|
@vaibhavjindal lemme know your thoughts and if any additional work is needed on this one. Thank you! |
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.
Description
Addresses #1067 (previously explored in #1068)
This PR brings the LoRA normalization optimization across the finish line:
main(cleanly resolving the [Test]: Refactor benchmark_geglu with standardized model configs #1116 benchmark conflicts that blocked Skip norm weight/bias gradients when frozen (LoRA/PEFT optimization) #1068).Nonedirectly for unused gradient pointers).Full co-author credit is preserved for @yukiu00 in the commit.
Motivation
In parameter-efficient fine-tuning (LoRA / PEFT), normalization parameters (weights and biases) are frozen (
requires_grad=False). Previously, Liger-Kernel unconditionally:_dW,_DBof sizesm_count * n_cols) in HBM..sum(dim=0)global reductions to produce tensors that PyTorch autograd immediately discarded.Key Changes
rms_norm.py: AddedCOMPUTE_DW: tl.constexprto_rms_norm_backward_kerneland_block_rms_norm_backward_kernel. Prunes accumulation and memory writes whencompute_dw=False; skips_dWbuffer allocation and reduction; queriesctx.needs_input_grad[1].layer_norm.py: AddedCOMPUTE_DWandCOMPUTE_DBflags to prune weight/bias gradients independently based onctx.needs_input_grad[1]and[2].fused_add_rms_norm.py: AddedCOMPUTE_DWto skip_dWallocation and reduction based onctx.needs_input_grad[2].test/ops/test_norm_lora_parity.py: Added 24 unit tests verifying numerical parity (FP32 & BF16), checking thatw.grad is None/b.grad is Nonewhen frozen, and confirming exactx.gradequality.benchmark/scripts/benchmark_norm_lora.py: Added dedicated standalone LoRA backward microbenchmark.Benchmark Results
NVIDIA A100-SXM4-40GB (
triton.testing.do_bench, bfloat16)NVIDIA A10G (
triton.testing.do_bench, bfloat16)Test Validation
test/ops/test_norm_lora_parity.py: 24 / 24 PASSED (100%)make checkstyle(ruff check&ruff format): PASSED