-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Avoid importing all models when instantiating a pipeline #24960
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ | |
|
||
if is_torch_available(): | ||
from ..models.auto.modeling_auto import ( | ||
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING, | ||
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING, | ||
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING, | ||
MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING, | ||
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, | ||
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES, | ||
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES, | ||
MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES, | ||
) | ||
|
||
|
||
|
@@ -71,14 +71,11 @@ def __init__(self, *args, **kwargs): | |
raise ValueError(f"The {self.__class__} is only available in PyTorch.") | ||
|
||
requires_backends(self, "vision") | ||
self.check_model_type( | ||
dict( | ||
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING.items() | ||
+ MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING.items() | ||
+ MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING.items() | ||
+ MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING.items() | ||
) | ||
) | ||
mapping = MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sum is not working anymore on the ordered dicts, so had to write it this way. |
||
mapping.update(MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES) | ||
mapping.update(MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES) | ||
mapping.update(MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES) | ||
self.check_model_type(mapping) | ||
|
||
def _sanitize_parameters(self, **kwargs): | ||
preprocess_kwargs = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
if is_torch_available(): | ||
import torch | ||
|
||
from ..models.auto.modeling_auto import MODEL_FOR_OBJECT_DETECTION_MAPPING, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING | ||
from ..models.auto.modeling_auto import ( | ||
MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES, | ||
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES, | ||
) | ||
|
||
logger = logging.get_logger(__name__) | ||
|
||
|
@@ -53,9 +56,9 @@ def __init__(self, *args, **kwargs): | |
raise ValueError(f"The {self.__class__} is only available in PyTorch.") | ||
|
||
requires_backends(self, "vision") | ||
self.check_model_type( | ||
dict(MODEL_FOR_OBJECT_DETECTION_MAPPING.items() + MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING.items()) | ||
) | ||
mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES.copy() | ||
mapping.update(MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change the type but token classification here seems like a mistake? |
||
self.check_model_type(mapping) | ||
|
||
def _sanitize_parameters(self, **kwargs): | ||
postprocess_kwargs = {} | ||
|
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.
@sgugger @ArthurZucker Am I correct that this breaks if an user has registered a model with
AutoModelForSpeechSeq2Seq.register(AutoConfig, MyCustomModel)
and want to use it with the pipeline? Given that theMODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
seem to be static and not influenced byregister
.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.
From the description of the PR I would think that no (
_extra_content
is what should have been kept).The
self._model_mapping._model_mapping = self
adds a field toMODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
but it's not taken into account when computing thevalues()
if I am not mistakenThere 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.
No new key is added
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
, but you can check for its_model_mapping
if it exists, as is done in the diff below inpipelines/base.py
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 see thank you!