Feature request
Feature Description
Currently, if a user misspells or passes an invalid device argument when initializing transformers.pipeline() (e.g., passing device="mpx" instead of "mps" or "cuda"), the function proceeds to download and load the full model weights into RAM before validating the device.
Validating the device parameter early at the pipeline() entry point would save bandwidth, RAM/disk overhead, and developer time.
Current Internal Execution Flow & Behavior
When executing:
from transformers import pipeline
# Downloads gigabytes of model weights first... and then crashes at tensor placement
classifier = pipeline("text-classification", model="bert-base-uncased", device="mpx")
Proposed Solution
Add lightweight early validation at the very top of transformers.pipeline() before from_pretrained() or model initialization is triggered.
If device is a string, validate it against canonical device prefixes (cpu, cuda, mps, npu, xpu, hpu), integers, or torch.device instances. If invalid, fail immediately:
ValueError: Invalid device 'mpx'. Expected a valid device string (e.g., 'cpu', 'cuda', 'mps', 'npu', 'xpu'), an integer device ordinal (e.g., 0), or a torch.device instance.
Motivation
It is most likely that any user would be annoyed to see an entire model download and fail at tensor placement.
Your contribution
I am happy to open PR adding this early check and unit tests if the maintainers agree with this enhancement.
will open PR for this
Feature request
Feature Description
Currently, if a user misspells or passes an invalid
deviceargument when initializingtransformers.pipeline()(e.g., passingdevice="mpx"instead of"mps"or"cuda"), the function proceeds to download and load the full model weights into RAM before validating the device.Validating the
deviceparameter early at thepipeline()entry point would save bandwidth, RAM/disk overhead, and developer time.Current Internal Execution Flow & Behavior
When executing:
Proposed Solution
Add lightweight early validation at the very top of transformers.pipeline() before from_pretrained() or model initialization is triggered.
If device is a string, validate it against canonical device prefixes (cpu, cuda, mps, npu, xpu, hpu), integers, or torch.device instances. If invalid, fail immediately:
ValueError: Invalid device 'mpx'. Expected a valid device string (e.g., 'cpu', 'cuda', 'mps', 'npu', 'xpu'), an integer device ordinal (e.g., 0), or a
torch.deviceinstance.Motivation
It is most likely that any user would be annoyed to see an entire model download and fail at tensor placement.
Your contribution
I am happy to open PR adding this early check and unit tests if the maintainers agree with this enhancement.
will open PR for this