-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Make pipeline
able to load processor
#32514
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main changes for pipeline code:
- Added loading of
processor
(previously only tokenizer, image_processor and feature_extractor) - Added Pipeline class args to control loading
The main changes
- Refactored test signatures to support
processor
pass - Changed the way how class names are obtained for processors of the testing tiny models in a pipeline. Instead of getting them from JSON file, the MAPPINGs are used.
I highlighted these changes below, please see the comments
cc @ydshieh for initial review
# Check that pipeline class required loading | ||
load_tokenizer = load_tokenizer and pipeline_class._load_tokenizer | ||
load_feature_extractor = load_feature_extractor and pipeline_class._load_feature_extractor | ||
load_image_processor = load_image_processor and pipeline_class._load_image_processor | ||
load_processor = load_processor and pipeline_class._load_processor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backward compatibility, we can control with Pipeline
class if we need to load specific processors/tokenizers. For example, for zero-shot object detection, we will need to load only the processor
, and do not need to load image_processor
and tokenizer separately. Other legacy pipelines might load only tokenizer and image_processor, even if they have processor class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Piggy-backing on the comment above, this is likely something we want to highlight very clearly in each pipeline's documentation
src/transformers/pipelines/base.py
Outdated
# Previously, pipelines support only `tokenizer`, `feature_extractor`, and `image_processor`. | ||
# As we start adding `processor`, we want to avoid loading processor for some pipelines, that don't required it, | ||
# because, for example, use `image_processor` and `tokenizer` separately. | ||
# However, we want to enable it for new pipelines. Moreover, this allow us to granularly control loading components | ||
# and avoid loading tokenizer/image_processor/feature_extractor twice: once as a separate object | ||
# and once in the processor. The following flags a set this way for backward compatibility ans might be overridden | ||
# in specific Pipeline class. | ||
_load_processor = False | ||
_load_image_processor = True | ||
_load_feature_extractor = True | ||
_load_tokenizer = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
granular control for loading, see comment in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense and I appreciate us being explicit. This repeats what is said above, but this should be extremely clear in the pipelines documentation if possible
def is_pipeline_test_to_skip( | ||
self, | ||
pipeline_test_case_name, | ||
config_class, | ||
model_architecture, | ||
tokenizer_name, | ||
image_processor_name, | ||
feature_extractor_name, | ||
processor_name, | ||
): | ||
if tokenizer_name is None: | ||
return True | ||
|
||
# `MT5EncoderOnlyModelTest` is not working well with slow tokenizers (for some models) and we don't want to touch the file | ||
# `src/transformers/data/processors/squad.py` (where this test fails for this model) | ||
if pipeline_test_case_name == "TokenClassificationPipelineTests" and not tokenizer_name.endswith("Fast"): | ||
return True | ||
|
||
return False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is skipped on the main but was not skipped on this branch, so I added a skip rule here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is skipped on the main
Could you explain a bit what this means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean, in the job run's result, it shows it is skipped (on the main branch)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this test was not running on the main branch. One of the problem of current tests: we are testing a set of cases, and if one of the cases (e.g. the first one) falls under skipTest(...) the rest test cases are not running. Probably it's better to return case status, and then aggregate statuses in the main test function running on multiple cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple example to reproduce, this test will be skipped
import unittest
class TestCases(unittest.TestCase):
def test_multiple_cases(self):
for i in range(10):
self.run_test(i)
def run_test(self, i):
if i == 0:
self.skipTest("Skip this test")
elif i == 5:
raise ValueError("This test failed")
@@ -413,6 +431,7 @@ def run_pipeline_test(self, text_generator, _): | |||
"XGLMForCausalLM", | |||
"GPTNeoXForCausalLM", | |||
"FuyuForCausalLM", | |||
"LlamaForCausalLM", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Llama no longer raises exception for long generation, so I added it to exclude list in the test. This test was skipped on main.
tests/test_pipeline_mixin.py
Outdated
# tokenizers are mapped to tuple, e.g. ("XxxTokenizer", None) | ||
tokenizer_names = TOKENIZER_MAPPING_NAMES.get(model_type, [None]) | ||
if len(tokenizer_names) > 1: | ||
tokenizer_names = [name for name in tokenizer_names if name is not None] | ||
|
||
# image processors are mapped to tuple, e.g. ("XxxImageProcessor", None) | ||
image_processor_names = IMAGE_PROCESSOR_MAPPING_NAMES.get(model_type, [None]) | ||
if len(image_processor_names) > 1: | ||
image_processor_names = [name for name in image_processor_names if name is not None] | ||
|
||
# feature extractors are mapped to instance, e.g. "XxxFeatureExtractor" | ||
feature_extractor_names = FEATURE_EXTRACTOR_MAPPING_NAMES.get(model_type, [None]) | ||
if not isinstance(feature_extractor_names, (list, tuple)): | ||
feature_extractor_names = [feature_extractor_names] | ||
|
||
# processors are mapped to instance, e.g. "XxxProcessor" | ||
processor_names = PROCESSOR_MAPPING_NAMES.get(model_type, [None]) | ||
if not isinstance(processor_names, (list, tuple)): | ||
processor_names = [processor_names] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, tokenizer, image processor and feature extractor class names were taken from JSON file of tiny models, however, there is no *Processor
class there. Now MAPPING lists are used to get class names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not in favor of using MAPPING
for anything except processor
.
The pipeline testing is highly tighten to the tiny model on the Hub, and we should use the actual classes that are used on the Hub repositories (to avoid any surprising).
For processor
, it's OK to use MAPPING
, but we can also change the json file's structure for the long term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it because in the original tiny-models JSON file we do not have separate lists for image processors and feature extractors, I found they are stored in the same list (even processors are sometimes in this list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# TODO: We should check if a model file is on the Hub repo. instead. | ||
try: | ||
model = model_architecture.from_pretrained(repo_id, revision=commit) | ||
except Exception: | ||
logger.warning( | ||
f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')}_{torch_dtype} is skipped: Could not find or load " | ||
f"the model from `{repo_id}` with `{model_architecture}`." | ||
) | ||
self.skipTest(f"Could not find or load the model from {repo_id} with {model_architecture}.") | ||
|
||
# -------------------- Load tokenizer -------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of loading is a bit changed in this test, now the model is loaded first to check if it exists, otherwise, the test is skipped.
processor
in pipelineprocessor
to the pipeline
Hi @qubvel . IIRC, that PR is more about "make pipeline able to accept loading processor", but no currently existing pipeline code is changed to use processor yet (even if we specify to load it), right? |
@ydshieh yes, you are right, the following PR will add processor to the ZeroShotObjectDetection pipeline. I decided to split it to simplify the review a bit. |
processor
to the pipelinepipeline
able to load processor
Hi @qubvel I have a general question. The process class could load also a single tokenizer, image processor or feature extractor (if not all components are on a Hub repository). For example, from transformers import AutoProcessor
AutoProcessor.from_pretrained("bert-base-uncased") will turn out to be a tokenizer instead of an instance of Therefore, in # Instantiate processor if needed
if isinstance(processor, (str, tuple)):
processor = AutoProcessor.from_pretrained(processor, _from_pipeline=task, **hub_kwargs, **model_kwargs) should have some guard to make sure we really get a WDYT? I will share my thoughts regarding the testing part this afternoon, somehow related to the same consideration. |
continuation of my previous commentOnce we start to have the code using
for testingSimilar consideration to the above. We should test 2 cases:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments :-)
def is_pipeline_test_to_skip( | ||
self, | ||
pipeline_test_case_name, | ||
config_class, | ||
model_architecture, | ||
tokenizer_name, | ||
image_processor_name, | ||
feature_extractor_name, | ||
processor_name, | ||
): | ||
if tokenizer_name is None: | ||
return True | ||
|
||
# `MT5EncoderOnlyModelTest` is not working well with slow tokenizers (for some models) and we don't want to touch the file | ||
# `src/transformers/data/processors/squad.py` (where this test fails for this model) | ||
if pipeline_test_case_name == "TokenClassificationPipelineTests" and not tokenizer_name.endswith("Fast"): | ||
return True | ||
|
||
return False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is skipped on the main
Could you explain a bit what this means?
def is_pipeline_test_to_skip( | ||
self, | ||
pipeline_test_case_name, | ||
config_class, | ||
model_architecture, | ||
tokenizer_name, | ||
image_processor_name, | ||
feature_extractor_name, | ||
processor_name, | ||
): | ||
if tokenizer_name is None: | ||
return True | ||
|
||
# `MT5EncoderOnlyModelTest` is not working well with slow tokenizers (for some models) and we don't want to touch the file | ||
# `src/transformers/data/processors/squad.py` (where this test fails for this model) | ||
if pipeline_test_case_name == "TokenClassificationPipelineTests" and not tokenizer_name.endswith("Fast"): | ||
return True | ||
|
||
return False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean, in the job run's result, it shows it is skipped (on the main branch)?
tests/test_pipeline_mixin.py
Outdated
# tokenizers are mapped to tuple, e.g. ("XxxTokenizer", None) | ||
tokenizer_names = TOKENIZER_MAPPING_NAMES.get(model_type, [None]) | ||
if len(tokenizer_names) > 1: | ||
tokenizer_names = [name for name in tokenizer_names if name is not None] | ||
|
||
# image processors are mapped to tuple, e.g. ("XxxImageProcessor", None) | ||
image_processor_names = IMAGE_PROCESSOR_MAPPING_NAMES.get(model_type, [None]) | ||
if len(image_processor_names) > 1: | ||
image_processor_names = [name for name in image_processor_names if name is not None] | ||
|
||
# feature extractors are mapped to instance, e.g. "XxxFeatureExtractor" | ||
feature_extractor_names = FEATURE_EXTRACTOR_MAPPING_NAMES.get(model_type, [None]) | ||
if not isinstance(feature_extractor_names, (list, tuple)): | ||
feature_extractor_names = [feature_extractor_names] | ||
|
||
# processors are mapped to instance, e.g. "XxxProcessor" | ||
processor_names = PROCESSOR_MAPPING_NAMES.get(model_type, [None]) | ||
if not isinstance(processor_names, (list, tuple)): | ||
processor_names = [processor_names] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not in favor of using MAPPING
for anything except processor
.
The pipeline testing is highly tighten to the tiny model on the Hub, and we should use the actual classes that are used on the Hub repositories (to avoid any surprising).
For processor
, it's OK to use MAPPING
, but we can also change the json file's structure for the long term.
tests/test_pipeline_mixin.py
Outdated
) | ||
self.skipTest(f"Could not load the processor from {repo_id} with {processor_name}.") | ||
self.skipTest(f"Could not load the tokenizer from {repo_id} with {tokenizer_name}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not skip here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 8e3eb2b
f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')}_{torch_dtype} is skipped: " | ||
f"Could not load the {key} from `{repo_id}` with `{name}`." | ||
) | ||
self.skipTest(f"Could not load the {key} from {repo_id} with {name}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not skip here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is designed the same way on the main
now, according to the comment some instances might not be loaded due to optional dependencies
transformers/tests/test_pipeline_mixin.py
Lines 256 to 267 in af638c4
processor = None | |
if processor_name is not None: | |
processor_class = getattr(transformers_module, processor_name) | |
# If the required packages (like `Pillow` or `torchaudio`) are not installed, this will fail. | |
try: | |
processor = processor_class.from_pretrained(repo_id, revision=commit) | |
except Exception: | |
logger.warning( | |
f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')}_{torch_dtype} is skipped: Could not load the " | |
f"processor from `{repo_id}` with `{processor_name}`." | |
) | |
self.skipTest(f"Could not load the processor from {repo_id} with {processor_name}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently on main
, this run_pipeline_test
only take a single tokenizer_name
and a single processor_name
, and try to load them. So if a specified processor_name
could not be loaded, we can skip it.
However, here in this PR, we try to collect the processors and put them into the dictionary processors
. So logically it's better not to skip the test during this collection.
(But in practice, this may not produce any difference)
Yes, you are correct. It is because I treated them (image processor / feature exactor) equally, and later I decided to make I see better now why you need this change. Could you, at least for now, simply use the information from the summary file |
@ydshieh Thanks for reviewing, I addressed the comments, please have a look!
This is what I tried to achieve with granular control for each pipeline class by adding |
@ydshieh could you please have a look once again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits but overall good!
Let me know if my comments are clear 🙏
f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')}_{torch_dtype} is skipped: " | ||
f"Could not load the {key} from `{repo_id}` with `{name}`." | ||
) | ||
self.skipTest(f"Could not load the {key} from {repo_id} with {name}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently on main
, this run_pipeline_test
only take a single tokenizer_name
and a single processor_name
, and try to load them. So if a specified processor_name
could not be loaded, we can skip it.
However, here in this PR, we try to collect the processors and put them into the dictionary processors
. So logically it's better not to skip the test during this collection.
(But in practice, this may not produce any difference)
# Adding `None` (if empty) so we can generate tests | ||
tokenizer_names = [None] if len(tokenizer_names) == 0 else tokenizer_names | ||
processor_names = [None] if len(processor_names) == 0 else processor_names | ||
if model_arch_name in tiny_model_summary and "sha" in tiny_model_summary[model_arch_name]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first condition is not necessary at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise we can get an error while doing tiny_model_summary[model_arch_name]
Hi @yonigozlan, just a lack of time 🙂 I will address comments this week, and hopefully it can be merged then! |
cc @Rocketknight1 as well (please always ping Matt for pipelines 🤗) |
Hey! 🤗 Thanks for your contribution to the Before merging this pull request, slow tests CI should be triggered. To enable this:
(For maintainers) The documentation for slow tests CI on PRs is here. |
9b88faa
to
e06053d
Compare
@Rocketknight1 can you please review the PR, if that aligns with plans for |
I'm sorry, I missed that ping somehow! Reviewing now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just finished the review, with a few comments.
Overall summary for core maintainers:
- This is a nice PR! It's clean, and although it seems very large, almost all of the changes are boilerplate adding kwargs and fixing spelling mistakes in a lot of files.
- The actual changes you need to look at are
__init__.py
,base.py
andtest_pipeline_mixin.py
- I made some comments, but they're nits and shouldn't affect any of the PR logic.
cc @LysandreJik for core maintainer review!
or feature_extractor is not None | ||
or isinstance(feature_extractor, str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this conditional is redundant - if feature_extractor
is a str
then it will always be not None
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in d553dab
test_cases = [ | ||
{ | ||
"tokenizer_name": tokenizer_name, | ||
"image_processor_name": image_processor_name, | ||
"feature_extractor_name": feature_extractor_name, | ||
"processor_name": processor_name, | ||
} | ||
for tokenizer_name in tokenizer_names | ||
for image_processor_name in image_processor_names | ||
for feature_extractor_name in feature_extractor_names | ||
for processor_name in processor_names | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for other reviewers: When a model doesn't support one of these preprocessor types, the list of names will be [None]
, not an empty list. When I first looked at this quadruple-loop I was worried that test_cases
would be empty if any of the four name lists was empty, but that should never occur. For safety, we might want to add a check for that, though, since it depends on behaviour in a different function that might be modified later!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, let's have this check closer to the loop to ensure we always have something to test
6ff4e68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this change, you can also remove
if not isinstance(processor_names, (list, tuple)):
processor_names = [processor_names]
(which was there for the same reason)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it there to make sure we do not have str
processor_names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I'm mostly concerned about having good and clear documentation and removing unnecessary warnings.
Pipelines are the very first transformers object many users interact with -> ensuring that they're aware of the info they need, without being hammered by warnigns should be an absolute goal of ours.
Thanks for working on this important change!
The image processor that will be used by the pipeline to preprocess images for the model. This can be a | ||
model identifier or an actual image processor inheriting from [`BaseImageProcessor`]. | ||
|
||
Image processors are used for Vision models and multi-modal models that require image inputs. Multi-modal | ||
models will also require a tokenizer to be passed. | ||
|
||
If not provided, the default image processor for the given `model` will be loaded (if it is a string). If | ||
`model` is not specified or not a string, then the default image processor for `config` is loaded (if it is | ||
a string). | ||
processor (`str` or [`ProcessorMixin`], *optional*): | ||
The processor that will be used by the pipeline to preprocess data for the model. This can be a model | ||
identifier or an actual processor inheriting from [`ProcessorMixin`]. | ||
|
||
Processors are used for multi-modal models that require multi-modal inputs, for example, a model that | ||
requires both text and image inputs. | ||
|
||
If not provided, the default processor for the given `model` will be loaded (if it is a string). If `model` | ||
is not specified or not a string, then the default processor for `config` is loaded (if it is a string). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now a few overlapping inputs:
- tokenizer
- feature extractor
- image processor
- processor
I believe it would be nice to highlight somewhere visible (like in the documentation above) what attribute is necessary for what: at no point should a user specify all four of them, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a separate Note
section to highlight that we should not provide all types of processors
at once
e712717 and refer to a specific pipeline in case one would like to provide them explicitly.
For each specific pipeline we have only required processors args in docs section configured with docs decorator. e.g. here
build_pipeline_init_args(has_image_processor=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, updated pipeline doc to more relevant one in 6996695
# Check that pipeline class required loading | ||
load_tokenizer = load_tokenizer and pipeline_class._load_tokenizer | ||
load_feature_extractor = load_feature_extractor and pipeline_class._load_feature_extractor | ||
load_image_processor = load_image_processor and pipeline_class._load_image_processor | ||
load_processor = load_processor and pipeline_class._load_processor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Piggy-backing on the comment above, this is likely something we want to highlight very clearly in each pipeline's documentation
warnings.warn( | ||
f"Processor will be not loaded, because {processor} is not an instance of `ProcessorMixin`. " | ||
f"Got type `{type(processor)}` instead.", | ||
UserWarning, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With transformers already having too many warnings, I'd be cautious about the ones we add.
What purpose does this warning serve? Is it sufficiently actionable? Does it concern users (the ones that will see it), or repo owners/creators that have not configured their processors/feature extractors correctly (that will likely not see this warning)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the questions!
There was a discussion here. The main idea is that AutoProcessor
can load not only processors but also basic processing classes, like tokenizer
.
Indeed, a misconfiguration in the model-pipeline-processor setup could trigger this and raising a warning + dropping the processor
might be sufficient only when the processor
isn't needed in the pipeline
at all.
However, with granular control, such a case shouldn't occur. Therefore, it seems more appropriate to replace the warning with an error to clearly indicate a misconfiguration. Otherwise, the error will happen later with a less clear message because the processor
is None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to error raise here bcce4dc
src/transformers/pipelines/base.py
Outdated
@@ -805,6 +816,18 @@ class Pipeline(_ScikitCompat, PushToHubMixin): | |||
constructor argument. If set to `True`, the output will be stored in the pickle format. | |||
""" | |||
|
|||
# Previously, pipelines support only `tokenizer`, `feature_extractor`, and `image_processor`. | |||
# As we start adding `processor`, we want to avoid loading processor for some pipelines, that don't required it, | |||
# because, for example, use `image_processor` and `tokenizer` separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get this comment 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to make it clearer in 9793e01
src/transformers/pipelines/base.py
Outdated
# Previously, pipelines support only `tokenizer`, `feature_extractor`, and `image_processor`. | ||
# As we start adding `processor`, we want to avoid loading processor for some pipelines, that don't required it, | ||
# because, for example, use `image_processor` and `tokenizer` separately. | ||
# However, we want to enable it for new pipelines. Moreover, this allow us to granularly control loading components | ||
# and avoid loading tokenizer/image_processor/feature_extractor twice: once as a separate object | ||
# and once in the processor. The following flags a set this way for backward compatibility ans might be overridden | ||
# in specific Pipeline class. | ||
_load_processor = False | ||
_load_image_processor = True | ||
_load_feature_extractor = True | ||
_load_tokenizer = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense and I appreciate us being explicit. This repeats what is said above, but this should be extremely clear in the pipelines documentation if possible
Co-authored-by: Lysandre Debut <[email protected]>
Co-authored-by: Lysandre Debut <[email protected]>
@LysandreJik thanks for reviewing, I addressed the comment: made clearer docs and removed the warning. Please have a look whenever you have bandwidth. P.S. The test failure looks unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok great, thanks for the changes @qubvel!
* 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 <[email protected]> * Update src/transformers/pipelines/base.py Co-authored-by: Lysandre Debut <[email protected]> * Rework comment * Better docs, add note about pipeline components * Change warning to error raise * Fixup * Refine pipeline docs --------- Co-authored-by: Lysandre Debut <[email protected]>
What does this PR do?
Add
processor
to thepipeline
and refactor tests a bit to support it. Related toFixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.