





'''simple docstring'''






import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs







class 		UpperCAmelCase (					lowercase_):


  """simple docstring"""







  def __init__(					self     :       List[Any]				,						UpperCamelCase__     :       Optional[int]				,						UpperCamelCase__     :       Tuple=None				,						UpperCamelCase__     :       Any=True				,						UpperCamelCase__     :       Union[str, Any]=None				,						**UpperCamelCase__     :       Union[str, Any]	)  ->    int:
    _UpperCamelCase							      =parent
    _UpperCamelCase							      =config_class
    _UpperCamelCase							      =has_text_modality
    _UpperCamelCase							      =kwargs
    _UpperCamelCase							      =common_properties


  def 	UpperCamelCase__   (					self     :       Dict	)  ->    List[str]:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict	)
    _UpperCamelCase							      =(
        ['''hidden_size''', '''num_attention_heads''', '''num_hidden_layers''']
        if self.common_properties is None
        else self.common_properties
    )

    # Add common fields for text models
    if self.has_text_modality:
      common_properties.extend(['''vocab_size''']	)

    # Test that config has the common properties as getters
    for prop in common_properties:
      self.parent.assertTrue(hasattr(UpperCamelCase__				,						UpperCamelCase__	)				,						msg=F'''`{prop}` does not exist'''	)

    # Test that config has the common properties as setter
    for idx, name in enumerate(UpperCamelCase__	):
      try:
        setattr(UpperCamelCase__				,						UpperCamelCase__				,						UpperCamelCase__	)
        self.parent.assertEqual(
            getattr(UpperCamelCase__				,						UpperCamelCase__	)				,						UpperCamelCase__				,						msg=F'''`{name} value {idx} expected, but was {getattr(UpperCamelCase__				,						UpperCamelCase__	)}'''	)
      except NotImplementedError:
        # Some models might not be able to implement setters for common_properties
        # In that case, a NotImplementedError is raised
        pass

        # Test if config class can be called with Config(prop_name=..)
    for idx, name in enumerate(UpperCamelCase__	):
      try:
        _UpperCamelCase							      =self.config_class(**{name: idx}	)
        self.parent.assertEqual(
            getattr(UpperCamelCase__				,						UpperCamelCase__	)				,						UpperCamelCase__				,						msg=F'''`{name} value {idx} expected, but was {getattr(UpperCamelCase__				,						UpperCamelCase__	)}'''	)
      except NotImplementedError:
        # Some models might not be able to implement setters for common_properties
        # In that case, a NotImplementedError is raised
        pass


  def 	UpperCamelCase__   (					self     :       str	)  ->    List[str]:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict	)
    _UpperCamelCase							      =json.loads(config.to_json_string()	)
    for key, value in self.inputs_dict.items():
      self.parent.assertEqual(obj[key]				,						UpperCamelCase__	)


  def 	UpperCamelCase__   (					self     :       Optional[Any]	)  ->    str:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict	)

    with tempfile.TemporaryDirectory() as tmpdirname:
      _UpperCamelCase							      =os.path.join(UpperCamelCase__				,						'''config.json'''	)
      config_first.to_json_file(UpperCamelCase__	)
      _UpperCamelCase							      =self.config_class.from_json_file(UpperCamelCase__	)

    self.parent.assertEqual(config_second.to_dict()				,						config_first.to_dict()	)


  def 	UpperCamelCase__   (					self     :       Tuple	)  ->    List[Any]:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict	)

    with tempfile.TemporaryDirectory() as tmpdirname:
      config_first.save_pretrained(UpperCamelCase__	)
      _UpperCamelCase							      =self.config_class.from_pretrained(UpperCamelCase__	)

    self.parent.assertEqual(config_second.to_dict()				,						config_first.to_dict()	)


  def 	UpperCamelCase__   (					self     :       Any	)  ->    Optional[Any]:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict	)

    _UpperCamelCase							      ='''test'''
    with tempfile.TemporaryDirectory() as tmpdirname:
      _UpperCamelCase							      =os.path.join(UpperCamelCase__				,						UpperCamelCase__	)
      config_first.save_pretrained(UpperCamelCase__	)
      _UpperCamelCase							      =self.config_class.from_pretrained(UpperCamelCase__				,						subfolder=UpperCamelCase__	)

    self.parent.assertEqual(config_second.to_dict()				,						config_first.to_dict()	)


  def 	UpperCamelCase__   (					self     :       List[Any]	)  ->    Union[str, Any]:
    _UpperCamelCase							      =self.config_class(**self.inputs_dict				,						num_labels=5	)
    self.parent.assertEqual(len(config.idalabel	)				,						5	)
    self.parent.assertEqual(len(config.labelaid	)				,						5	)

    _UpperCamelCase							      =3
    self.parent.assertEqual(len(config.idalabel	)				,						3	)
    self.parent.assertEqual(len(config.labelaid	)				,						3	)


  def 	UpperCamelCase__   (					self     :       Optional[int]	)  ->    Any:






    if self.config_class.is_composition:
      return
    _UpperCamelCase							      =self.config_class()
    self.parent.assertIsNotNone(UpperCamelCase__	)


  def 	UpperCamelCase__   (					self     :       Optional[Any]	)  ->    List[Any]:
    _UpperCamelCase							      =copy.deepcopy(UpperCamelCase__	)
    _UpperCamelCase							      =self.config_class(**UpperCamelCase__	)
    _UpperCamelCase							      =[]
    for key, value in config_common_kwargs.items():
      if key == "torch_dtype":
        if not is_torch_available():
          continue
        else:
          import torch

          if config.torch_dtype != torch.floataa:
            wrong_values.append(('''torch_dtype''', config.torch_dtype, torch.floataa)	)
      elif getattr(UpperCamelCase__				,						UpperCamelCase__	) != value:
        wrong_values.append((key, getattr(UpperCamelCase__				,						UpperCamelCase__	), value)	)

    if len(UpperCamelCase__	) > 0:
      _UpperCamelCase							      ='''\n'''.join([F'''- {v[0]}: got {v[1]} instead of {v[2]}''' for v in wrong_values]	)
      raise ValueError(F'''The following keys were not properly set in the config:\n{errors}'''	)




  def 	UpperCamelCase__   (					self     :       Union[str, Any]	)  ->    int:
    self.create_and_test_config_common_properties()
    self.create_and_test_config_to_json_string()
    self.create_and_test_config_to_json_file()
    self.create_and_test_config_from_and_save_pretrained()
    self.create_and_test_config_from_and_save_pretrained_subfolder()
    self.create_and_test_config_with_num_labels()
    self.check_config_can_be_init_without_params()
    self.check_config_arguments_init()









from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_   							=  logging.get_logger(__name__)

lowercase_   							=  {
    'facebook/timesformer': 'https://huggingface.co/facebook/timesformer/resolve/main/config.json',
}





class 					__lowerCAmelCase	(   SCREAMING_SNAKE_CASE				):
  _a		     =    """timesformer"""




  def __init__(							self				,  lowerCAmelCase=224				,  lowerCAmelCase=16				,  lowerCAmelCase=3				,  lowerCAmelCase=8				,  lowerCAmelCase=768				,  lowerCAmelCase=12				,  lowerCAmelCase=12				,  lowerCAmelCase=3_072				,  lowerCAmelCase="gelu"				,  lowerCAmelCase=0.0				,  lowerCAmelCase=0.0				,  lowerCAmelCase=0.02				,  lowerCAmelCase=1e-6				,  lowerCAmelCase=True				,  lowerCAmelCase="divided_space_time"				,  lowerCAmelCase=0				,  **lowerCAmelCase				,  )    ->					Any:
        '''simple docstring'''






        super().__init__(**lowerCAmelCase   )

        _lowercase      			=image_size
        _lowercase      			=patch_size
        _lowercase      			=num_channels
        _lowercase      			=num_frames

        _lowercase      			=hidden_size
        _lowercase      			=num_hidden_layers
        _lowercase      			=num_attention_heads
        _lowercase      			=intermediate_size
        _lowercase      			=hidden_act
        _lowercase      			=hidden_dropout_prob
        _lowercase      			=attention_probs_dropout_prob
        _lowercase      			=initializer_range
        _lowercase      			=layer_norm_eps
        _lowercase      			=qkv_bias

        _lowercase      			=attention_type
        _lowercase      			=drop_path_rate


