Change dispatch_model when we have only one device#1648
Merged
SunMarc merged 6 commits intohuggingface:mainfrom Jun 27, 2023
Merged
Change dispatch_model when we have only one device#1648SunMarc merged 6 commits intohuggingface:mainfrom
SunMarc merged 6 commits intohuggingface:mainfrom
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
sgugger
reviewed
Jun 27, 2023
Collaborator
sgugger
left a comment
There was a problem hiding this comment.
Thanks for working on this!
| main_device = "cpu" | ||
| # We attach hooks if the device_map have at least 2 different devices. Otherwise, the model in already loaded | ||
| # in the unique device and the user can decide where to dispatch the model. | ||
| if len(device_map.values()) > 1: |
Collaborator
There was a problem hiding this comment.
I think it's missing an else with model.to() the only device in the dict.
Member
Author
There was a problem hiding this comment.
Oh yeah, we can add that to be sure. However, the model should already be on the right device if the user uses load_checkpoint_in_model or load the model from from_pretrained method
Collaborator
There was a problem hiding this comment.
Yes, but the user might be calling dispatch_model by themselves.
sgugger
approved these changes
Jun 27, 2023
|
Just for googlers, this presents as this exception when the change is pulled down and using Traceback (most recent call last)
[<ipython-input-3-34cc1538f877>](https://localhost:8080/#) in <cell line: 14>()
12
13 tokenizer = AutoTokenizer.from_pretrained(model_id)
---> 14 model = AutoModelForCausalLM.from_pretrained(model_id,
15 quantization_config=bnb_config,
16 device_map={"":0}, trust_remote_code=True)
2 frames
[/usr/local/lib/python3.10/dist-packages/accelerate/big_modeling.py](https://localhost:8080/#) in dispatch_model(model, device_map, main_device, state_dict, offload_dir, offload_index, offload_buffers, skip_keys, preload_module_classes)
387 retie_parameters(model, tied_params)
388 else:
--> 389 device = device_map.values()[0]
390 if device != "disk":
391 model.to(device)
TypeError: 'dict_values' object is not subscriptable |
Merged
Member
Author
|
Thx for testing @zero1zero. Should be fixed in this PR. |
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 ?
This PR changes the behavior of the
dispatch_modelfunction when thedevice_maphave only one device. We don't attach the hooks anymore and the user will be able to move the model with.to(). This change breaks the case where thedevice_mapis{"":'cpu'}or{"":'disk'}where the hooks will dispatch the weights to themain_device. However, this fix will lead to less issues from users who want to usedevice_mapas a regulardeviceparameter.