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

enable Pipeline to get device from model #30534

Merged
merged 12 commits into from
May 13, 2024
3 changes: 3 additions & 0 deletions src/transformers/pipelines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ def __init__(

# `accelerate` device map
hf_device_map = getattr(self.model, "hf_device_map", None)
model_device = getattr(self.model, "device", None)

if hf_device_map is not None and device is not None:
raise ValueError(
Expand All @@ -841,6 +842,8 @@ def __init__(
if hf_device_map is not None:
# Take the first device used by `accelerate`.
device = next(iter(hf_device_map.values()))
elif model_device is not None:
device = model_device
else:
device = -1

Expand Down