Pipelines APIs
openmind.pipeline Method
Function
Encapsulates the preprocessing, inference, and postprocessing steps of a model so that users can directly call this method to implement fast inference with AI models across multiple domains.
Prototype
python
openmind.pipeline(
task: Optional[str] = None,
model=None,
config=None,
tokenizer=None,
feature_extractor=None,
image_processor=None,
framework: Optional[str] = None,
backend: Optional[str] = None,
model_kwargs: Optional[Dict[str, Any]] = None,
**kwargs,
)
Parameters
- task (
str, optional): Inference task name. For details, see Pipeline Supported Inference Tasks and Default Models. - model (
str,PreTrainedModel,BaseModel,Model, orTuple[str, str], optional): Model used for inference in a pipeline, which can be a model ID from the hub, local model path, or model instance, and the model instance supports PreTrainedModel (PyTorch), Model, and BaseModel (MindSpore). - config (
strorPretrainedConfig, optional): Configuration option used for model initialization in a pipeline, which can be a model ID from the hub, local model path, or model instance, and the model instance supports PretrainedConfig. - tokenizer (
str,PreTrainedTokenizer,PreTrainedTokenizerFast, orBaseTokenizer, optional): Used for model data encoding in a pipeline, which can be a model ID from the hub, local model path, or tokenizer instance. If this parameter is not provided, the default tokenizer instance of the corresponding framework is automatically loaded. - feature_extractor (
strorPreTrainedFeatureExtractor, optional): Feature extractor used for non-NLP models (such as speech, vision, and multimodal models) in a pipeline, which can be a model ID from the hub, local model path, or an actual instantiated object PreTrainedFeatureExtractor. - image_processor (
BaseImageProcessor, optional): processor used for encoding image data in the pipeline. The instantiated object supports the inherited class of BaseImageProcessor. - framework (
ptorms, optional): Name of the connected backend framework. The value can be pt (PyTorch) or ms (MindSpore). - backend (
transformers,diffusers,mindformers,mindone, ormindnlp, optional): Backend interconnection suite name. When the framework ispt, set the backend totransformersanddiffusers. When the framework isms, set the backend tomindformers,mindone, ormindnlp. - kwargs (optional): Customization parameters used to build pipeline objects, The following is an example:
- revision: Specific model version to be used. It can be a branch name, tag name, or commit ID.
- use_fast: Whether to use a fast tokenizer.
- token: user access token required for accessing non-public data in the Hub. (Either
use_auth_tokenortokenmust be configured for accessing non-public data. Configuringtokenis recommended.) - device: Only PyTorch is supported. Device on which a specific pipeline object runs, which can be NPU or CPU.
- device_map: Only PyTorch is supported. Defines how to assign different parts of a model among multiple devices. It is a parallelism policy.
- torch_dtype: Only PyTorch is supported. Data type of the torch.Tensor object.
- trust_remote_code: Whether custom models can be defined in model files on the Hub. This option should only be set to
Trueif you trust the model repository and have read the code in it, as it will execute the Hub-hosted code on your local machine. - model_kwargs: Model-related keyword argument dictionary.
- pipeline_class: pipeline type.
- use_auth_token: Only PyTorch is supported. User access token required for accessing non-public data in Hub (to be deprecated).
- audio_processor (
BaseAudioProcessor, optional): Only MindSpore is supported. Processor used by the pipeline to encode audio data. The instantiated object supports the BaseAudioProcessor class. - ge_config_path: Only MindSporeLite is supported. Configuration file path.
- device_id: Only Mindformers is supported. ID of the device on which the pipeline object runs.
- device_target: Only Mindformers is supported. Device on which a specific pipeline object runs.