ValueError: 任务 `summarization_v2` 不被 pipeline 支持。支持的任务有:['text-classification', 'token-classification', 'question-answering', 'summarization', 'translation', 'text-generation', 'zero-shot-classification', 'fill-mask', 'ner', 'sentiment-analysis']
ValueError: The task `summarization_v2` is not supported by the pipeline. Supported tasks are: ['text-classification', 'token-classification', 'question-answering', 'summarization', 'translation', 'text-generation', 'zero-shot-classification', 'fill-mask', 'ner', 'sentiment-analysis']
ID: huggingface/pipeline-invalid-task
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| transformers>=4.25.0 | active | — | — | — |
| huggingface-hub>=0.12.0 | active | — | — | — |
根因分析
pipeline API 被调用时使用了未注册的任务标识符,通常是由于拼写错误或使用了非标准任务名称。
English
The pipeline API was called with a task identifier that does not match any registered pipeline task, often due to typos or using a non-standard task name.
官方文档
https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.pipeline.task解决方案
-
Correct the task name to a valid one: `from transformers import pipeline; pipe = pipeline('summarization', model='facebook/bart-large-cnn')` -
Use the model's default task by omitting the task argument: `pipe = pipeline(model='facebook/bart-large-cnn')` which auto-detects the task.
-
If the task is truly custom, register it with `from transformers.pipelines import SUPPORTED_TASKS; SUPPORTED_TASKS['custom_task'] = {...}`
无效尝试
常见但无效的做法:
-
Installing an older version of transformers (e.g., 4.20.0) to bypass the error
80% 失败
Older versions have even fewer supported tasks; the invalid task will still fail.
-
Creating a custom pipeline with the same name without registering it
90% 失败
The pipeline registry is static; custom tasks must be registered via `PipelineRegistry` or by using a valid alias.
-
Changing the model name in the pipeline call
95% 失败
The error is about the task argument, not the model; changing the model does not affect task validation.