Skip to content

Fix Lion to use decoupled weight decay in the Triton 32-bit kernel#2001

Merged
matthewdouglas merged 2 commits into
bitsandbytes-foundation:mainfrom
eaglstun:fix/lion-triton-decoupled-wd-v2
Jul 16, 2026
Merged

Fix Lion to use decoupled weight decay in the Triton 32-bit kernel#2001
matthewdouglas merged 2 commits into
bitsandbytes-foundation:mainfrom
eaglstun:fix/lion-triton-decoupled-wd-v2

Conversation

@eaglstun

Copy link
Copy Markdown
Contributor

Follow-up to #1993, which fixed the same coupled-vs-decoupled weight-decay bug for Lion in the default backend and the CUDA 32-bit kernel. matthewdouglas invited a Triton follow-up when approving #1993.

_optimizer_update_1state_32bit_triton_kernel folded weight decay into the gradient (coupled L2) for every 1-state optimizer, Lion included. Lion requires decoupled (AdamW-style) decay applied to the param directly (p = 1 - lrwd), outside the sign update (Chen et al. 2023); folding decay into the gradient corrupts the input to sign(), changing the update direction, not just its magnitude. This mirrors the CUDA 32-bit fix exactly: exclude LION (id 4) from the gradient fold, and shrink the param in the LION branch before the sign update.

The existing test_lion32bit_weight_decay (added in #1993) is parametrized over get_available_devices(), so it already exercises this kernel on XPU hardware in CI. Like #1993's CUDA change, the Triton kernel is XPU-only and cannot be built or run on the available hardware.

eaglstun and others added 2 commits July 14, 2026 17:27
Follow-up to bitsandbytes-foundation#1993, which fixed the same coupled-vs-decoupled weight-decay bug
for Lion in the default backend and the CUDA 32-bit kernel. matthewdouglas
invited a Triton follow-up when approving bitsandbytes-foundation#1993.

_optimizer_update_1state_32bit_triton_kernel folded weight decay into the
gradient (coupled L2) for every 1-state optimizer, Lion included. Lion requires
*decoupled* (AdamW-style) decay applied to the param directly (p *= 1 - lr*wd),
outside the sign update (Chen et al. 2023); folding decay into the gradient
corrupts the input to sign(), changing the update direction, not just its
magnitude. This mirrors the CUDA 32-bit fix exactly: exclude LION (id 4) from
the gradient fold, and shrink the param in the LION branch before the sign
update.

The existing test_lion32bit_weight_decay (added in bitsandbytes-foundation#1993) is parametrized over
get_available_devices(), so it already exercises this kernel on XPU hardware in
CI. Like bitsandbytes-foundation#1993's CUDA change, the Triton kernel is XPU-only and cannot be built
or run on the available hardware.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matthewdouglas matthewdouglas added Optimizers Issues or feature requests relating to optimizers Intel labels Jul 15, 2026
@matthewdouglas

Copy link
Copy Markdown
Member

@jiqing-feng Would you mind checking the optimizer tests for this on XPU? At first glance it looks correct to me. Thanks in advance!

@github-actions

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@matthewdouglas matthewdouglas added this to the v0.50.0 milestone Jul 15, 2026
@jiqing-feng

Copy link
Copy Markdown
Contributor

Verified it's okay on XPU with the command python -m pytest tests/test_optim.py -k "xpu and lion" -q:
image

@matthewdouglas
matthewdouglas merged commit a6b6834 into bitsandbytes-foundation:main Jul 16, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Intel Optimizers Issues or feature requests relating to optimizers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants