Pipeline
Pipeline is the simplest inference API for Hub models across many tasks.
Adapted for this playbook from the π€ Transformers documentation by Hugging Face. Official page: https://huggingface.co/docs/transformers/pipeline_tutorial. Images Β© Hugging Face (
documentation-images) unless noted. This is not a substitute for the upstream docs β verify against the current version.Covers Hugging Face pages: pipeline_tutorial, add_new_pipeline
Minimal exampleβ
from transformers import pipeline
pipe = pipeline(task="text-generation", model="openai-community/gpt2")
print(pipe("the secret to baking a really good cake is ", max_new_tokens=30))
Cross-modality examplesβ
ASR
asr = pipeline(task="automatic-speech-recognition", model="openai/whisper-large-v3")
asr("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac")
Image classification
clf = pipeline(task="image-classification", model="google/vit-base-patch16-224")
clf("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")

Source: Hugging Face documentation images (pipeline-cat-chonk.jpeg).
Useful parametersβ
| Parameter | Role |
|---|---|
task | Selects the task-specific pipeline class |
model | Checkpoint id or local path |
device / Accelerate | GPU / MPS placement |
torch_dtype | float16 / bfloat16 for memory and speed |
batch_size | Throughput for lists of inputs |
When Pipeline is not enoughβ
Move to AutoModel + generate for custom logits processors, advanced caching, or tight latency loops β see Text generation.
Discussion
Commentsβ
Share feedback or questions about this page. No account required.
Loading commentsβ¦