





"""simple docstring"""
import copy
import tempfile
import unittest

from huggingface_hub import HfFolder, delete_repo
from parameterized import parameterized
from requests.exceptions import HTTPError

from transformers import AutoConfig, GenerationConfig
from transformers.testing_utils import TOKEN, USER, is_staging_test






class 					_SCREAMING_SNAKE_CASE(   unittest.TestCase  ):




       @parameterized.expand([(None,), ('''foo.json''',)]							)
       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Any						=  GenerationConfig(
                 do_sample=SCREAMING_SNAKE_CASE__		,temperature=0.7		,length_penalty=1.0		,bad_words_ids=[[1, 2, 3], [4, 5]]		,)
             with tempfile.TemporaryDirectory() as tmp_dir:
                   config.save_pretrained(SCREAMING_SNAKE_CASE__		,config_name=SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE   :int						=  GenerationConfig.from_pretrained(SCREAMING_SNAKE_CASE__		,config_name=SCREAMING_SNAKE_CASE__							)

             # Checks parameters that were specified
             self.assertEqual(loaded_config.do_sample		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(loaded_config.temperature		,0.7							)
             self.assertEqual(loaded_config.length_penalty		,1.0							)
             self.assertEqual(loaded_config.bad_words_ids		,[[1, 2, 3], [4, 5]]							)

             # Checks parameters that were not specified (defaults)
             self.assertEqual(loaded_config.top_k		,50							)
             self.assertEqual(loaded_config.max_length		,20							)
             self.assertEqual(loaded_config.max_time		,SCREAMING_SNAKE_CASE__							)




       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[int]						=  AutoConfig.from_pretrained('''gpt2'''							)
             __SCREAMING_SNAKE_CASE   :str						=  GenerationConfig.from_model_config(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  GenerationConfig()

             # The generation config has loaded a few non-default parameters from the model config
             self.assertNotEqual(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             # One of those parameters is eos_token_id -- check if it matches
             self.assertNotEqual(generation_config_from_model.eos_token_id		,default_generation_config.eos_token_id							)
             self.assertEqual(generation_config_from_model.eos_token_id		,model_config.eos_token_id							)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  GenerationConfig()
             __SCREAMING_SNAKE_CASE   :Dict						=  {
                 '''max_new_tokens''': 10_24,
                 '''foo''': '''bar''',
             }
             __SCREAMING_SNAKE_CASE   :Any						=  copy.deepcopy(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE   :List[str]						=  generation_config.update(**SCREAMING_SNAKE_CASE__							)

             # update_kwargs was not modified (no side effects)
             self.assertEqual(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             # update_kwargs was used to update the config on valid attributes
             self.assertEqual(generation_config.max_new_tokens		,10_24							)

             # `.update()` returns a dictionary of unused kwargs
             self.assertEqual(SCREAMING_SNAKE_CASE__		,{'''foo''': '''bar'''}							)




       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :str						=  GenerationConfig()
             __SCREAMING_SNAKE_CASE   :List[Any]						=  '''bar'''

             with tempfile.TemporaryDirectory('''test-generation-config'''							) as tmp_dir:
                   generation_config.save_pretrained(SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Dict						=  GenerationConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
             # update_kwargs was used to update the config on valid attributes
             self.assertEqual(new_config.foo		,'''bar'''							)

             __SCREAMING_SNAKE_CASE   :Dict						=  GenerationConfig.from_model_config(SCREAMING_SNAKE_CASE__							)
             assert not hasattr(SCREAMING_SNAKE_CASE__		,'''foo'''							)  # no new kwargs should be initialized if from config




       def     _UpperCamelCase     (						self							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  GenerationConfig()
             self.assertEqual(default_config.temperature		,1.0							)
             self.assertEqual(default_config.do_sample		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(default_config.num_beams		,1							)

             __SCREAMING_SNAKE_CASE   :Tuple						=  GenerationConfig(
                 do_sample=SCREAMING_SNAKE_CASE__		,temperature=0.7		,length_penalty=1.0		,bad_words_ids=[[1, 2, 3], [4, 5]]		,)
             self.assertEqual(config.temperature		,0.7							)
             self.assertEqual(config.do_sample		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(config.num_beams		,1							)

             with tempfile.TemporaryDirectory() as tmp_dir:
                   config.save_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE   :Any						=  GenerationConfig.from_pretrained(SCREAMING_SNAKE_CASE__		,temperature=1.0							)

             self.assertEqual(loaded_config.temperature		,1.0							)
             self.assertEqual(loaded_config.do_sample		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(loaded_config.num_beams		,1							)  # default value






@is_staging_test
class 					_SCREAMING_SNAKE_CASE(   unittest.TestCase  ):




       @classmethod
       def     _UpperCamelCase     (						cls							)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  TOKEN
             HfFolder.save_token(SCREAMING_SNAKE_CASE__							)




       @classmethod
       def     _UpperCamelCase     (						cls							)			->      Any:





             """simple docstring"""






             try:
                   delete_repo(token=cls._token		,repo_id='''test-generation-config'''							)
             except HTTPError:
                   pass

             try:
                   delete_repo(token=cls._token		,repo_id='''valid_org/test-generation-config-org'''							)
             except HTTPError:
                   pass




       def     _UpperCamelCase     (						self							)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  GenerationConfig(
                 do_sample=SCREAMING_SNAKE_CASE__		,temperature=0.7		,length_penalty=1.0		,)
             config.push_to_hub('''test-generation-config'''		,use_auth_token=self._token							)

             __SCREAMING_SNAKE_CASE   :List[Any]						=  GenerationConfig.from_pretrained(f'''{USER}/test-generation-config'''							)
             for k, v in config.to_dict().items():
                   if k != "transformers_version":
                         self.assertEqual(SCREAMING_SNAKE_CASE__		,getattr(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)

        # Reset repo
             delete_repo(token=self._token		,repo_id='''test-generation-config'''							)

             # Push to hub via save_pretrained
             with tempfile.TemporaryDirectory() as tmp_dir:
                   config.save_pretrained(
                       SCREAMING_SNAKE_CASE__		,repo_id='''test-generation-config'''		,push_to_hub=SCREAMING_SNAKE_CASE__		,use_auth_token=self._token							)

             __SCREAMING_SNAKE_CASE   :List[Any]						=  GenerationConfig.from_pretrained(f'''{USER}/test-generation-config'''							)
             for k, v in config.to_dict().items():
                   if k != "transformers_version":
                         self.assertEqual(SCREAMING_SNAKE_CASE__		,getattr(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)




       def     _UpperCamelCase     (						self							)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[Any]						=  GenerationConfig(
                 do_sample=SCREAMING_SNAKE_CASE__		,temperature=0.7		,length_penalty=1.0		,)
             config.push_to_hub('''valid_org/test-generation-config-org'''		,use_auth_token=self._token							)

             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  GenerationConfig.from_pretrained('''valid_org/test-generation-config-org'''							)
             for k, v in config.to_dict().items():
                   if k != "transformers_version":
                         self.assertEqual(SCREAMING_SNAKE_CASE__		,getattr(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)

        # Reset repo
             delete_repo(token=self._token		,repo_id='''valid_org/test-generation-config-org'''							)

             # Push to hub via save_pretrained
             with tempfile.TemporaryDirectory() as tmp_dir:
                   config.save_pretrained(
                       SCREAMING_SNAKE_CASE__		,repo_id='''valid_org/test-generation-config-org'''		,push_to_hub=SCREAMING_SNAKE_CASE__		,use_auth_token=self._token							)

             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  GenerationConfig.from_pretrained('''valid_org/test-generation-config-org'''							)
             for k, v in config.to_dict().items():
                   if k != "transformers_version":
                         self.assertEqual(SCREAMING_SNAKE_CASE__		,getattr(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)






"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase_								=		logging.get_logger(__name__)

lowerCamelCase_								=		{
    "google/vivit-b-16x2-kinetics400": (
        "https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      List[str]							=  '''vivit'''




       def __init__(						self		,SCREAMING_SNAKE_CASE__=2_24		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=[2, 16, 16]		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=7_68		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=30_72		,SCREAMING_SNAKE_CASE__="gelu_fast"		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-06		,SCREAMING_SNAKE_CASE__=True		,**SCREAMING_SNAKE_CASE__		,)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  hidden_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_hidden_layers
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  num_attention_heads
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  intermediate_size
             __SCREAMING_SNAKE_CASE   :Any						=  hidden_act
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE   :str						=  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE   :Any						=  initializer_range
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  layer_norm_eps

             __SCREAMING_SNAKE_CASE   :Optional[int]						=  image_size
             __SCREAMING_SNAKE_CASE   :List[str]						=  num_frames
             __SCREAMING_SNAKE_CASE   :Any						=  tubelet_size
             __SCREAMING_SNAKE_CASE   :str						=  num_channels
             __SCREAMING_SNAKE_CASE   :Any						=  qkv_bias

             super().__init__(**SCREAMING_SNAKE_CASE__							)