Pipeline orchestration

This part manages the overall pipeline setup, runs the generation process, and returns the final text results.

Columns are parts of the code, grouped by process. Read top to bottom. Solid arrow: hands work over. Dashed: the reply. Purple: crosses between processes. Hook: work inside one part. Dashed boxes repeat. Hover a column name or a step for its full text.

MAIN PROCESSBegin resolving componentsLoad model weightsTry candidate class…Load matching tokenizerConfigure padding directionSet…Acc…Process single inputDetermine return mo…Tokenize input textCon…Move tensors to dev…Run generation processPro…Decode generated toke…Cre…
Pipeline Setup
Base Pipeline
Text Gen Logic
1Resolve model and configuration — The system begins by resolving the model identifier, configuration, and task type for the pipeline. It loads the configuration from the model checkpoint, infers the task if not specified, and sets up default parameters like using fast tokenizers and automatic data types.
2Load the model weights — The system loads the model weights from the checkpoint, trying candidate model classes sequentially until one succeeds. If loading fails with the original data type, it retries with 32-bit floating point, stopping at the first successful load.
3Resolve and load tokenizer — The system resolves and loads the tokenizer required for text generation, using the same checkpoint as the model. It ensures the tokenizer matches the model's vocabulary and special tokens.
4Initialize pipeline settings — The pipeline initializes itself and configures the tokenizer to use left padding instead of right padding for text generation. It also sets up default prefix parameters for certain model types.
5Process input prompt — When you call the pipeline, it processes your input prompt and determines whether to return results immediately or lazily for datasets. It sanitizes your parameters and merges them with the pipeline's default settings.
6Tokenize the prompt — The system converts your text prompt into token IDs that the model can understand, adding any special tokens and preparing the input tensors. It reserves room for new tokens based on generation parameters and truncates if the input exceeds the model's maximum length.
7Run model forward pass — The system moves your input tensors to the model's device and runs the forward pass within an inference context. After generation completes, it moves the output tensors back to the CPU for post-processing.
8Generate new tokens — The model generates new tokens based on your prompt, producing sequences of token IDs. It groups the generated sequences by input and extracts auxiliary outputs like attention masks that match the output batch size.
9Format output records — The system converts the generated token IDs back into text by decoding only the new tokens after your input. It creates one record per generated sequence, optionally prepending your original prompt to the generated text.
10Return final results — The pipeline returns your results as a list if you provided a single input, or as an iterator for datasets and generators. It logs warnings if you call it many times on GPU without using a dataset.
STEP · hover for full text