



'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
     from transformers import (
         AutoConfig,
         BertConfig,
         GPTaConfig,
         TaConfig,
         TFAutoModel,
         TFAutoModelForCausalLM,
         TFAutoModelForMaskedLM,
         TFAutoModelForPreTraining,
         TFAutoModelForQuestionAnswering,
         TFAutoModelForSeqaSeqLM,
         TFAutoModelForSequenceClassification,
         TFAutoModelWithLMHead,
         TFBertForMaskedLM,
         TFBertForPreTraining,
         TFBertForQuestionAnswering,
         TFBertForSequenceClassification,
         TFBertModel,
         TFGPTaLMHeadModel,
         TFRobertaForMaskedLM,
         TFTaForConditionalGeneration,
     )
     from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
     from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
     from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
     from transformers import (
         AutoModel,
         AutoModelForCausalLM,
         AutoModelForMaskedLM,
         AutoModelForPreTraining,
         AutoModelForQuestionAnswering,
         AutoModelForSeqaSeqLM,
         AutoModelForSequenceClassification,
         AutoModelWithLMHead,
         BertForMaskedLM,
         BertForPreTraining,
         BertForQuestionAnswering,
         BertForSequenceClassification,
         BertModel,
         GPTaLMHeadModel,
         RobertaForMaskedLM,
         TaForConditionalGeneration,
     )

@is_pt_tf_cross_test
class 							a__( unittest.TestCase     ):







    @slow
    def       lowercase_	(				self			:  Dict     ):
      # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      for model_name in ["bert-base-uncased"]:
        a						: Optional[Any]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: str					       =					TFAutoModel.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: str					       =					AutoModel.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  Dict     ):
      # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      for model_name in ["bert-base-uncased"]:
        a						: str					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Dict					       =					TFAutoModelForPreTraining.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Union[str, Any]					       =					AutoModelForPreTraining.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  int     ):
      for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						: Optional[int]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: int					       =					TFAutoModelForCausalLM.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        a       ,     a						: List[Any]					       =					TFAutoModelForCausalLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Any					       =					AutoModelForCausalLM.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        a       ,     a						: List[Any]					       =					AutoModelForCausalLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  List[Any]     ):
      for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						: Optional[Any]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Union[str, Any]					       =					TFAutoModelWithLMHead.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: str					       =					AutoModelWithLMHead.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  List[Any]     ):
      for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						: Union[str, Any]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: List[str]					       =					TFAutoModelForMaskedLM.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        a       ,     a						: List[Any]					       =					TFAutoModelForMaskedLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Optional[int]					       =					AutoModelForMaskedLM.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        a       ,     a						: List[Any]					       =					AutoModelForMaskedLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  int     ):
      for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						: Optional[int]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: str					       =					TFAutoModelForSeqaSeqLM.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        a       ,     a						: Optional[int]					       =					TFAutoModelForSeqaSeqLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: List[str]					       =					AutoModelForSeqaSeqLM.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        a       ,     a						: Any					       =					AutoModelForSeqaSeqLM.from_pretrained(
            __lowercase						,      output_loading_info=__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  int     ):
      # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      for model_name in ["bert-base-uncased"]:
        a						: Union[str, Any]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: List[Any]					       =					TFAutoModelForSequenceClassification.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Dict					       =					AutoModelForSequenceClassification.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    @slow
    def       lowercase_	(				self			:  List[Any]     ):
      # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      for model_name in ["bert-base-uncased"]:
        a						: Optional[Any]					       =					AutoConfig.from_pretrained(__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: List[Any]					       =					TFAutoModelForQuestionAnswering.from_pretrained(__lowercase						,      from_pt=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )

        a						: Union[str, Any]					       =					AutoModelForQuestionAnswering.from_pretrained(__lowercase						,      from_tf=__lowercase     )
        self.assertIsNotNone(__lowercase     )
        self.assertIsInstance(__lowercase						,      __lowercase     )







    def       lowercase_	(				self			:  List[str]     ):
      a						: Tuple					       =					TFAutoModelWithLMHead.from_pretrained(__lowercase						,      from_pt=__lowercase     )
      self.assertIsInstance(__lowercase						,      __lowercase     )
      self.assertEqual(model.num_parameters()						,      1_44_10     )
      self.assertEqual(model.num_parameters(only_trainable=__lowercase     )						,      1_44_10     )

      a						: Any					       =					AutoModelWithLMHead.from_pretrained(__lowercase						,      from_tf=__lowercase     )
      self.assertIsInstance(__lowercase						,      __lowercase     )
      self.assertEqual(model.num_parameters()						,      1_44_10     )
      self.assertEqual(model.num_parameters(only_trainable=__lowercase     )						,      1_44_10     )







    def       lowercase_	(				self			:  Union[str, Any]     ):
      a						: Tuple					       =					TFAutoModelWithLMHead.from_pretrained(__lowercase						,      from_pt=__lowercase     )
      self.assertIsInstance(__lowercase						,      __lowercase     )
      self.assertEqual(model.num_parameters()						,      1_44_10     )
      self.assertEqual(model.num_parameters(only_trainable=__lowercase     )						,      1_44_10     )

      a						: Optional[int]					       =					AutoModelWithLMHead.from_pretrained(__lowercase						,      from_tf=__lowercase     )
      self.assertIsInstance(__lowercase						,      __lowercase     )
      self.assertEqual(model.num_parameters()						,      1_44_10     )
      self.assertEqual(model.num_parameters(only_trainable=__lowercase     )						,      1_44_10     )




'''simple docstring'''






from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowerCAmelCase: Any							=						logging.get_logger(__name__)

class 							a__( lowerCamelCase__     ):
    lowercase__			=   ["""pixel_values"""]







    def __init__(				self			:  List[str]						,      __snake_case			:  bool = True						,      __snake_case			:  int = 32						,      __snake_case			:  Union[str, Any]=PILImageResampling.BILINEAR						,      __snake_case			:  bool = True						,      **__snake_case			:  List[Any]						,      ):
      a						: Optional[Any]					       =					do_resize
      a						: Union[str, Any]					       =					do_rescale
      a						: Union[str, Any]					       =					size_divisor
      a						: List[Any]					       =					resample
      super().__init__(**__snake_case     )







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  np.ndarray						,      __snake_case			:  int						,      __snake_case			:  Tuple						,      __snake_case			:  Optional[ChannelDimension] = None						,      **__snake_case			:  Tuple     ):
      a       ,     a						: Optional[int]					       =					get_image_size(__snake_case     )
      # Rounds the height and width down to the closest multiple of size_divisor
      a						: int					       =					height // size_divisor * size_divisor
      a						: int					       =					width // size_divisor * size_divisor
      a						: Any					       =					resize(__snake_case						,      (new_h, new_w)						,      resample=__snake_case						,      data_format=__snake_case						,      **__snake_case     )
      return image







    def       lowercase_	(				self			:  Optional[int]						,      __snake_case			:  np.ndarray						,      __snake_case			:  float						,      __snake_case			:  Optional[ChannelDimension] = None						,      **__snake_case			:  Optional[Any]     ):
      return rescale(image=__snake_case						,      scale=__snake_case						,      data_format=__snake_case						,      **__snake_case     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]]						,      __snake_case			:  Optional[bool] = None						,      __snake_case			:  Optional[int] = None						,      __snake_case			:  Dict=None						,      __snake_case			:  Optional[bool] = None						,      __snake_case			:  Optional[Union[TensorType, str]] = None						,      __snake_case			:  ChannelDimension = ChannelDimension.FIRST						,      **__snake_case			:  Any						,      ):
      a						: List[str]					       =					do_resize if do_resize is not None else self.do_resize
      a						: Tuple					       =					do_rescale if do_rescale is not None else self.do_rescale
      a						: Optional[Any]					       =					size_divisor if size_divisor is not None else self.size_divisor
      a						: Union[str, Any]					       =					resample if resample is not None else self.resample

      if do_resize and size_divisor is None:
        raise ValueError('size_divisor is required for resizing'     )

      a						: Tuple					       =					make_list_of_images(__snake_case     )

      if not valid_images(__snake_case     ):
        raise ValueError('Invalid image(s)'     )

      # All transformations expect numpy arrays.
      a						: str					       =					[to_numpy_array(__snake_case     ) for img in images]

      if do_resize:
        a						: int					       =					[self.resize(__snake_case						,      size_divisor=__snake_case						,      resample=__snake_case     ) for image in images]

      if do_rescale:
        a						: List[str]					       =					[self.rescale(__snake_case						,      scale=1 / 2_55     ) for image in images]

      a						: Any					       =					[to_channel_dimension_format(__snake_case						,      __snake_case     ) for image in images]

      a						: Any					       =					{'pixel_values': images}
      return BatchFeature(data=__snake_case						,      tensor_type=__snake_case     )