Repository navigation
Conversation
Signed-off-by: Afloat <ShuffleMonkey@163.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Bitsandbytes optimizers inherit
register_load_state_dict_pre_hookandregister_load_state_dict_post_hook, but theirload_state_dictoverride never calls them. Checkpoint adaptation therefore silently fails: a registered pre-hook cannot migrate saved parameter groups before validation, and a registered post-hook cannot run after restoration.Change
Invoke the existing pre-hook registry on a shallow copy, honoring replacement dictionaries, then retain the existing deep copy, FSDP quantization-state unwrapping, dtype/device handling and validation. Invoke post-hooks only after the state has been installed successfully. Ordering,
prepend=True, and handle removal use the inherited registries.The loader continues to avoid modifying checkpoint data during its own unwrap/cast operations. User pre-hooks keep PyTorch's normal shallow-copy semantics for nested data.
Validation
Base
a616886cacf86701514f0cb1d6be760f967481c0; patch5fc14afef96ad3e2c2bfd387b8b3587b861082cf.move_to_deviceflags, and validation failure without a post-hook call.git diff --checkpass.BNB_TEST_DEVICE=cpu OMP_NUM_THREADS=2 python -m pytest tests/test_optim.py -k 'load_state_dict_hook or load_state_dict_post_hook or ademamix_state_dict' -qPython 3.12.14 / PyTorch 2.15.0+cpu; current bitsandbytes native CPU library built from source. GPU/distributed execution and the complete test suite were not run.
Checked the optimizer file history, current PR catalog and all-state checkpoint/hook searches. The related FSDP prototype #2081 changes an example, and #1958 fixes module serialization; neither implements optimizer load hooks.