Repository: huggingface/transformers
File: src/transformers/processing_utils.py (Python)

Code before:
            if key == "common_kwargs":
                for common_key, common_value in value.items():
                    common_kwargs[common_key] = common_value
            elif key in ["text_kwargs", "images_kwargs", "audio_kwargs", "videos_kwargs"]:
                pass
            elif (
                key not in ModelProcessorKwargs.__annotations__["text_kwargs"].__annotations__
                and key not in ModelProcessorKwargs.__annotations__["images_kwargs"].__annotations__
                and key not in ModelProcessorKwargs.__annotations__["audio_kwargs"].__annotations__
                and key not in ModelProcessorKwargs.__annotations__["videos_kwargs"].__annotations__
            ):
                common_kwargs[key] = value

        # ensure common kwargs are propagated to all relevant modalities
        for key, value in common_kwargs.items():
            for modality in output_kwargs:
                if modality != "common_kwargs":
                    output_kwargs[modality][key] = value

        # remove common kwargs from the kwargs to process the rest
        kwargs = {k: v for k, v in kwargs.items() if k not in common_kwargs}

        # update modality kwargs with passed kwargs
        for modality in output_kwargs:
            for modality_key in ModelProcessorKwargs.__annotations__[modality].__annotations__.keys():
                if modality_key in kwargs:
                    output_kwargs[modality][modality_key] = kwargs[modality_key]
                elif modality in kwargs and modality_key in kwargs[modality]:
                    output_kwargs[modality][modality_key] = kwargs[modality][modality_key]
        return output_kwargs

    @classmethod
    def from_pretrained(
        cls,
        pretrained_model_name_or_path: Union[str, os.PathLike],
        cache_dir: Optional[Union[str, os.PathLike]] = None,
        force_download: bool = False,
        local_files_only: bool = False,
        token: Optional[Union[str, bool]] = None,
        revision: str = "main",
        **kwargs,
    ):
        r"""
        Instantiate a processor associated with a pretrained model.

        <Tip>

        This class method is simply calling the feature extractor
        [`~feature_extraction_utils.FeatureExtractionMixin.from_pretrained`], image processor
        [`~image_processing_utils.ImageProcessingMixin`] and the tokenizer
        [`~tokenization_utils_base.PreTrainedTokenizer.from_pretrained`] methods. Please refer to the docstrings of the

Review comment (suggestion):
https://github.com/huggingface/transformers/blob/2c8180acd9d7fc9b91f56425e281ac7237ce3305/src/transformers/processing_utils.py#L682
As stated in here 
`high_priority_kwargs = {"crop_size" = (224, 224), "padding" = "max_length"}`
should be the first priority. However, previous treat this priority as second. So I just switched the order.

Code after:
        for modality in output_kwargs:
            for modality_key in ModelProcessorKwargs.__annotations__[modality].__annotations__.keys():
                # check if we received a structured kwarg dict or not to handle it correctly
                if modality in kwargs:
                    kwarg_value = kwargs[modality].pop(modality_key, "__empty__")
                    # check if this key was passed as a flat kwarg.
                    if kwarg_value != "__empty__" and modality_key in non_modality_kwargs:
                        raise ValueError(
                            f"Keyword argument {modality_key} was passed two times: in a dictionary for {modality} and as a **kwarg."
                        )
                elif modality_key in kwargs:
                    kwarg_value = kwargs.pop(modality_key, "__empty__")
                else:
                    kwarg_value = "__empty__"
                if kwarg_value != "__empty__":
                    output_kwargs[modality][modality_key] = kwarg_value
        # if something remains in kwargs, it belongs to common after flattening
        if set(kwargs) & set(default_kwargs):
            # here kwargs is dictionary-based since it shares keys with default set
            [output_kwargs["common_kwargs"].update(subdict) for _, subdict in kwargs.items()]
        else:
            # here it's a flat dict
            output_kwargs["common_kwargs"].update(kwargs)

        # all modality-specific kwargs are updated with common kwargs
        for modality in output_kwargs:
            output_kwargs[modality].update(output_kwargs["common_kwargs"])
        return output_kwargs

    @classmethod
    def from_pretrained(
        cls,
        pretrained_model_name_or_path: Union[str, os.PathLike],
        cache_dir: Optional[Union[str, os.PathLike]] = None,
        force_download: bool = False,
        local_files_only: bool = False,
        token: Optional[Union[str, bool]] = None,
        revision: str = "main",
        **kwargs,
    ):
        r"""
        Instantiate a processor associated with a pretrained model.

        <Tip>

        This class method is simply calling the feature extractor
        [`~feature_extraction_utils.FeatureExtractionMixin.from_pretrained`], image processor
        [`~image_processing_utils.ImageProcessingMixin`] and the tokenizer
        [`~tokenization_utils_base.PreTrainedTokenizer.from_pretrained`] methods. Please refer to the docstrings of the
        methods above for more information.