Exporting a model from one framework to some format (also called backend here) involves specifying inputs and outputs information that the export function needs. The way…
The TasksManager
Exporting a model from one framework to some format (also called backend here) involves specifying inputs and outputs information that the export function needs. The way optimum.exporters is structured for each backend is as follows:
- Configuration classes containing the information for each model to perform the export.
- Exporting functions using the proper configuration for the model to export.
The role of the optimum.exporters.tasks.TasksManager is to be the main entry-point to load a model given a name and a task, and to get the proper configuration for a given (architecture, backend) couple.
That way, there is a centralized place to register the task -> model class and (architecture, backend) -> configuration mappings. This allows the export functions to use this, and to rely on the various checks it provides.
Task names
The tasks supported might depend on the backend, but here are the mappings between a task name and the auto class for PyTorch.
It is possible to know which tasks are supported for a model for a given backend, by doing:
>>> from optimum.exporters.tasks import TasksManager >>> model_type = "distilbert" >>> # For instance, for the ONNX export. >>> backend = "onnx" >>> distilbert_tasks = list(TasksManager.get_supported_tasks_for_model_type(model_type, backend).keys()) >>> print(distilbert_tasks) ['default', 'fill-mask', 'text-classification', 'multiple-choice', 'token-classification', 'question-answering']
PyTorch
Transformers
Tabla (27 filas)
| Task | Auto Class |
|---|---|
audio-classification |
AutoModelForAudioClassification |
audio-frame-classification |
AutoModelForAudioFrameClassification |
audio-xvector |
AutoModelForAudioXVector |
automatic-speech-recognition |
AutoModelForSpeechSeq2Seq, AutoModelForCTC |
depth-estimation |
AutoModelForDepthEstimation |
feature-extraction |
AutoModel |
fill-mask |
AutoModelForMaskedLM |
image-classification |
AutoModelForImageClassification |
image-to-image |
AutoModelForImageToImage |
image-to-text |
AutoModelForVision2Seq, AutoModel |
image-text-to-text |
AutoModelForImageTextToText |
mask-generation |
AutoModel |
masked-im |
AutoModelForMaskedImageModeling |
multiple-choice |
AutoModelForMultipleChoice |
object-detection |
AutoModelForObjectDetection |
question-answering |
AutoModelForQuestionAnswering |
reinforcement-learning |
AutoModel |
semantic-segmentation |
AutoModelForSemanticSegmentation |
text-to-audio |
AutoModelForTextToSpectrogram, AutoModelForTextToWaveform |
text-generation |
AutoModelForCausalLM |
text2text-generation |
AutoModelForSeq2SeqLM |
text-classification |
AutoModelForSequenceClassification |
token-classification |
AutoModelForTokenClassification |
visual-question-answering |
AutoModelForVisualQuestionAnswering |
zero-shot-image-classification |
AutoModelForZeroShotImageClassification |
zero-shot-object-detection |
AutoModelForZeroShotObjectDetection |
Diffusers
| Task | Auto Class |
|---|---|
text-to-image |
AutoPipelineForText2Image |
image-to-image |
AutoPipelineForImage2Image |
inpainting |
AutoPipelineForInpainting |
Sentence Transformers
| Task | Auto Class |
|---|---|
feature-extraction |
SentenceTransformer |
sentence-similarity |
SentenceTransformer |
Reference
[[autodoc]] exporters.tasks.TasksManager
Source and license
Source: Optimum documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.