Skip to content

Fused LoRA: run PEFT for a partially merged block whose input needs no grad - #14748

Merged
danielhanchen merged 3 commits into
mainfrom
fused-lora-inactive-backward
Oct 25, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fused-lora-inactive-backward

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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:

AttributeError: 'NoneType' object has no attribute 'to'

Reproduced on current main with real PEFT layers on CPU (QKV path, lora_dropout 0.0 and 0.3, k_proj merged).

Change

The disabled / merged branch of _lora_dropout_and_bias also 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:

  • Fully disabled or fully merged blocks route exactly as before (no active adapter).
  • No-grad and inference-mode reference forwards (DPO / GRPO) keep the fused base matmul.
  • Eligible plain LoRA configs never reach the branch.

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.py and were dropped.

Tests

  • New test_partially_merged_block_with_frozen_input_matches_peft in tests/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.py on CPU: 104 passed, 60 skipped (CUDA only).
  • test_routing_compiles_without_graph_breaks, plus a partially merged block under torch.compile(fullgraph=True) with backward: both pass on CPU (torch 2.13).

…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T05:32:32.983133Z 323471f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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]
@danielhanchen danielhanchen changed the title Fused LoRA: run PEFT for disabled or merged adapters when the pass backpropagates Fused LoRA: run PEFT for a partially merged block whose input needs no grad Oct 25, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 323471f013

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 42591ca into main Oct 25, 2026
35 of 37 checks passed
@danielhanchen
danielhanchen deleted the fused-lora-inactive-backward branch October 25, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant