Skip to content

Commit

Permalink
Limit which tasks transformers has support for (#591)
Browse files Browse the repository at this point in the history
Until now, the Hub assumes `transformers` has support for all tasks for
which there's API, such as `audio-to-audio` (and there's no
`AudioToAudioPipeline` in `transformers`). This list is derived from
https://github.com/huggingface/api-inference/blob/main/shard/app/validation/__init__.py#L24

This will hide widgets/snippets for tasks not supported here
  • Loading branch information
osanseviero authored Mar 29, 2024
1 parent 1398ffb commit 32e3e48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/tasks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { LIBRARY_TASK_MAPPING_EXCLUDING_TRANSFORMERS } from "./library-to-tasks";
export { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
export { MAPPING_DEFAULT_WIDGET } from "./default-widget-inputs";
export type { TaskData, TaskDemo, TaskDemoEntry, ExampleRepo } from "./tasks";
export * from "./tasks";
Expand Down
28 changes: 23 additions & 5 deletions packages/tasks/src/library-to-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { ModelLibraryKey } from "./model-libraries";
import type { PipelineType } from "./pipelines";

/**
* Mapping from library name (excluding Transformers) to its supported tasks.
* Mapping from library name to its supported tasks.
* Inference API (serverless) should be disabled for all other (library, task) pairs beyond this mapping.
* As an exception, we assume Transformers supports all inference tasks.
* This mapping is generated automatically by "python-api-export-tasks" action in huggingface/api-inference-community repo upon merge.
* Ref: https://github.com/huggingface/api-inference-community/pull/158
* This mapping is partially generated automatically by "python-api-export-tasks" action in
* huggingface/api-inference-community repo upon merge. For transformers, the mapping is manually
* based on api-inference.
*/
export const LIBRARY_TASK_MAPPING_EXCLUDING_TRANSFORMERS: Partial<Record<ModelLibraryKey, PipelineType[]>> = {
export const LIBRARY_TASK_MAPPING: Partial<Record<ModelLibraryKey, PipelineType[]>> = {
"adapter-transformers": ["question-answering", "text-classification", "token-classification"],
allennlp: ["question-answering"],
asteroid: [
Expand Down Expand Up @@ -44,5 +44,23 @@ export const LIBRARY_TASK_MAPPING_EXCLUDING_TRANSFORMERS: Partial<Record<ModelLi
],
stanza: ["token-classification"],
timm: ["image-classification"],
transformers: [
"audio-classification",
"automatic-speech-recognition",
"depth-estimation",
"document-question-answering",
"fill-mask",
"image-classification",
"image-segmentation",
"image-to-text",
"image-to-image",
"object-detection",
"question-answering",
"text-generation",
"text2text-generation",
"visual-question-answering",
"zero-shot-classification",
"zero-shot-image-classification",
],
mindspore: ["image-classification"],
};

0 comments on commit 32e3e48

Please sign in to comment.