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

Better pipeline defaults #34026

Merged
merged 8 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/transformers/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,8 @@ def _prepare_generated_length(
and not self.config.is_encoder_decoder
):
generation_config.max_length -= inputs_tensor.shape[1]
else: # by default let's always generate 10 new tokens
generation_config.max_length = generation_config.max_length + input_ids_length

# same for min length
if generation_config.min_new_tokens is not None:
Expand Down
17 changes: 4 additions & 13 deletions src/transformers/pipelines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,18 +881,7 @@ def __init__(
# Take the first device used by `accelerate`.
device = next(iter(hf_device_map.values()))
else:
device = -1
if (
is_torch_mlu_available()
or is_torch_cuda_available()
or is_torch_npu_available()
or is_torch_xpu_available(check_device=True)
or is_torch_mps_available()
):
logger.warning(
"Hardware accelerator e.g. GPU is available in the environment, but no `device` argument"
" is passed to the `Pipeline` object. Model will be on CPU."
)
device = 0

if is_torch_available() and self.framework == "pt":
if device == -1 and self.model.device is not None:
Expand Down Expand Up @@ -920,10 +909,12 @@ def __init__(
elif is_torch_mps_available():
self.device = torch.device(f"mps:{device}")
else:
raise ValueError(f"{device} unrecognized or not available.")
self.device = torch.device("cpu")
else:
self.device = device if device is not None else -1

logger.warning(f"Device set to use {self.device}")

self.binary_output = binary_output
# We shouldn't call `model.to()` for models loaded with accelerate as well as the case that model is already on device
if (
Expand Down
Loading