Skip to content

Commit 7aa17ce

Browse files
authored
Merge pull request #1 from eaglstun/mps-lion-triton-32bit
Fix Lion decoupled weight decay in the Triton 32-bit kernel
2 parents 5e7ff4e + 45813c3 commit 7aa17ce

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bitsandbytes/backends/triton/kernels_optim.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ def _optimizer_update_1state_32bit_triton_kernel(
270270
s1_vals = tl.load(state1_ptr + offsets, mask=mask, other=0.0)
271271

272272
g_vals = gnorm_scale * g_vals
273-
if weight_decay > 0.0:
273+
# Coupled (L2) weight decay: fold wd into the gradient. This is correct for
274+
# MOMENTUM/RMSPROP/ADAGRAD, but NOT for LION (id 4), which uses *decoupled*
275+
# (AdamW-style) weight decay applied to the param directly (see the LION branch
276+
# below and Chen et al. 2023). LION is intentionally excluded here.
277+
if OPTIMIZER_ID != 4 and weight_decay > 0.0:
274278
g_vals = g_vals + p_vals * weight_decay
275279

276280
update_scale = 1.0
@@ -289,6 +293,12 @@ def _optimizer_update_1state_32bit_triton_kernel(
289293
p_vals = p_vals + update_val
290294

291295
elif OPTIMIZER_ID == 4: # LION
296+
# Lion uses decoupled weight decay: shrink the param directly (p *= 1 - lr*wd)
297+
# rather than folding wd into the gradient. Matches the 8-bit blockwise kernel,
298+
# the default/cpu backends, and the Lion paper (Chen et al. 2023).
299+
if weight_decay > 0.0:
300+
p_vals = p_vals * (1.0 - lr * weight_decay)
301+
292302
momentum_update = s1_vals * beta1 + (1.0 - beta1) * g_vals
293303
update_val = update_scale * lr * tl.where(momentum_update > 0, 1.0, tl.where(momentum_update < 0, -1.0, 0.0))
294304
p_vals = p_vals - update_val

0 commit comments

Comments
 (0)