graph LR
Pipeline["Pipeline"]
PreTrainedModel_TFPreTrainedModel["PreTrainedModel / TFPreTrainedModel"]
PreTrainedTokenizer["PreTrainedTokenizer"]
PreTrainedFeatureExtractor_BaseImageProcessor["PreTrainedFeatureExtractor / BaseImageProcessor"]
ProcessorMixin["ProcessorMixin"]
ModelOutput["ModelOutput"]
GenerationConfig["GenerationConfig"]
Pipeline -- "uses" --> PreTrainedModel_TFPreTrainedModel
Pipeline -- "delegates preprocessing to" --> PreTrainedTokenizer
Pipeline -- "delegates preprocessing to" --> PreTrainedFeatureExtractor_BaseImageProcessor
Pipeline -- "consumes" --> ModelOutput
Pipeline -- "uses" --> GenerationConfig
PreTrainedModel_TFPreTrainedModel -- "produces" --> ModelOutput
PreTrainedTokenizer -- "uses" --> ProcessorMixin
PreTrainedFeatureExtractor_BaseImageProcessor -- "uses" --> ProcessorMixin
The transformers library's inference subsystem is orchestrated by the Pipeline component, which provides a high-level API for various machine learning tasks. The Pipeline delegates input preprocessing to specialized components: PreTrainedTokenizer for text-based inputs and PreTrainedFeatureExtractor / BaseImageProcessor for non-textual data. Both preprocessing components leverage the ProcessorMixin for common functionalities. After preprocessing, the Pipeline utilizes PreTrainedModel / TFPreTrainedModel to perform the actual inference, which in turn produces ModelOutput objects containing the raw results. For generative tasks, the Pipeline configures the model's behavior using GenerationConfig. This modular design ensures clear separation of concerns, enabling flexible and efficient execution of diverse ML inference workflows.
The central orchestrator of the inference workflow. It provides a unified, high-level API for various ML tasks, managing the sequence of operations from raw input to final output.
Related Classes/Methods:
Represents the core deep learning model responsible for performing the actual inference. These classes encapsulate the model architecture and loaded weights, providing the forward pass functionality.
Related Classes/Methods:
transformers.modeling_utils.PreTrainedModel:2034-6016transformers.modeling_tf_utils.TFPreTrainedModel:1109-3244
Handles the preprocessing of text inputs. It converts raw text into numerical representations (e.g., token IDs, attention masks) suitable for text-based models.
Related Classes/Methods:
Manages the preprocessing of non-textual inputs (e.g., images, audio). It transforms raw data into features or tensors compatible with vision or audio models.
Related Classes/Methods:
transformers.feature_extraction_utils.PreTrainedFeatureExtractortransformers.image_processing_utils.BaseImageProcessor:37-167
A mixin class providing common functionalities and utilities for various data processors (tokenizers, feature extractors). It promotes code reuse across different preprocessing components.
Related Classes/Methods:
A standardized data structure used to encapsulate the raw outputs generated by PreTrainedModels after inference. It provides a consistent way for the Pipeline to receive and further process model results.
Related Classes/Methods:
Defines the parameters and strategies for text generation tasks (e.g., beam search, sampling, max length). The Pipeline uses this configuration when performing generative inference with a model.
Related Classes/Methods: