Repository navigation
Pass Q-GaLore optimizer options to bitsandbytes by name - #10874
Conversation
|
Confirmed the positional super().init call in unsloth/optimizers/q_galore_adamw.py still binds percentile_clipping and block_wise by position, which silently changes the update on newer bitsandbytes, and switching to keywords looks like the right fix. Will get this reviewed. |
test_default_optimizer_updates_match_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 four parametrisations run, and all four fail. Both are versions pyproject.toml allows (`bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0`, no upper bound), and neither is the 0.50.2 this PR's own workflow pins, so CI would not have caught it. Measured on CPU with torch 2.10.0, before this commit: bnb 0.45.5 25 passed, 6 skipped bnb 0.47.0 4 failed, 25 passed, 2 skipped bnb 0.49.2 4 failed, 25 passed, 2 skipped bnb 0.50.2 31 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, and 31 passed on 0.50.2 on both CPU and CUDA. The two options tests are unaffected: they only construct the optimizer, which works on every version in the range.
|
Confirmed the positional super().init call in unsloth/optimizers/q_galore_adamw.py is what misbinds percentile_clipping and block_wise on newer bitsandbytes, and passing by name is the right fix. Could you note the oldest bitsandbytes version you tested this against so I can check the guard path before review? |
|
This is the most serious of the three. On current bitsandbytes, Q-GaLore on main does not train at all, and this PR is what fixes it. Verified on hardware. I pushed one fix to your tests. What is actually brokenbitsandbytes 0.50.0 removed
update_scale = sqrtf(unorm[0]);
if (update_scale > max_unorm * param_norm) update_scale = (max_unorm * param_norm) / update_scale;and Measured, 5 steps, max absolute change in a GaLore-projected parameter, bitsandbytes 0.50.2 on a B200:
Same picture in a real 30 step training loop, where the projected layer is frozen and only the non-projected layer learns:
Does it break old installsNo, and I checked rather than assumed. The positional call was correct on every release up to and including 0.49.2. Argument binding after this PR, same probe:
The introspection branch does the right thing in both directions: on old bitsandbytes the two options are forwarded by name, on new bitsandbytes a non-default value raises instead of being silently misapplied. That new What I pushedYour Measured on CPU with torch 2.10.0, before my commit:
I also added a bitsandbytes version axis to Your two options tests are fine as written and needed no change. Merge note#10842 needed the same guard fix, so both branches now add the same This one should go in first of the three. Good find. |
|
@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 Review: Didn't find any major issues. Nice work! 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". |
🛡️ 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. 🚀 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
The bitsandbytes version axis that used to live in a workflow of its own now lives where the repo already keeps this kind of check. tests/version_compat/ test_bitsandbytes_pinned_symbols.py is parametrised over 0.45.5, 0.47.0, 0.49.2 and main, reads the upstream source directly and needs no install, so it covers the same ground for free in a job that already runs. The new case reads Optimizer2State.__init__'s parameter list at each tag and asserts this repo does not pass into it positionally. 0.50.0 removed percentile_clipping and block_wise, so positions 10 and 11 became max_unorm and skip_zeros; arity still matched and nothing raised, which is why the misbinding reached main at all. It fails against the positional call on main and passes here, so it belongs with this fix rather than ahead of it.
|
Rebased on main now that #10841 has landed, and dropped the workflow from this PR. The standalone The bitsandbytes version axis that workflow provided has not been dropped, it has moved somewhere better. It lives here rather than in #10898 because it fails against the positional call still on main and passes against this PR's fix, so it belongs with the fix. Verified both ways: 4 failed on main, 8 passed here. 42 passed locally, plus the version-compat cases. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8779e74722
ℹ️ 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".
| ) | ||
| for name in ("percentile_clipping", "block_wise"): | ||
| if name in call: | ||
| assert f"{name} = " in call or f'"{name}"' in call, ( |
There was a problem hiding this comment.
Inspect the actual superclass call for keyword forwarding
This assertion is already satisfied by the quoted names in the preceding legacy_kwargs tuple, regardless of how super().__init__ receives those values. If a later edit retains that tuple but passes percentile_clipping or block_wise positionally again, every tag will still pass this version-compat test while the silent Q-GaLore update freeze returns; parse or isolate the superclass call before checking for keyword arguments.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it was a tautology. The slice ran from class QGaLoreAdamW8bit to the next decorator, so it covered the legacy_kwargs table where both names appear as quoted strings. That alone satisfied the "{name}" branch, so the assertion passed no matter how super().init was actually invoked. A regression to a positional call would have kept all four tags green, which is the one thing this test existed to prevent.
Fixed in 2a668df by locating the call with ast instead of grepping the body. It now asserts on the call node itself: everything after "adam" and params must be a keyword, and an option bitsandbytes has dropped at that tag must not be passed at all.
The difference is measurable, and the old version could not show it. Against the positional constructor still on main all four tags now fail; against this PR's constructor all four pass.
The keyword assertion was tautological. It searched the whole class body, which also contains the legacy_kwargs table where "percentile_clipping" and "block_wise" appear as quoted strings, so the check was satisfied by that table alone and passed whether or not super().__init__ actually used keywords. A regression to a positional call would have kept every tag green. Now the call itself is located with ast and asserted on: everything after "adam" and params must be a keyword, and an option bitsandbytes has dropped at that tag must not be passed at all. Checked both ways, which the previous version could not do: against the positional call still on main all four tags fail, and against this PR's constructor all four pass.
# Conflicts: # tests/utils/test_q_galore.py
|
@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 freezes projected parameters using bitsandbytes 0.50.2's FP32 state fallback, despite nonzero gradients.
Cause: Removed positional options now bind percentile_clipping=100 to max_unorm and block_wise=True to skip_zeros. Norm clipping against the zero-filled update buffer erases the update.
Fix: Pass optimizer arguments by name. Forward legacy options only when supported and reject unsupported nondefaults. Add a CPU job for the excluded Q-GaLore suite.
Test: Three CPU update regressions fail before; all 31 tests pass afterward with bitsandbytes 0.50.2, including AdamW comparisons and legacy-constructor forwarding. Changed-file pre-commit and the workflow guard pass.