Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to choose devices for models #264

Merged
merged 1 commit into from
Sep 7, 2023
Merged

Conversation

BramVanroy
Copy link
Contributor

@BramVanroy BramVanroy commented Sep 2, 2023

Currently, there are some issues when loading a transformers model because it explicitly calls .to(device). The default is "cpu" (which is already the default in transformers to begin with). So I recommend to remove device as an argument completely and let the user decide how they want to load the model. That allows things like device_map and loading in kbit. Internally inside the Transformers class nothing changes, but we set self.device to model.device to ensure that everything stays compatible in the rest of the library.

closes #238

@giraffeingreen
Copy link

This addresses a problem that pops up when you've got several GPUs in play. When you set the device-map to 'auto', the model loads onto multiple GPUs just fine. But then, when you try to do 'model.to(device)', it tries to cram everything onto just one GPU.

@brandonwillard
Copy link
Contributor

I've updated this branch with some formatting fixes and test/docstring changes from @rlouf.

@@ -114,7 +114,7 @@ def test_transformers_integration_choice():

def test_transformers_integration_with_pad_token():
model_name = "hf-internal-testing/tiny-random-XLMRobertaXLForCausalLM"
model = models.transformers(model_name, device="cpu")
model = models.transformers(model_name, device="meta")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary in order to get around some "meta device" issues related to accelerate.

@brandonwillard brandonwillard changed the title ADD: more freedom for model loading Allow users to choose devices for models Sep 7, 2023
@brandonwillard brandonwillard added enhancement transformers Linked to the `transformers` integration labels Sep 7, 2023
@rlouf
Copy link
Member

rlouf commented Sep 7, 2023

Thank you @BramVanroy !

@rlouf rlouf merged commit ce0fad4 into outlines-dev:main Sep 7, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement transformers Linked to the `transformers` integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

models.transformers fails when using device_map="auto"
4 participants