Repository navigation
QLoRA quant-state fallback: gate per weight, not a process-global flag - #14231
Conversation
…al flag; block compile passes checkpoint's stop-recompute through
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
The |
…yer (unslothai#14065) Part of unslothai#14063. ## Summary The fix this PR originally made (re-raise torch's `_StopRecomputationError` from the block-compile trial loop instead of demoting the layer) landed on main separately in unslothai#14231, so the code change here is dropped after merging main. What main does not have is a test for it, so this PR now adds only that: - `test_stop_recomputation_does_not_demote` makes the compiled block raise `torch.utils.checkpoint._StopRecomputationError` and asserts it propagates with the layer still on its first mode and not marked checked. Demoting on it is what made the recompute run the stock forward and fail `check_recomputed_tensors_match` on distributed runs. ## Verification - With main's re-raise reverted (`if False:`), the new test fails; with main as is, it passes. - `tests/test_block_compile.py` on CPU: the new test passes; the one failure there (`test_sm_count_is_read_outside_the_trace`) needs a CUDA device and fails the same way on main without one. The remaining Muse Glimmer route in unslothai#14063 (65 vs 64 with no demotion logged, plus the slowdown) is fixed in unslothai/unsloth-zoo#1895. ## CI fixes pulled in with main Merging main brought in CPU CI failures unrelated to block compile; they are fixed here (tests only, merge base to head touches only `tests/`): - `tests/test_gpt_oss_*`: skip guards read `has_real_cuda()` instead of the spoofable `torch.cuda.is_available()`, and the Hub stub writes with `encoding="utf-8"`. - `tests/test_ddp_comm_defaults.py`: torch refuses `bf16_compress_hook` on builds without CUDA/HIP and NCCL 2.10+ (`DistributedDataParallel._check_comm_hook`), which sank the shared ranks fixture on CPU wheels. The bf16 case now runs only where that same build check passes; the fp16 case still runs on every host. --------- Co-authored-by: Daniel Han <[email protected]>
Summary
Follow-up to the #13880 review.
prepare_fsdp2_qlorasetunsloth.kernels.utils._FSDP2_QLORA_PREPARED = True, and the LoRA getters andfast_lora_forwardread it before falling back to theLinear4bit's ownquant_state. Dynamo guards on a global it reads. Once one FSDP2 QLoRA model had been prepared, every compiled dense LoRA forward in the process compiled a second graph. The fallback is now gated on the weight itself: only an FSDP2 all-gathered 4-bit weight losesquant_state, and its packed bytes are(N, 1). The flag and its setter are removed._StopRecomputationErrorthrough the forward. The block compile wrapper treated that as a compile failure and put the stock forward back in every block. It now re-raises it.Without FSDP2 the getters take the same path as before:
getattr(W, "quant_state")first, and the shape check only runs when that isNone.Tests
tests/python/test_get_lora_parameters_fsdp2_quant_state.py:With the existing fp8 getter tests,
tests/test_block_compile.py,tests/test_fsdp2_qlora.pyandtests/test_fsdp2_qlora_prepare_order.py: 59 passed.Under a 2-rank launch with Unsloth's block compile, Llama, Qwen3, Qwen3-MoE, Gemma3, Gemma4 and Qwen2.5-VL show 0 graph breaks and nothing compiling from step 2 on, LoRA and QLoRA.
Not covered here