





'''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      ):






				"""simple docstring"""







				@parameterized.expand([(None,), ("foo.json",)]					)
				def   UpperCamelCase__   (  self     :					Tuple					,				__a     :					Optional[Any]					):
								_a								= GenerationConfig(
								    do_sample=__a					,				temperature=0.7					,				length_penalty=1.0					,				bad_words_ids=[[1, 2, 3], [4, 5]]					,				)
								with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(__a					,				config_name=__a					)
												_a								= GenerationConfig.from_pretrained(__a					,				config_name=__a					)

								# Checks parameters that were specified
								self.assertEqual(loaded_config.do_sample					,				__a					)
								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					,				__a					)




				def   UpperCamelCase__   (  self     :					Union[str, Any]					):
								_a								= AutoConfig.from_pretrained("gpt2"					)
								_a								= GenerationConfig.from_model_config(__a					)
								_a								= GenerationConfig()

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

								# 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     :					int					):
								_a								= GenerationConfig()
								_a								= {
								    "max_new_tokens": 10_24,
								    "foo": "bar",
								}
								_a								= copy.deepcopy(__a					)
								_a								= generation_config.update(**__a					)

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

								# 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(__a					,				{"foo": "bar"}					)




				def   UpperCamelCase__   (  self     :					Dict					):
								_a								= GenerationConfig()
								_a								= "bar"

								with tempfile.TemporaryDirectory("test-generation-config"					) as tmp_dir:
												generation_config.save_pretrained(__a					)

												_a								= GenerationConfig.from_pretrained(__a					)
								# update_kwargs was used to update the config on valid attributes
								self.assertEqual(new_config.foo					,				"bar"					)

								_a								= GenerationConfig.from_model_config(__a					)
								assert not hasattr(__a					,				"foo"					)  # no new kwargs should be initialized if from config




				def   UpperCamelCase__   (  self     :					Dict					):
								_a								= GenerationConfig()
								self.assertEqual(default_config.temperature					,				1.0					)
								self.assertEqual(default_config.do_sample					,				__a					)
								self.assertEqual(default_config.num_beams					,				1					)

								_a								= GenerationConfig(
								    do_sample=__a					,				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					,				__a					)
								self.assertEqual(config.num_beams					,				1					)

								with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(__a					)
												_a								= GenerationConfig.from_pretrained(__a					,				temperature=1.0					)

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


@is_staging_test
class 				__SCREAMING_SNAKE_CASE  (unittest.TestCase      ):






				"""simple docstring"""







				@classmethod
				def   UpperCamelCase__   (  cls     :					Union[str, Any]					):
								_a								= TOKEN
								HfFolder.save_token(__a					)




				@classmethod
				def   UpperCamelCase__   (  cls     :					Optional[Any]					):
								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     :					Optional[Any]					):
								_a								= GenerationConfig(
								    do_sample=__a					,				temperature=0.7					,				length_penalty=1.0					,				)
								config.push_to_hub("test-generation-config"					,				use_auth_token=self._token					)

								_a								= GenerationConfig.from_pretrained(f'{USER}/test-generation-config'					)
								for k, v in config.to_dict().items():
												if k != "transformers_version":
																self.assertEqual(__a					,				getattr(__a					,				__a					)					)

        # 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(
												    __a					,				repo_id="test-generation-config"					,				push_to_hub=__a					,				use_auth_token=self._token					)

								_a								= GenerationConfig.from_pretrained(f'{USER}/test-generation-config'					)
								for k, v in config.to_dict().items():
												if k != "transformers_version":
																self.assertEqual(__a					,				getattr(__a					,				__a					)					)




				def   UpperCamelCase__   (  self     :					int					):
								_a								= GenerationConfig(
								    do_sample=__a					,				temperature=0.7					,				length_penalty=1.0					,				)
								config.push_to_hub("valid_org/test-generation-config-org"					,				use_auth_token=self._token					)

								_a								= GenerationConfig.from_pretrained("valid_org/test-generation-config-org"					)
								for k, v in config.to_dict().items():
												if k != "transformers_version":
																self.assertEqual(__a					,				getattr(__a					,				__a					)					)

        # 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(
												    __a					,				repo_id="valid_org/test-generation-config-org"					,				push_to_hub=__a					,				use_auth_token=self._token					)

								_a								= GenerationConfig.from_pretrained("valid_org/test-generation-config-org"					)
								for k, v in config.to_dict().items():
												if k != "transformers_version":
																self.assertEqual(__a					,				getattr(__a					,				__a					)					)







'''simple docstring'''







from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase_					:    int      	=			logging.get_logger(__name__)

lowerCAmelCase_					:    Tuple      	=			{
    'google/bigbird-roberta-base': 'https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json',
    'google/bigbird-roberta-large': 'https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json',
    'google/bigbird-base-trivia-itc': 'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json',
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            ='big_bird'




				def __init__(  self     :					Optional[int]					,				__a     :					Dict=5_03_58					,				__a     :					str=7_68					,				__a     :					List[Any]=12					,				__a     :					List[str]=12					,				__a     :					Union[str, Any]=30_72					,				__a     :					str="gelu_new"					,				__a     :					Dict=0.1					,				__a     :					Union[str, Any]=0.1					,				__a     :					Any=40_96					,				__a     :					int=2					,				__a     :					Tuple=0.02					,				__a     :					List[Any]=1e-1_2					,				__a     :					int=True					,				__a     :					List[str]=0					,				__a     :					Tuple=1					,				__a     :					Optional[Any]=2					,				__a     :					Tuple=66					,				__a     :					str="block_sparse"					,				__a     :					Tuple=True					,				__a     :					Optional[int]=False					,				__a     :					str=64					,				__a     :					Tuple=3					,				__a     :					Any=None					,				**__a     :					Dict					,				):
								super().__init__(
								    pad_token_id=__a					,				bos_token_id=__a					,				eos_token_id=__a					,				sep_token_id=__a					,				**__a					,				)

								_a								= vocab_size
								_a								= max_position_embeddings
								_a								= hidden_size
								_a								= num_hidden_layers
								_a								= num_attention_heads
								_a								= intermediate_size
								_a								= hidden_act
								_a								= hidden_dropout_prob
								_a								= attention_probs_dropout_prob
								_a								= initializer_range
								_a								= type_vocab_size
								_a								= layer_norm_eps
								_a								= use_cache

								_a								= rescale_embeddings
								_a								= attention_type
								_a								= use_bias
								_a								= block_size
								_a								= num_random_blocks
								_a								= classifier_dropout


class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				@property
				def   UpperCamelCase__   (  self     :					Optional[int]					):
								if self.task == "multiple-choice":
												_a								= {0: "batch", 1: "choice", 2: "sequence"}
								else:
												_a								= {0: "batch", 1: "sequence"}
								return OrderedDict(
								    [
								        ("input_ids", dynamic_axis),
								        ("attention_mask", dynamic_axis),
								    ]					)
