[BigModeling] Add missing check for quantized models#1652
Merged
younesbelkada merged 4 commits intomainfrom Jun 28, 2023
Merged
[BigModeling] Add missing check for quantized models#1652younesbelkada merged 4 commits intomainfrom
BigModeling] Add missing check for quantized models#1652younesbelkada merged 4 commits intomainfrom
Conversation
younesbelkada
commented
Jun 28, 2023
src/accelerate/big_modeling.py
Outdated
| else: | ||
| device = list(device_map.values())[0] | ||
| if device != "disk": | ||
| if device != "disk" and not getattr(model, "is_quantized", False): |
Contributor
Author
There was a problem hiding this comment.
we should maybe check with the attributes is_loaded_in_8bit or is_loaded_in_4bit as is_quantized has been only recently introduced. WDYT?
4 tasks
|
The documentation is not available anymore as the PR was closed or merged. |
younesbelkada
commented
Jun 28, 2023
| device = list(device_map.values())[0] | ||
| if device != "disk": | ||
| # for backward compatibility | ||
| is_quantized = getattr(model, "is_quantized", False) or getattr(model, "is_loaded_in_8bit", False) |
Contributor
Author
There was a problem hiding this comment.
getattr(model, "is_loaded_in_8bit", False) --> for backward compatilibty for users that have an old version of transformers (before 4bit integration)
sgugger
approved these changes
Jun 28, 2023
Collaborator
sgugger
left a comment
There was a problem hiding this comment.
Thanks for your PR, added a small comment.
src/accelerate/big_modeling.py
Outdated
Comment on lines
394
to
396
| elif is_quantized: | ||
| pass | ||
| else: |
Collaborator
There was a problem hiding this comment.
Suggested change
| elif is_quantized: | |
| pass | |
| else: | |
| elif not is_quantized: |
Contributor
Author
There was a problem hiding this comment.
Ah added it already b93d93c before your review :D
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.
What does this PR do?
Fixes huggingface/transformers#24540 and the failing test: https://github.com/huggingface/accelerate/actions/runs/5396594202/jobs/9800396637
Currently on the main branch loading a quantized model on a single GPU fails:
In #1648 it seems that a check was missing before calling
.toto the model in case of single GPU model dispatching. Adding a small check circunvemts this issuecc @sgugger @SunMarc