




import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


a__		     =     get_logger(__name__)


a__		     =     R'''
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam
            search or log softmax for each vocabulary token when using beam search
        kwargs (`Dict[str, Any]`, *optional*):
            Additional logits processor specific kwargs.

    Return:
        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.

'''


class    SCREAMING_SNAKE_CASE_				:



	"""simple docstring"""


	@add_start_docstrings(lowerCAmelCase	)
	def __call__(					self		:						str					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray	)	->       jnp.ndarray:







						"""simple docstring"""







						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''	)






class    SCREAMING_SNAKE_CASE_				:



	"""simple docstring"""


	@add_start_docstrings(lowerCAmelCase	)
	def __call__(					self		:						Tuple					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray	)	->       jnp.ndarray:







						"""simple docstring"""







						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''	)






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	@add_start_docstrings(lowerCAmelCase	)
	def __call__(					self		:						Optional[int]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int					,     **lowerCAmelCase		:						Optional[int]	)	->       jnp.ndarray:







						"""simple docstring"""







						for processor in self:
											__UpperCamelCase					:	Optional[Any]             =      inspect.signature(processor.__call__	).parameters
											if len(lowerCAmelCase	) > 3:
																if not all(arg in kwargs for arg in list(function_args.keys()	)[2:]	):
																					raise ValueError(
																					    F'''Make sure that all the required parameters: {list(function_args.keys()	)} for '''
																					    F'''{processor.__class__} are passed to the logits processor.'''	)
																__UpperCamelCase					:	int             =      processor(lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase					,     **lowerCAmelCase	)
											else:
																__UpperCamelCase					:	Dict             =      processor(lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase	)
						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						List[Any]					,     lowerCAmelCase		:						float	)	->       Dict:







						"""simple docstring"""







						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or not (temperature > 0):
											raise ValueError(F'''`temperature` has to be a strictly positive float, but is {temperature}'''	)

						__UpperCamelCase					:	Optional[Any]             =      temperature






	def __call__(					self		:						int					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase					:	Optional[Any]             =      scores / self.temperature
						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						List[Any]					,     lowerCAmelCase		:						float					,     lowerCAmelCase		:						float = -float("""Inf"""	)					,     lowerCAmelCase		:						int = 1	)	->       List[str]:







						"""simple docstring"""







						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or (top_p < 0 or top_p > 1.0):
											raise ValueError(F'''`top_p` has to be a float > 0 and < 1, but is {top_p}'''	)
						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or (min_tokens_to_keep < 1):
											raise ValueError(F'''`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}'''	)

						__UpperCamelCase					:	int             =      top_p
						__UpperCamelCase					:	Tuple             =      filter_value
						__UpperCamelCase					:	Tuple             =      min_tokens_to_keep






	def __call__(					self		:						Optional[int]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase      ,			__UpperCamelCase					:	List[Any]             =      lax.top_k(lowerCAmelCase					,     scores.shape[-1]	)

						__UpperCamelCase					:	List[str]             =      jnp.full_like(lowerCAmelCase					,     self.filter_value	)
						__UpperCamelCase					:	List[Any]             =      jax.nn.softmax(lowerCAmelCase					,     axis=-1	).cumsum(axis=-1	)
						__UpperCamelCase					:	int             =      cumulative_probs < self.top_p

						# include the token that is higher than top_p as well
						__UpperCamelCase					:	int             =      jnp.roll(lowerCAmelCase					,     1	)
						score_mask |= score_mask.at[:, 0].set(lowerCAmelCase	)

						# min tokens to keep
						__UpperCamelCase					:	int             =      score_mask.at[:, : self.min_tokens_to_keep].set(lowerCAmelCase	)

						__UpperCamelCase					:	List[Any]             =      jnp.where(lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase	)
						__UpperCamelCase					:	Optional[int]             =      jax.lax.sort_key_val(lowerCAmelCase					,     lowerCAmelCase	)[-1]

						return next_scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Optional[Any]					,     lowerCAmelCase		:						int					,     lowerCAmelCase		:						float = -float("""Inf"""	)					,     lowerCAmelCase		:						int = 1	)	->       int:







						"""simple docstring"""







						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or top_k <= 0:
											raise ValueError(F'''`top_k` has to be a strictly positive integer, but is {top_k}'''	)

						__UpperCamelCase					:	List[str]             =      max(lowerCAmelCase					,     lowerCAmelCase	)
						__UpperCamelCase					:	Tuple             =      filter_value






	def __call__(					self		:						List[str]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase      ,			__UpperCamelCase					:	Optional[int]             =      scores.shape
						__UpperCamelCase					:	Optional[Any]             =      jnp.full(batch_size * vocab_size					,     self.filter_value	)

						__UpperCamelCase					:	List[Any]             =      min(self.top_k					,     scores.shape[-1]	)  # Safety check
						__UpperCamelCase      ,			__UpperCamelCase					:	int             =      lax.top_k(lowerCAmelCase					,     lowerCAmelCase	)
						__UpperCamelCase					:	List[str]             =      jnp.broadcast_to((jnp.arange(lowerCAmelCase	) * vocab_size)[:, None]					,     (batch_size, topk)	).flatten()
						__UpperCamelCase					:	List[Any]             =      topk_scores.flatten()
						__UpperCamelCase					:	Optional[Any]             =      topk_indices.flatten() + shift

						__UpperCamelCase					:	List[str]             =      next_scores_flat.at[topk_indices_flat].set(lowerCAmelCase	)
						__UpperCamelCase					:	str             =      next_scores_flat.reshape(lowerCAmelCase					,     lowerCAmelCase	)
						return next_scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Optional[int]					,     lowerCAmelCase		:						int	)	->       List[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	Optional[int]             =      bos_token_id






	def __call__(					self		:						Optional[Any]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase					:	Optional[int]             =      jnp.full(scores.shape					,     -float("""inf"""	)	)

						__UpperCamelCase					:	Optional[Any]             =      1 - jnp.bool_(cur_len - 1	)

						__UpperCamelCase					:	Any             =      jnp.where(lowerCAmelCase					,     new_scores.at[:, self.bos_token_id].set(0	)					,     lowerCAmelCase	)

						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Any					,     lowerCAmelCase		:						int					,     lowerCAmelCase		:						int	)	->       List[str]:







						"""simple docstring"""







						__UpperCamelCase					:	int             =      max_length
						__UpperCamelCase					:	Optional[int]             =      eos_token_id






	def __call__(					self		:						Union[str, Any]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase					:	List[Any]             =      jnp.full(scores.shape					,     -float("""inf"""	)	)

						__UpperCamelCase					:	Any             =      1 - jnp.bool_(cur_len - self.max_length + 1	)

						__UpperCamelCase					:	List[str]             =      jnp.where(lowerCAmelCase					,     new_scores.at[:, self.eos_token_id].set(0	)					,     lowerCAmelCase	)

						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Dict					,     lowerCAmelCase		:						int					,     lowerCAmelCase		:						int	)	->       int:







						"""simple docstring"""







						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or min_length < 0:
											raise ValueError(F'''`min_length` has to be a positive integer, but is {min_length}'''	)

						if not isinstance(lowerCAmelCase					,     lowerCAmelCase	) or eos_token_id < 0:
											raise ValueError(F'''`eos_token_id` has to be a positive integer, but is {eos_token_id}'''	)

						__UpperCamelCase					:	Union[str, Any]             =      min_length
						__UpperCamelCase					:	Any             =      eos_token_id






	def __call__(					self		:						Union[str, Any]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase					:	List[str]             =      1 - jnp.clip(cur_len - self.min_length					,     0					,     1	)

						__UpperCamelCase					:	Dict             =      jnp.where(lowerCAmelCase					,     scores.at[:, self.eos_token_id].set(-float("""inf"""	)	)					,     lowerCAmelCase	)

						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Union[str, Any]					,     lowerCAmelCase		:						int					,     lowerCAmelCase		:						Optional[Any]	)	->       List[str]:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      list(lowerCAmelCase	)
						__UpperCamelCase					:	Tuple             =      begin_index






	def __call__(					self		:						int					,     lowerCAmelCase		:						Optional[Any]					,     lowerCAmelCase		:						Union[str, Any]					,     lowerCAmelCase		:						int	)	->       int:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      1 - jnp.bool_(cur_len - self.begin_index	)

						__UpperCamelCase					:	Dict             =      jnp.where(lowerCAmelCase					,     scores.at[:, self.begin_suppress_tokens].set(-float("""inf"""	)	)					,     lowerCAmelCase	)

						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						int					,     lowerCAmelCase		:						list	)	->       int:







						"""simple docstring"""







						__UpperCamelCase					:	Tuple             =      list(lowerCAmelCase	)






	def __call__(					self		:						List[str]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						__UpperCamelCase					:	Dict             =      scores.at[..., self.suppress_tokens].set(-float("""inf"""	)	)

						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						Optional[Any]					,     lowerCAmelCase		:						Any	)	->       Any:







						"""simple docstring"""







						__UpperCamelCase					:	Union[str, Any]             =      dict(lowerCAmelCase	)
						# Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
						# index of the array corresponds to the index of the token to be forced, for XLA compatibility.
						# Indexes without forced tokens will have a negative value.
						__UpperCamelCase					:	int             =      jnp.ones((max(force_token_map.keys()	) + 1)					,     dtype=jnp.intaa	) * -1
						for index, token in force_token_map.items():
											if token is not None:
																__UpperCamelCase					:	Optional[int]             =      force_token_array.at[index].set(lowerCAmelCase	)
						__UpperCamelCase					:	List[Any]             =      jnp.intaa(lowerCAmelCase	)






	def __call__(					self		:						List[str]					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						jnp.ndarray					,     lowerCAmelCase		:						int	)	->       jnp.ndarray:







						"""simple docstring"""







						def _force_token(lowerCAmelCase		:						Optional[int]	):
											__UpperCamelCase					:	List[Any]             =      scores.shape[0]
											__UpperCamelCase					:	int             =      self.force_token_array[generation_idx]

											__UpperCamelCase					:	int             =      jnp.ones_like(lowerCAmelCase					,     dtype=scores.dtype	) * -float("""inf"""	)
											__UpperCamelCase					:	List[Any]             =      jnp.zeros((batch_size, 1)					,     dtype=scores.dtype	)
											__UpperCamelCase					:	List[Any]             =      lax.dynamic_update_slice(lowerCAmelCase					,     lowerCAmelCase					,     (0, current_token)	)
											return new_scores

						__UpperCamelCase					:	Optional[int]             =      lax.cond(
						    cur_len >= self.force_token_array.shape[0]					,     lambda: scores					,     lambda: lax.cond(
						        self.force_token_array[cur_len] >= 0					,     lambda: _force_token(lowerCAmelCase	)					,     lambda: scores					,     )					,     )
						return scores






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def __init__(					self		:						List[Any]					,     lowerCAmelCase		:						int					,     lowerCAmelCase		:						Optional[int]					,     lowerCAmelCase		:						Any	)	->       List[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      generate_config.eos_token_id
						__UpperCamelCase					:	int             =      generate_config.no_timestamps_token_id
						__UpperCamelCase					:	Dict             =      generate_config.no_timestamps_token_id + 1

						__UpperCamelCase					:	Optional[int]             =      decoder_input_length + 1

						if generate_config.is_multilingual:
											# room for language token and task token
											self.begin_index += 2
						if hasattr(lowerCAmelCase					,     """max_initial_timestamp_index"""	):
											__UpperCamelCase					:	Optional[int]             =      generate_config.max_initial_timestamp_index
						else:
											__UpperCamelCase					:	Any             =      model_config.vocab_size
						if self.max_initial_timestamp_index is None:
											__UpperCamelCase					:	Dict             =      model_config.vocab_size






	def __call__(					self		:						List[str]					,     lowerCAmelCase		:						Dict					,     lowerCAmelCase		:						Optional[Any]					,     lowerCAmelCase		:						str	)	->       Optional[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	Union[str, Any]             =      scores.at[:, self.no_timestamps_token_id].set(-float("""inf"""	)	)

						def handle_pairs(lowerCAmelCase		:						Tuple					,     lowerCAmelCase		:						int	):
											__UpperCamelCase					:	Union[str, Any]             =      jnp.where((cur_len - self.begin_index) >= 1					,     lowerCAmelCase					,     lowerCAmelCase	)
											__UpperCamelCase					:	str             =      jnp.where(
											    input_ids_k[cur_len - 1] >= self.timestamp_begin					,     True and last_was_timestamp					,     lowerCAmelCase					,     )

											__UpperCamelCase					:	Dict             =      jnp.where((cur_len - self.begin_index) < 2					,     lowerCAmelCase					,     lowerCAmelCase	)
											__UpperCamelCase					:	str             =      jnp.where(
											    input_ids_k[cur_len - 2] >= self.timestamp_begin					,     lowerCAmelCase					,     lowerCAmelCase					,     )

											return jnp.where(
											    lowerCAmelCase					,     jnp.where(
											        penultimate_was_timestamp > 0					,     scores_k.at[self.timestamp_begin :].set(-float("""inf"""	)	)					,     scores_k.at[: self.eos_token_id].set(-float("""inf"""	)	)					,     )					,     lowerCAmelCase					,     )

						__UpperCamelCase					:	Any             =      jax.vmap(lowerCAmelCase	)(lowerCAmelCase					,     lowerCAmelCase	)

						__UpperCamelCase					:	Union[str, Any]             =      jnp.where(cur_len == self.begin_index					,     lowerCAmelCase					,     lowerCAmelCase	)
						__UpperCamelCase					:	Union[str, Any]             =      jnp.where(
						    self.max_initial_timestamp_index is not None					,     True and apply_max_initial_timestamp					,     lowerCAmelCase					,     )

						__UpperCamelCase					:	Any             =      self.timestamp_begin + self.max_initial_timestamp_index

						__UpperCamelCase					:	Any             =      jnp.where(
						    lowerCAmelCase					,     scores.at[:, last_allowed + 1 :].set(-float("""inf"""	)	)					,     lowerCAmelCase					,     )

						# if sum of probability over timestamps is above any other token, sample timestamp
						__UpperCamelCase					:	Optional[int]             =      jax.nn.log_softmax(lowerCAmelCase					,     axis=-1	)

						def handle_cumulative_probs(lowerCAmelCase		:						List[Any]					,     lowerCAmelCase		:						Optional[int]	):
											__UpperCamelCase					:	Any             =      jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]					,     axis=-1	)
											__UpperCamelCase					:	Tuple             =      jnp.max(logprobs_k[: self.timestamp_begin]	)
											return jnp.where(
											    timestamp_logprob > max_text_token_logprob					,     scores_k.at[: self.timestamp_begin].set(-float("""inf"""	)	)					,     lowerCAmelCase					,     )

						__UpperCamelCase					:	List[Any]             =      jax.vmap(lowerCAmelCase	)(lowerCAmelCase					,     lowerCAmelCase	)

						return scores












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    SCREAMING_SNAKE_CASE_				(       unittest.TestCase   ):



	"""simple docstring"""


	def 					lowerCamelCase__     (					self		:						str	)	->       Dict:







						"""simple docstring"""







						__UpperCamelCase					:	Optional[Any]             =      0






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







						"""simple docstring"""







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






	def 					lowerCamelCase__     (					self		:						Optional[Any]	)	->       Dict:







						"""simple docstring"""







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






	def 					lowerCamelCase__     (					self		:						List[Any]	)	->       Optional[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	Dict             =      AutoConfig.from_pretrained(lowerCAmelCase	)
						self.assertIsInstance(lowerCAmelCase					,     lowerCAmelCase	)






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







						"""simple docstring"""







						__UpperCamelCase					:	Optional[int]             =      AutoConfig.from_pretrained(lowerCAmelCase	)
						self.assertIsInstance(lowerCAmelCase					,     lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Tuple	)	->       Any:







						"""simple docstring"""







						__UpperCamelCase					:	List[Any]             =      AutoConfig.for_model("""roberta"""	)
						self.assertIsInstance(lowerCAmelCase					,     lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						int	)	->       List[Any]:







						"""simple docstring"""







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






	def 					lowerCamelCase__     (					self		:						int	)	->       str:







						"""simple docstring"""







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

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

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






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







						"""simple docstring"""







						with self.assertRaisesRegex(
						    lowerCAmelCase					,     """bert-base is not a local folder and is not a valid model identifier"""	):
											__UpperCamelCase					:	Tuple             =      AutoConfig.from_pretrained("""bert-base"""	)






	def 					lowerCamelCase__     (					self		:						Dict	)	->       Any:







						"""simple docstring"""







						with self.assertRaisesRegex(
						    lowerCAmelCase					,     R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""	):
											__UpperCamelCase					:	Optional[Any]             =      AutoConfig.from_pretrained(lowerCAmelCase					,     revision="""aaaaaa"""	)






	def 					lowerCamelCase__     (					self		:						str	)	->       List[str]:







						"""simple docstring"""







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






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







						"""simple docstring"""







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

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

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






	def 					lowerCamelCase__     (					self		:						Optional[int]	)	->       str:







						"""simple docstring"""







						class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



							"""simple docstring"""


							__magic_name__   :       int      	=		'new-model'

						try:
											AutoConfig.register("""new-model"""					,     lowerCAmelCase	)
											# If remote code is not set, the default is to use local
											__UpperCamelCase					:	Tuple             =      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=lowerCAmelCase	)
											self.assertEqual(config.__class__.__name__					,     """NewModelConfigLocal"""	)

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

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






