Fix circular import between utils.bnb and big_modeling - #4174
Open
shubhxho wants to merge 2 commits into
Open
Conversation
Import dispatch_model/init_empty_weights only inside the functions that need them so concurrent imports of accelerate.utils and accelerate.big_modeling no longer hit a partial-initialization ImportError. Fixes huggingface#4173
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.
Fixes #4173
Summary
accelerate.utils.bnbimporteddispatch_modelandinit_empty_weightsat module level, which closed a cycle:utils→bnb→big_modeling→hooks→utilsSingle-threaded imports usually survived by accident. Concurrent imports of
accelerate.utilsandaccelerate.big_modelingfailed with a partial-initializationImportError.Those names are only used inside
load_and_quantize_modelandget_keys_to_not_convert, so they are imported there instead. Public exports are unchanged.The diagnosis and this cut are from @adrihans on #4173.
Tests
Passed 4 times locally (Python 3.12, torch 2.13.0, macOS arm64). The same test fails on unpatched
mainwith:AI assistance was used to apply the change and write the regression test. I reviewed the diff.