
'''simple docstring'''





from typing import Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
						from PIL import Image

						from ..image_utils import load_image

if is_torch_available():
						from ..models.auto.modeling_auto import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

UpperCAmelCase    					=   logging.get_logger(__name__)

@add_end_docstrings(__magic_name__    )
class 						a   (				__magic_name__    ):




				def __init__(							self	:				Optional[Any],    *SCREAMING_SNAKE_CASE_	:				Union[str, Any],    **SCREAMING_SNAKE_CASE_	:				Dict      ):
										super().__init__(*SCREAMING_SNAKE_CASE_,    **SCREAMING_SNAKE_CASE_      )
										self.check_model_type(SCREAMING_SNAKE_CASE_      )




				def 	__snake_case							(							self	:				Optional[Any],    SCREAMING_SNAKE_CASE_	:				Dict=None,    SCREAMING_SNAKE_CASE_	:				List[str]=None,    SCREAMING_SNAKE_CASE_	:				int=None,    **SCREAMING_SNAKE_CASE_	:				Union[str, Any]      ):
										snake_case,					snake_case       :     Any =    {}, {}
										if padding is not None:
																snake_case       :     str =    padding
										if truncation is not None:
																snake_case       :     int =    truncation
										if top_k is not None:
																snake_case       :     int =    top_k
										return preprocess_params, {}, postprocess_params




				def __call__(							self	:				List[Any],    SCREAMING_SNAKE_CASE_	:				Union["Image.Image", str],    SCREAMING_SNAKE_CASE_	:				str = None,    **SCREAMING_SNAKE_CASE_	:				List[str]      ):
										if isinstance(SCREAMING_SNAKE_CASE_,    (Image.Image, str)      ) and isinstance(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_      ):
																snake_case       :     Optional[Any] =    {'''image''': image, '''question''': question}
										else:
																snake_case       :     Dict =    image
										snake_case       :     Optional[int] =    super().__call__(SCREAMING_SNAKE_CASE_,    **SCREAMING_SNAKE_CASE_      )
										return results




				def 	__snake_case							(							self	:				List[Any],    SCREAMING_SNAKE_CASE_	:				List[Any],    SCREAMING_SNAKE_CASE_	:				int=False,    SCREAMING_SNAKE_CASE_	:				Optional[Any]=False      ):
										snake_case       :     Dict =    load_image(inputs['''image''']      )
										snake_case       :     Optional[int] =    self.tokenizer(
										    inputs['''question'''],    return_tensors=self.framework,    padding=SCREAMING_SNAKE_CASE_,    truncation=SCREAMING_SNAKE_CASE_      )
										snake_case       :     List[str] =    self.image_processor(images=SCREAMING_SNAKE_CASE_,    return_tensors=self.framework      )
										model_inputs.update(SCREAMING_SNAKE_CASE_      )
										return model_inputs




				def 	__snake_case							(							self	:				int,    SCREAMING_SNAKE_CASE_	:				str      ):
										snake_case       :     Optional[int] =    self.model(**SCREAMING_SNAKE_CASE_      )
										return model_outputs




				def 	__snake_case							(							self	:				str,    SCREAMING_SNAKE_CASE_	:				Optional[int],    SCREAMING_SNAKE_CASE_	:				List[Any]=5      ):
										if top_k > self.model.config.num_labels:
																snake_case       :     Dict =    self.model.config.num_labels

										if self.framework == "pt":
																snake_case       :     Optional[int] =    model_outputs.logits.sigmoid()[0]
																snake_case,					snake_case       :     str =    probs.topk(SCREAMING_SNAKE_CASE_      )
										else:
																raise ValueError(F"""Unsupported framework: {self.framework}"""      )

										snake_case       :     str =    scores.tolist()
										snake_case       :     List[str] =    ids.tolist()
										return [{"score": score, "answer": self.model.config.idalabel[_id]} for score, _id in zip(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_      )]



'''simple docstring'''





import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
UpperCAmelCase    					=   "src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
UpperCAmelCase    					=   direct_transformers_import(PATH_TO_TRANSFORMERS)

UpperCAmelCase    					=   transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
UpperCAmelCase    					=   re.compile(r"\[(.+?)\]\((https://huggingface\.co/.+?)\)")


UpperCAmelCase    					=   {
    "DecisionTransformerConfig",
    "EncoderDecoderConfig",
    "MusicgenConfig",
    "RagConfig",
    "SpeechEncoderDecoderConfig",
    "TimmBackboneConfig",
    "VisionEncoderDecoderConfig",
    "VisionTextDualEncoderConfig",
    "LlamaConfig",
}

def      A (       A_							:					Union[str, Any]       ):
						snake_case       :     Tuple =    None

						# source code of `config_class`
						snake_case       :     Union[str, Any] =    inspect.getsource(A_       )
						snake_case       :     List[Any] =    _re_checkpoint.findall(A_       )

						# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
						# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
						for ckpt_name, ckpt_link in checkpoints:
												# allow the link to end with `/`
												if ckpt_link.endswith('''/'''       ):
																		snake_case       :     Optional[int] =    ckpt_link[:-1]

												# verify the checkpoint name corresponds to the checkpoint link
												snake_case       :     Dict =    F"""https://huggingface.co/{ckpt_name}"""
												if ckpt_link == ckpt_link_from_name:
																		snake_case       :     Dict =    ckpt_name
																		break

						return checkpoint

def      A (       ):
						snake_case       :     List[str] =    []

						for config_class in list(CONFIG_MAPPING.values()       ):
												# Skip deprecated models
												if "models.deprecated" in config_class.__module__:
																		continue
												snake_case       :     Tuple =    get_checkpoint_from_config_class(A_       )

												snake_case       :     Optional[Any] =    config_class.__name__
												if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
																		configs_without_checkpoint.append(A_       )

						if len(A_       ) > 0:
												snake_case       :     Optional[int] =    '''\n'''.join(sorted(A_       )       )
												raise ValueError(F"""The following configurations don't contain any valid checkpoint:\n{message}"""       )


if __name__ == "__main__":
						check_config_docstrings_have_checkpoints()

