Skip to main content

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")

Example image used in Pipeline docs (cat / chonk) β€” Source: Hugging Face

Source: Hugging Face documentation images (pipeline-cat-chonk.jpeg).

Useful parameters​

ParameterRole
taskSelects the task-specific pipeline class
modelCheckpoint id or local path
device / AccelerateGPU / MPS placement
torch_dtypefloat16 / bfloat16 for memory and speed
batch_sizeThroughput 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…