PytorchLARS.step() 在默认 momentum=0 设置下发生 UnboundLocalError 导致崩溃
作者: caiotheodoro创建于 2026年9月9日更新于 2026年9月9日
PytorchLARS.step() (bitsandbytes/optim/lars.py) 只在 if momentum != 0: 块中分配 update:
if momentum != 0:
buf = state.get("momentum_buffer", None)
if buf is None:
buf = torch.clone(d_p).detach()
state["momentum_buffer"] = buf
else:
buf.mul_(momentum).add_(d_p, alpha=1 - dampening)
if nesterov:
update = d_p + buf * momentum
else:
update = buf
update_scale = 1.0
if max_unorm > 0.0:
...
p.add_(update, alpha=-lr * update_scale)没有定义 momentum == 0 的 update 的 else 分支,并且 __init__ 中 momentum 默认为 0。因此,在默认构造中,类会崩溃:
内容来源: bitsandbytes-foundation/bitsandbytes