Repository navigation
Make AdEMAMix32bit inherit AdEMAMix so it allocates the double state buffer - #2076
Conversation
…buffer AdEMAMix32bit and PagedAdEMAMix32bit subclassed Optimizer2State directly, so they never used AdEMAMix.init_state and allocated state1 with the shape of the parameter instead of (2, *p.shape). The ademamix kernels read m2 from the second half of state1, so on the CPU and default backends the first step raised RuntimeError, and the t_alpha/t_beta3 schedulers were silently ignored. Subclass AdEMAMix with optim_bits=32, mirroring AdEMAMix8bit, and add a test comparing both classes against AdEMAMix(optim_bits=32).
|
Could a maintainer take a look at this when there's time? The main decision is whether re-parenting |
|
Bumping this. The fix is a one-line re-parent to match how |
|
Is re-parenting |
|
anyone have a minute for this? it's a one-line re-parent for #2075, and if you'd rather fix the allocation in |
|
Thanks for the fix, subclassing AdEMAMix is the right approach. I simplified the test a bit: instead of the new test, the existing state dict test had two |
|
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. |
4ee340f
into
bitsandbytes-foundation:main
Fixes #2075.
AdEMAMix32bitandPagedAdEMAMix32bitsubclassedOptimizer2Statedirectly, sostate1was allocated asp.shapeinstead of(2, *p.shape)and thet_alpha/t_beta3scheduler inAdEMAMix.update_stepnever ran. On the CPU and default backends the firststep()raisedRuntimeError: output with shape [] doesn't match the broadcast shape [4096]. This re-parentsAdEMAMix32bitontoAdEMAMixwithoptim_bits=32, mirroringAdEMAMix8bit.PagedAdEMAMix32bitinherits the change. The constructor signature and defaults are unchanged.New test
test_ademamix32bit_matches_ademamixsteps both classes next toAdEMAMix(optim_bits=32)for 5 steps, scheduled and unscheduled, and assertsstate1.shape == (2, 4096)plus equalstate1,state2and parameters. Onmainit fails 6 of 6 with the RuntimeError above. On this branch 6 pass and 2 skip (paged on CPU, following the existing convention intest_optimizer32bit).Checks run on macOS arm64 (CPU build plus MPS), torch 2.14.0, Python 3.13.12:
pytest tests/test_optim.py -k ademamix -n 4: 32 failed, 90 passed, 26 skipped on this branch; 32 failed, 84 passed, 24 skipped onmain. The 32 failures are the same MPS-only cases on both trees (optimizer_update_8bit_blockwiseand paged buffers are not implemented on MPS)._ReferenceAdEMAMixonmainand on this branch. The 72AdEMAMix32bitandPagedAdEMAMix32bitcases go from RuntimeError to parameters bit-identical withAdEMAMix(optim_bits=32). The other 108 cases produce identical bytes on both trees.pre-commit run --all-files: all hooks pass.I could not run the CUDA kernel.
kOptimizer32bit2Stateloads m2 fromstate1[n + i], so on CUDA the old single-size buffer was read past its end.Drafted with Claude Opus / Fable 5.1.