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

use device_map=auto when accelerate is installed #2666

Merged
merged 1 commit into from Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion deepchecks/nlp/utils/text_properties_models.py
Expand Up @@ -10,6 +10,7 @@
#
"""Module containing the text properties models for the NLP module."""
import importlib
import importlib.util
import pathlib
from functools import lru_cache
from typing import Optional, Union
Expand Down Expand Up @@ -169,6 +170,9 @@ def _get_transformer_pipeline(
"""Return a transformers pipeline for the given model name."""
transformers = import_optional_property_dependency('transformers', property_name=property_name)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name, device_map=device)
# device_map=auto if accelerate is installed
accelerate_is_installed = importlib.util.find_spec('accelerate') is not None
pipeline_kwargs = {'device_map': 'auto'} if accelerate_is_installed else {'device': device}
model = _get_transformer_model(
property_name=property_name,
model_name=model_name,
Expand All @@ -179,7 +183,7 @@ def _get_transformer_pipeline(
'text-classification',
model=model,
tokenizer=tokenizer,
device=device
**pipeline_kwargs
)


Expand Down