Repository navigation
Advance the Q-GaLore Adam step counter once per update - #10842
danielhanchen merged 6 commits into
Conversation
bab8bd1 to
aa6d51a
Compare
aa6d51a to
207a084
Compare
|
Confirmed the counter in unsloth/optimizers/q_galore_adamw.py is advanced both inside update_step and again at the end of the loop, so bias correction and the projection refresh gap both run off doubled steps. Will get this reviewed. |
test_optimizer_bias_correction_matches_adamw gates itself on `"cpu" in bitsandbytes.supported_torch_devices`. That attribute does not answer the question. It does not exist before 0.46.0, and from 0.46.0 through 0.49.x it already lists "cpu" even though the CPU optimizer kernels only landed in 0.50.0. So on 0.47.x and 0.49.x the guard passes, the test runs, and it fails. Both are versions pyproject.toml allows (`bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0`, no upper bound). Measured on CPU with torch 2.10.0, before this commit: bnb 0.45.5 24 passed, 1 skipped bnb 0.47.0 1 failed, 24 passed bnb 0.49.2 1 failed, 24 passed bnb 0.50.2 25 passed The failure is the environment, not the code under test: 0.45.5 NameError: name 'str2optimizer32bit' is not defined 0.47.0 AttributeError: 'NoneType' object has no attribute 'shape' 0.49.2 AttributeError: 'NoneType' object has no attribute 'shape' requires_bnb_optimizer() runs one optimizer step and finds out instead. It drives bitsandbytes' own AdamW32bit rather than QGaLoreAdamW8bit, so a genuine regression in the code under test still fails the test rather than quietly becoming a skip. After this commit all four versions are green, with the optimizer case skipped on the three that cannot run it, and 25 passed on 0.50.2 on both CPU and CUDA.
|
Verified. The double increment is real, the removal is the right fix, and the effect is larger than the description suggests. I pushed one fix to your test. Before and after
That feeds two things: Adam bias correction, and the The bias correction damage, against
5.4e-02 at lr 0.1 is about half a step of error. After the fix it sits at 1.5e-05, which is 8-bit state quantization noise. Does it break anythingNo. A 30 step training loop still converges, with and without projection quantization, losses finite throughout. I ran the full file 30 times on a B200 to check for order dependence: 30 out of 30 green, no flakiness. What I pushedYour Measured on CPU with torch 2.10.0, before my commit:
The failure is the environment, not your code: I replaced the guard with I also added a bitsandbytes version axis to Merge note#10874 needed the same guard fix, so both branches now add the same Worth landing this together with #10874. They are independent, but #10874 is the one that makes projected parameters move at all on current bitsandbytes, and the accuracy claim here is only fully visible once both are in. |
|
Confirmed this hits q_galore_adamw.py where state["step"] is advanced again after update_step has already done it, so bias correction and the projection refresh both run on doubled steps. Will get this reviewed. |
|
@codex security review |
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 Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
# Conflicts: # .github/workflows/q-galore-tests.yml
|
Rebased on main now that #10841 has landed, and dropped the workflow from this PR. The standalone This PR no longer touches CI at all, so it is now just the step-counter fix and its test. That also means merge order with #10898 does not matter: only one PR owns the workflow removal. 35 passed locally. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Q-GaLore uses Adam bias-correction steps 1, 3, 5 instead of 1, 2, 3. Three constant-gradient updates leave a parameter at 0.72876 instead of 0.70000.
Cause: bitsandbytes
update_step()increments the counter, then Q-GaLore increments it again. Projection refreshes also run twice as often.Fix: Let bitsandbytes own the increment.
Test:
python -m pytest --confcutdir=tests/utils tests/utils/test_q_galore.py -q: regression fails before; 25 passed after with actual bitsandbytes CPU updates compared againsttorch.optim.AdamW.A dedicated CPU job runs this previously excluded file with Python 3.12, torch 2.10.0 and bitsandbytes 0.50.2. Core/Backend failures also occur on unchanged main.