Make pipeline able to load processor (#32514)
* Refactor get_test_pipeline * Fixup * Fixing tests * Add processor loading in tests * Restructure processors loading * Add processor to the pipeline * Move model loading on tom of the test * Update `get_test_pipeline` * Fixup * Add class-based flags for loading processors * Change `is_pipeline_test_to_skip` signature * Skip t5 failing test for slow tokenizer * Fixup * Fix copies for T5 * Fix typo * Add try/except for tokenizer loading (kosmos-2 case) * Fixup * Llama not fails for long generation * Revert processor pass in text-generation test * Fix docs * Switch back to json file for image processors and feature extractors * Add processor type check * Remove except for tokenizers * Fix docstring * Fix empty lists for tests * Fixup * Fix load check * Ensure we have non-empty test cases * Update src/transformers/pipelines/__init__.py Co-authored-by: Lysandre Debut <hi@lysand.re> * Update src/transformers/pipelines/base.py Co-authored-by: Lysandre Debut <hi@lysand.re> * Rework comment * Better docs, add note about pipeline components * Change warning to error raise * Fixup * Refine pipeline docs --------- Co-authored-by: Lysandre Debut <hi@lysand.re>
This commit is contained in:
committed by
GitHub
parent
4fb28703ad
commit
48461c0fe2
@@ -157,8 +157,16 @@ class ImageFeatureExtractionPipelineTests(unittest.TestCase):
|
||||
outputs = feature_extractor(img, return_tensors=True)
|
||||
self.assertTrue(tf.is_tensor(outputs))
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
if processor is None:
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if image_processor is None:
|
||||
self.skipTest(reason="No image processor")
|
||||
|
||||
elif type(model.config) in TOKENIZER_MAPPING:
|
||||
@@ -175,11 +183,16 @@ class ImageFeatureExtractionPipelineTests(unittest.TestCase):
|
||||
"""
|
||||
)
|
||||
|
||||
feature_extractor = ImageFeatureExtractionPipeline(
|
||||
model=model, image_processor=processor, torch_dtype=torch_dtype
|
||||
feature_extractor_pipeline = ImageFeatureExtractionPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
img = prepare_img()
|
||||
return feature_extractor, [img, img]
|
||||
return feature_extractor_pipeline, [img, img]
|
||||
|
||||
def run_pipeline_test(self, feature_extractor, examples):
|
||||
imgs = examples
|
||||
|
||||
Reference in New Issue
Block a user