Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue where generic model types wouldn't load properly with the pipeline #18392

9 changes: 9 additions & 0 deletions src/transformers/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,15 @@ def pipeline(
# the files could be missing from the hub, instead of failing
# on such repos, we just force to not load it.
load_tokenizer = False

if not load_feature_extractor and task not in NO_FEATURE_EXTRACTOR_TASKS:
raise EnvironmentError(
f"There is a problem in `transformers`. The task {task} requires a feature extractor, however the model {type(model_config)} seems to not support feature-extractors. Please report this issue. This is likely a misconfiguration in the library, please report this issue."
Narsil marked this conversation as resolved.
Show resolved Hide resolved
)
if not load_tokenizer and task not in NO_TOKENIZER_TASKS:
raise EnvironmentError(
f"There is a problem in `transformers`. The task {task} requires a tokenizer, however the model {type(model_config)} seems to not support tokenizer. This is likely a misconfiguration in the library, please report this issue."
)
if task in NO_FEATURE_EXTRACTOR_TASKS:
load_feature_extractor = False

Expand Down
16 changes: 16 additions & 0 deletions tests/pipelines/test_pipelines_zero_shot_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ def test_small_model_tf(self):
],
)

@slow
@require_torch
def test_large_model_misconfigured(self):
# XXX this should be a fast test, but the triggering arch
# VisionTextDualEncoderModel is missing for small tests
# https://huggingface.co/hf-internal-testing
# This test will also start to fail, once this architecture
# correctly defines AutoFeatureExtractor. At this point
# we can safely remove this test as we don't really want
# to keep around an invalid model around just for this.
with self.assertRaises(EnvironmentError):
pipeline(
task="zero-shot-image-classification",
model="Bingsu/vitB32_bert_ko_small_clip",
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't include this test as it is. It's easy to build a small model in hf-internal-testing that is misconfigured and does not provide a tokenizer class while using a generic encoder/decoder arch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.


@slow
@require_torch
def test_large_model_pt(self):
Expand Down