Skip to content

Commit 4cc1500

Browse files
authored
Ignore unsupported pipelines for transformers (#703)
If a model has a type without a corresponding pipeline in transformers, we don't show the `pipeline` snippet but we still show the `AutoModel` one. This is useful for example for `sentence-similarity` models ![Screenshot from 2024-05-22 18-35-06](https://github.com/huggingface/huggingface.js/assets/7246357/77373f2b-477a-4dc4-84af-12b4baa31dd5) ![Screenshot from 2024-05-22 18-34-43](https://github.com/huggingface/huggingface.js/assets/7246357/64006386-6e61-49b3-8a5c-1795f23f6c4d) https://huggingface.slack.com/archives/C02EMARJ65P/p1716294199591799
1 parent 04a0eb4 commit 4cc1500

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/tasks/src/library-to-tasks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const LIBRARY_TASK_MAPPING: Partial<Record<ModelLibraryKey, PipelineType[
7070
"visual-question-answering",
7171
"zero-shot-classification",
7272
"zero-shot-image-classification",
73+
"zero-shot-object-detection",
7374
],
7475
mindspore: ["image-classification"],
7576
};

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ModelData } from "./model-data";
2+
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
23

34
const TAG_CUSTOM_CODE = "custom_code";
45

@@ -438,7 +439,7 @@ export const transformers = (model: ModelData): string[] => {
438439
].join("\n");
439440
}
440441

441-
if (model.pipeline_tag) {
442+
if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
442443
const pipelineSnippet = [
443444
"# Use a pipeline as a high-level helper",
444445
"from transformers import pipeline",

0 commit comments

Comments
 (0)