



"""simple docstring"""





import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / """utils"""))

from test_module.custom_configuration import CustomConfig  # noqa E402


A   =       get_tests_dir("""fixtures/dummy-config.json""")



class      a__				(	unittest.TestCase   ):


			def       a_     (      self      :    Optional[int]):


						"""simple docstring"""




						__UpperCAmelCase	: Any		=					0


			def       a_     (      self      :    List[Any]):


						"""simple docstring"""




						self.assertIsNotNone(transformers.models.auto.__spec__)
						self.assertIsNotNone(importlib.util.find_spec("transformers.models.auto"))


			def       a_     (      self      :    int):


						"""simple docstring"""




						__UpperCAmelCase	: int		=					AutoConfig.from_pretrained("bert-base-uncased")
						self.assertIsInstance(UpperCamelCase_      ,  UpperCamelCase_)


			def       a_     (      self      :    List[Any]):


						"""simple docstring"""




						__UpperCAmelCase	: List[str]		=					AutoConfig.from_pretrained(UpperCamelCase_)
						self.assertIsInstance(UpperCamelCase_      ,  UpperCamelCase_)


			def       a_     (      self      :    str):


						"""simple docstring"""




						__UpperCAmelCase	: Dict		=					AutoConfig.from_pretrained(UpperCamelCase_)
						self.assertIsInstance(UpperCamelCase_      ,  UpperCamelCase_)


			def       a_     (      self      :    Dict):


						"""simple docstring"""




						__UpperCAmelCase	: Optional[int]		=					AutoConfig.for_model("roberta")
						self.assertIsInstance(UpperCamelCase_      ,  UpperCamelCase_)


			def       a_     (      self      :    Union[str, Any]):


						"""simple docstring"""




						with tempfile.TemporaryDirectory() as tmp_dir:
									# This model name contains bert and roberta, but roberta ends up being picked.
									__UpperCAmelCase	: Any		=					os.path.join(UpperCamelCase_      ,  "fake-roberta")
									os.makedirs(UpperCamelCase_      ,  exist_ok=UpperCamelCase_)
									with open(os.path.join(UpperCamelCase_      ,  "config.json")      ,  "w") as f:
												f.write(json.dumps({}))
									__UpperCAmelCase	: str		=					AutoConfig.from_pretrained(UpperCamelCase_)
									self.assertEqual(type(UpperCamelCase_)      ,  UpperCamelCase_)


			def       a_     (      self      :    str):


						"""simple docstring"""




						try:
									AutoConfig.register("custom"      ,  UpperCamelCase_)
									# Wrong model type will raise an error
									with self.assertRaises(UpperCamelCase_):
												AutoConfig.register("model"      ,  UpperCamelCase_)
									# Trying to register something existing in the Transformers library will raise an error
									with self.assertRaises(UpperCamelCase_):
												AutoConfig.register("bert"      ,  UpperCamelCase_)

									# Now that the config is registered, it can be used as any other config with the auto-API
									__UpperCAmelCase	: Tuple		=					CustomConfig()
									with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(UpperCamelCase_)
												__UpperCAmelCase	: Union[str, Any]		=					AutoConfig.from_pretrained(UpperCamelCase_)
												self.assertIsInstance(UpperCamelCase_      ,  UpperCamelCase_)

						finally:
									if "custom" in CONFIG_MAPPING._extra_content:
												del CONFIG_MAPPING._extra_content["custom"]


			def       a_     (      self      :    List[Any]):


						"""simple docstring"""




						with self.assertRaisesRegex(
						    UpperCamelCase_      ,  "bert-base is not a local folder and is not a valid model identifier"):
									__UpperCAmelCase	: List[str]		=					AutoConfig.from_pretrained("bert-base")


			def       a_     (      self      :    Optional[Any]):


						"""simple docstring"""




						with self.assertRaisesRegex(
						    UpperCamelCase_      ,  r"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"):
									__UpperCAmelCase	: Any		=					AutoConfig.from_pretrained(UpperCamelCase_      ,  revision="aaaaaa")


			def       a_     (      self      :    Optional[int]):


						"""simple docstring"""




						with self.assertRaisesRegex(
						    UpperCamelCase_      ,  "hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."      ,  ):
									__UpperCAmelCase	: Optional[Any]		=					AutoConfig.from_pretrained("hf-internal-testing/no-config-test-repo")


			def       a_     (      self      :    Any):


						"""simple docstring"""




						with self.assertRaises(UpperCamelCase_):
									__UpperCAmelCase	: int		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model")
						# If remote code is disabled, we can't load this config.
						with self.assertRaises(UpperCamelCase_):
									__UpperCAmelCase	: Tuple		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,  trust_remote_code=UpperCamelCase_)

						__UpperCAmelCase	: List[str]		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,  trust_remote_code=UpperCamelCase_)
						self.assertEqual(config.__class__.__name__      ,  "NewModelConfig")

						# Test config can be reloaded.
						with tempfile.TemporaryDirectory() as tmp_dir:
									config.save_pretrained(UpperCamelCase_)
									__UpperCAmelCase	: Dict		=					AutoConfig.from_pretrained(UpperCamelCase_      ,  trust_remote_code=UpperCamelCase_)
						self.assertEqual(reloaded_config.__class__.__name__      ,  "NewModelConfig")


			def       a_     (      self      :    List[str]):


						"""simple docstring"""




						class      a__				(	__magic_name__   ):
									lowercase_    =	"new-model"

						try:
									AutoConfig.register("new-model"      ,  UpperCamelCase_)
									# If remote code is not set, the default is to use local
									__UpperCAmelCase	: Optional[int]		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model")
									self.assertEqual(config.__class__.__name__      ,  "NewModelConfigLocal")

									# If remote code is disabled, we load the local one.
									__UpperCAmelCase	: Any		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,  trust_remote_code=UpperCamelCase_)
									self.assertEqual(config.__class__.__name__      ,  "NewModelConfigLocal")

									# If remote is enabled, we load from the Hub
									__UpperCAmelCase	: Union[str, Any]		=					AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,  trust_remote_code=UpperCamelCase_)
									self.assertEqual(config.__class__.__name__      ,  "NewModelConfig")

						finally:
									if "new-model" in CONFIG_MAPPING._extra_content:
												del CONFIG_MAPPING._extra_content["new-model"]








"""simple docstring"""





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


A   =       logging.get_logger(__name__)

A   =       {
    """bigcode/gpt_bigcode-santacoder""": """https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json""",
}



class      a__				(	__magic_name__   ):
			lowercase_    =	"gpt_bigcode"
			lowercase_    =	["past_key_values"]
			lowercase_    =	{
			    "hidden_size": "n_embd",
			    "max_position_embeddings": "n_positions",
			    "num_attention_heads": "n_head",
			    "num_hidden_layers": "n_layer",
			}


			def __init__(      self      :    Any      ,  UpperCamelCase_      :    Tuple=50257      ,  UpperCamelCase_      :    Dict=1024      ,  UpperCamelCase_      :    Optional[Any]=768      ,  UpperCamelCase_      :    Optional[Any]=12      ,  UpperCamelCase_      :    Any=12      ,  UpperCamelCase_      :    Optional[int]=None      ,  UpperCamelCase_      :    List[Any]="gelu_pytorch_tanh"      ,  UpperCamelCase_      :    Optional[Any]=0.1      ,  UpperCamelCase_      :    Union[str, Any]=0.1      ,  UpperCamelCase_      :    Tuple=0.1      ,  UpperCamelCase_      :    Tuple=1e-5      ,  UpperCamelCase_      :    List[str]=0.02      ,  UpperCamelCase_      :    Dict=True      ,  UpperCamelCase_      :    Optional[int]=True      ,  UpperCamelCase_      :    str=50256      ,  UpperCamelCase_      :    Union[str, Any]=50256      ,  UpperCamelCase_      :    Dict=True      ,  UpperCamelCase_      :    List[str]=True      ,  UpperCamelCase_      :    Union[str, Any]=True      ,  **UpperCamelCase_      :    Union[str, Any]      ,  ):


						"""simple docstring"""




						__UpperCAmelCase	: Tuple		=					vocab_size
						__UpperCAmelCase	: Optional[int]		=					n_positions
						__UpperCAmelCase	: Tuple		=					n_embd
						__UpperCAmelCase	: str		=					n_layer
						__UpperCAmelCase	: Dict		=					n_head
						__UpperCAmelCase	: Optional[Any]		=					n_inner
						__UpperCAmelCase	: Optional[Any]		=					activation_function
						__UpperCAmelCase	: List[str]		=					resid_pdrop
						__UpperCAmelCase	: List[Any]		=					embd_pdrop
						__UpperCAmelCase	: Optional[Any]		=					attn_pdrop
						__UpperCAmelCase	: Dict		=					layer_norm_epsilon
						__UpperCAmelCase	: List[str]		=					initializer_range
						__UpperCAmelCase	: int		=					scale_attn_weights
						__UpperCAmelCase	: Tuple		=					use_cache
						__UpperCAmelCase	: List[Any]		=					attention_softmax_in_fpaa
						__UpperCAmelCase	: Any		=					scale_attention_softmax_in_fpaa
						__UpperCAmelCase	: str		=					multi_query

						__UpperCAmelCase	: int		=					bos_token_id
						__UpperCAmelCase	: str		=					eos_token_id

						super().__init__(bos_token_id=UpperCamelCase_      ,  eos_token_id=UpperCamelCase_      ,  **UpperCamelCase_)


