Skip to content

LoRA MLP: build the skipped down projection output out of place - #18656

Merged
danielhanchen merged 1 commit into
mainfrom
ci/fast-lora-skip-down-out-of-place
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/fast-lora-skip-down-out-of-place

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, rest) is red on main (seen on #18650, reproduced on current main):

FAILED tests/test_autograd_inplace_outputs.py::test_no_inplace_mutation_of_returned_fresh_tensors
AssertionError: unsloth/kernels/fast_lora.py:686 LoRA_MLP: i.fill_(_SKIPPED_FILL)

Cause

#18607 (skip the LoRA MLP down projection in gradient checkpoint replays) builds the skipped output as i = X.new_empty(X.shape). When the test-only _SKIPPED_FILL sentinel is set, it then calls i.fill_(_SKIPPED_FILL). i is returned from LoRA_MLP.forward.

The guard exists because torch 2.11 compiles a wrong gradient for an ATen in-place op on a fresh tensor a torch.autograd.Function forward returns (#14712), and the block-compile path (#18641) traces this forward. The guard is right, and the skip itself is right: only the mutation needs to go.

Change

  • unsloth/kernels/fast_lora.py: allocate the skipped output already filled, X.new_full(X.shape, _SKIPPED_FILL), when the sentinel is set. Otherwise it stays X.new_empty(X.shape). The values are identical (new_empty + fill_ and new_full both give a tensor of that shape full of that value), and production never sets the sentinel. There is no in-place op left on the returned tensor.

Testing

  • tests/test_autograd_inplace_outputs.py fails on main with the line above and passes with this change.
  • tests/test_gc_skip_replay_mlp_down.py and tests/test_autograd_inplace_outputs.py on CPU: 20 passed, 6 skipped. The skipped six need CUDA.
  • Not run here: those six CUDA tests, which fill the skipped output with NaN to prove nothing reads it, and test_gc_skip_replay_mlp_down_block_compile.py (torch >= 2.11 with CUDA). This host has no local GPU for this session, and the remote attempt failed in dependency setup before any test ran. CI's GPU jobs will exercise them.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T18:23:08.473363Z 1fce60f 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 1fce60f2c6

ℹ️ 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 ae21745 into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the ci/fast-lora-skip-down-out-of-place branch November 20, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant