mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Better defaults (#34026)
* be nice to our usres * nit * fixup * default to -1 * oups * turbo nit * auto infer framework
This commit is contained in:
parent
65753d6065
commit
05863817d6
@ -1440,6 +1440,8 @@ class GenerationMixin:
|
||||
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:
|
||||
|
@ -881,18 +881,7 @@ class Pipeline(_ScikitCompat, PushToHubMixin):
|
||||
# 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:
|
||||
@ -920,10 +909,12 @@ class Pipeline(_ScikitCompat, PushToHubMixin):
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user