
"""simple docstring"""





import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
		import jax

		from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
		from transformers.models.bert.modeling_flax_bert import FlaxBertModel
		from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel



@require_flax
class __lowerCAmelCase				(					unittest.TestCase      ):




			"""simple docstring"""







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







								"""simple docstring"""
								for model_name in ["bert-base-cased", "bert-large-uncased"]:
													with self.subTest(_snake_case	):
																		A_				 =						AutoConfig.from_pretrained(_snake_case	)
																		self.assertIsNotNone(_snake_case	)
																		self.assertIsInstance(_snake_case       ,   _snake_case	)

																		A_				 =						FlaxAutoModel.from_pretrained(_snake_case	)
																		self.assertIsNotNone(_snake_case	)
																		self.assertIsInstance(_snake_case       ,   _snake_case	)




			@slow
			def      lowerCamelCase__     (				self						:					Any	)      -> Tuple:







								"""simple docstring"""
								for model_name in ["roberta-base", "roberta-large"]:
													with self.subTest(_snake_case	):
																		A_				 =						AutoConfig.from_pretrained(_snake_case	)
																		self.assertIsNotNone(_snake_case	)
																		self.assertIsInstance(_snake_case       ,   _snake_case	)

																		A_				 =						FlaxAutoModel.from_pretrained(_snake_case	)
																		self.assertIsNotNone(_snake_case	)
																		self.assertIsInstance(_snake_case       ,   _snake_case	)




			@slow
			def      lowerCamelCase__     (				self						:					Dict	)      -> Any:







								"""simple docstring"""
								for model_name in ["bert-base-cased", "bert-large-uncased"]:
													A_				 =						AutoTokenizer.from_pretrained(_snake_case	)
													A_				 =						FlaxBertModel.from_pretrained(_snake_case	)
													A_				 =						tokenizer("Do you support jax jitted function?"       ,   return_tensors=TensorType.JAX	)

													@jax.jit
													def eval(**_snake_case						:					List[Any]	):
																		return model(**_snake_case	)

													eval(**_snake_case	).block_until_ready()




			@slow
			def      lowerCamelCase__     (				self						:					int	)      -> Dict:







								"""simple docstring"""
								for model_name in ["roberta-base", "roberta-large"]:
													A_				 =						AutoTokenizer.from_pretrained(_snake_case	)
													A_				 =						FlaxRobertaModel.from_pretrained(_snake_case	)
													A_				 =						tokenizer("Do you support jax jitted function?"       ,   return_tensors=TensorType.JAX	)

													@jax.jit
													def eval(**_snake_case						:					int	):
																		return model(**_snake_case	)

													eval(**_snake_case	).block_until_ready()




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







								"""simple docstring"""
								with self.assertRaisesRegex(
								    _snake_case       ,   "bert-base is not a local folder and is not a valid model identifier"	):
													A_				 =						FlaxAutoModel.from_pretrained("bert-base"	)




			def      lowerCamelCase__     (				self						:					Tuple	)      -> int:







								"""simple docstring"""
								with self.assertRaisesRegex(
								    _snake_case       ,   R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"	):
													A_				 =						FlaxAutoModel.from_pretrained(_snake_case       ,   revision="aaaaaa"	)




			def      lowerCamelCase__     (				self						:					Dict	)      -> int:







								"""simple docstring"""
								with self.assertRaisesRegex(
								    _snake_case       ,   "hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"       ,   ):
													A_				 =						FlaxAutoModel.from_pretrained("hf-internal-testing/config-no-model"	)






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







								"""simple docstring"""
								with self.assertRaisesRegex(_snake_case       ,   "Use `from_pt=True` to load this model"	):
													A_				 =						FlaxAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only"	)






"""simple docstring"""





import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
UpperCamelCase_					:						Optional[Any]				= '''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
UpperCamelCase_					:						Union[str, Any]				= direct_transformers_import(PATH_TO_TRANSFORMERS)

UpperCamelCase_					:						List[Any]				= transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
UpperCamelCase_					:						str				= re.compile(R'''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


UpperCamelCase_					:						Dict				= {
    '''DecisionTransformerConfig''',
    '''EncoderDecoderConfig''',
    '''MusicgenConfig''',
    '''RagConfig''',
    '''SpeechEncoderDecoderConfig''',
    '''TimmBackboneConfig''',
    '''VisionEncoderDecoderConfig''',
    '''VisionTextDualEncoderConfig''',
    '''LlamaConfig''',
}
def 							A_     (__a				):

					'''simple docstring'''





					A_				 =						None

					# source code of `config_class`
					A_				 =						inspect.getsource(__a				)
					A_				 =						_re_checkpoint.findall(__a				)

					# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
					# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
					for ckpt_name, ckpt_link in checkpoints:
										# allow the link to end with `/`
										if ckpt_link.endswith("/"				):
															A_				 =						ckpt_link[:-1]

										# verify the checkpoint name corresponds to the checkpoint link
										A_				 =						f'https://huggingface.co/{ckpt_name}'
										if ckpt_link == ckpt_link_from_name:
															A_				 =						ckpt_name
															break

					return checkpoint
def 							A_     ():

					'''simple docstring'''





					A_				 =						[]

					for config_class in list(CONFIG_MAPPING.values()				):
										# Skip deprecated models
										if "models.deprecated" in config_class.__module__:
															continue
										A_				 =						get_checkpoint_from_config_class(__a				)

										A_				 =						config_class.__name__
										if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
															configs_without_checkpoint.append(__a				)

					if len(__a				) > 0:
										A_				 =						"\n".join(sorted(__a				)				)
										raise ValueError(f'The following configurations don\'t contain any valid checkpoint:\n{message}'				)


if __name__ == "__main__":
		check_config_docstrings_have_checkpoints()




