Pipeline
Pipeline is the official high-level inference API: you pass a task name and a model ID; it wires Preprocessor + model + post-processing. Use it to explore Hub checkpoints. Drop down when you need generate() knobs or a training loop.
Common tasks
See the full list in the Pipeline docs. In production, always set model=—do not rely on the implicit default.
Text: classification
A list is batched. Each item has label and score.
Text: generation
max_new_tokens caps new tokens so you neither stop too early nor ramble. Greedy vs sampling is in Text Generation.
For Chinese instructions use Qwen/Qwen2.5-0.5B-Instruct with device_map="auto" and dtype="auto". DeepSeek Instruct models on the Hub are similarly CN-friendly—confirm they are ungated before downloading.
Vision: image classification
An ImageProcessor (a Preprocessor) normalizes pixels into model tensors.
Audio: Whisper-tiny
whisper-tiny is small and ungated—good enough to prove a WAV / mic path. For long or multilingual audio, step up to whisper-small+ and watch VRAM.
What Pipeline does
That is the same as hand-wiring AutoTokenizer + AutoModel*. Pipeline saves boilerplate; custom padding, beam search, or multi-turn chat templates are cleaner with AutoClasses.
When to switch tools
- Local chat only: Ollama is simpler.
- Paper metrics, new heads, your own DataLoader: stay on Transformers.
- Tensor shapes and
.to(device): PyTorch tutorial.