




'''simple docstring'''





import unittest

import numpy as np

from transformers import BertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
		from transformers.models.bert.modeling_flax_bert import (
		    FlaxBertForMaskedLM,
		    FlaxBertForMultipleChoice,
		    FlaxBertForNextSentencePrediction,
		    FlaxBertForPreTraining,
		    FlaxBertForQuestionAnswering,
		    FlaxBertForSequenceClassification,
		    FlaxBertForTokenClassification,
		    FlaxBertModel,
		)




class 			_snake_case		(     unittest.TestCase							):




			def __init__( self    ,							a__    ,							a__=13    ,							a__=7    ,							a__=True    ,							a__=True    ,							a__=True    ,							a__=True    ,							a__=99    ,							a__=32    ,							a__=5    ,							a__=4    ,							a__=37    ,							a__="gelu"    ,							a__=0.1    ,							a__=0.1    ,							a__=512    ,							a__=16    ,							a__=2    ,							a__=0.0_2    ,							a__=4    ,							)    ->    Optional[int]:

										'''simple docstring'''




										snake_case_      =				parent
										snake_case_      =				batch_size
										snake_case_      =				seq_length
										snake_case_      =				is_training
										snake_case_      =				use_attention_mask
										snake_case_      =				use_token_type_ids
										snake_case_      =				use_labels
										snake_case_      =				vocab_size
										snake_case_      =				hidden_size
										snake_case_      =				num_hidden_layers
										snake_case_      =				num_attention_heads
										snake_case_      =				intermediate_size
										snake_case_      =				hidden_act
										snake_case_      =				hidden_dropout_prob
										snake_case_      =				attention_probs_dropout_prob
										snake_case_      =				max_position_embeddings
										snake_case_      =				type_vocab_size
										snake_case_      =				type_sequence_label_size
										snake_case_      =				initializer_range
										snake_case_      =				num_choices




			def        lowerCAmelCase__    ( self							)    ->    Any:

										'''simple docstring'''




										snake_case_      =				ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size							)

										snake_case_      =				None
										if self.use_attention_mask:
																	snake_case_      =				random_attention_mask([self.batch_size, self.seq_length]							)

										snake_case_      =				None
										if self.use_token_type_ids:
																	snake_case_      =				ids_tensor([self.batch_size, self.seq_length]    ,							self.type_vocab_size							)

										snake_case_      =				BertConfig(
										    vocab_size=self.vocab_size    ,							hidden_size=self.hidden_size    ,							num_hidden_layers=self.num_hidden_layers    ,							num_attention_heads=self.num_attention_heads    ,							intermediate_size=self.intermediate_size    ,							hidden_act=self.hidden_act    ,							hidden_dropout_prob=self.hidden_dropout_prob    ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,							max_position_embeddings=self.max_position_embeddings    ,							type_vocab_size=self.type_vocab_size    ,							is_decoder=a__    ,							initializer_range=self.initializer_range    ,							)

										return config, input_ids, token_type_ids, attention_mask




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

										'''simple docstring'''




										snake_case_      =				self.prepare_config_and_inputs()
										snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      =				config_and_inputs
										snake_case_      =				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
										return config, inputs_dict




			def        lowerCAmelCase__    ( self							)    ->    Tuple:

										'''simple docstring'''




										snake_case_      =				self.prepare_config_and_inputs()
										snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      =				config_and_inputs

										snake_case_      =				True
										snake_case_      =				floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
										snake_case_      =				ids_tensor([self.batch_size, self.seq_length]    ,							vocab_size=2							)

										return (
										    config,
										    input_ids,
										    attention_mask,
										    encoder_hidden_states,
										    encoder_attention_mask,
										)




@require_flax
class 			_snake_case		(     lowercase_						,						unittest.TestCase							):
			lowerCAmelCase_					:				Union[str, Any]							=   True

			lowerCAmelCase_					:				int							=   (
			    (
			        FlaxBertModel,
			        FlaxBertForPreTraining,
			        FlaxBertForMaskedLM,
			        FlaxBertForMultipleChoice,
			        FlaxBertForQuestionAnswering,
			        FlaxBertForNextSentencePrediction,
			        FlaxBertForSequenceClassification,
			        FlaxBertForTokenClassification,
			        FlaxBertForQuestionAnswering,
			    )
			    if is_flax_available()
			    else ()
			)




			def        lowerCAmelCase__    ( self							)    ->    str:

										'''simple docstring'''




										snake_case_      =				FlaxBertModelTester(self							)




			@slow
			def        lowerCAmelCase__    ( self							)    ->    int:

										'''simple docstring'''




										snake_case_      =				FlaxBertModel.from_pretrained("bert-base-cased"							)
										snake_case_      =				model(np.ones((1, 1)							)							)
										self.assertIsNotNone(a__							)










'''simple docstring'''





import argparse
from collections import defaultdict

import yaml


_SCREAMING_SNAKE_CASE							:       Optional[Any]						=			"docs/source/en/_toctree.yml"


def 					UpperCamelCase_(     snake_case							:	Optional[Any]					):

							'''simple docstring'''






							snake_case_      =				defaultdict(snake_case					)
							for doc in model_doc:
														counts[doc["local"]] += 1
							snake_case_      =				[key for key, value in counts.items() if value > 1]

							snake_case_      =				[]
							for duplicate_key in duplicates:
														snake_case_      =				list({doc["title"] for doc in model_doc if doc["local"] == duplicate_key}					)
														if len(snake_case					) > 1:
																					raise ValueError(
																					    f'{duplicate_key} is present several times in the documentation table of content at '
																					    "`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the "
																					    "others."					)
														# Only add this once
														new_doc.append({"local": duplicate_key, "title": titles[0]}					)

							# Add none duplicate-keys
							new_doc.extend([doc for doc in model_doc if counts[doc["local"]] == 1]					)

							# Sort
							return sorted(snake_case							,    key=lambda snake_case					: s["title"].lower()					)


def 					UpperCamelCase_(     snake_case							:	Optional[int]=False					):

							'''simple docstring'''






							with open(snake_case							,    encoding="utf-8"					) as f:
														snake_case_      =				yaml.safe_load(f.read()					)

							# Get to the API doc
							snake_case_      =				0
							while content[api_idx]["title"] != "API":
														api_idx += 1
							snake_case_      =				content[api_idx]["sections"]

							# Then to the model doc
							snake_case_      =				0
							while api_doc[model_idx]["title"] != "Models":
														model_idx += 1

							snake_case_      =				api_doc[model_idx]["sections"]

							snake_case_      =				[(idx, section) for idx, section in enumerate(snake_case					) if "sections" in section]
							snake_case_      =				False
							for idx, modality_doc in modalities_docs:
														snake_case_      =				modality_doc["sections"]
														snake_case_      =				clean_model_doc_toc(snake_case					)

														if old_modality_doc != new_modality_doc:
																					snake_case_      =				True
																					if overwrite:
																												snake_case_      =				new_modality_doc

							if diff:
														if overwrite:
																					snake_case_      =				model_doc
																					snake_case_      =				api_doc
																					with open(snake_case							,    "w"							,    encoding="utf-8"					) as f:
																												f.write(yaml.dump(snake_case							,    allow_unicode=snake_case					)					)
														else:
																					raise ValueError(
																					    "The model doc part of the table of content is not properly sorted, run `make style` to fix this."					)


if __name__ == "__main__":
		_SCREAMING_SNAKE_CASE							:       List[str]						=			argparse.ArgumentParser()
		parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.")
		_SCREAMING_SNAKE_CASE							:       Any						=			parser.parse_args()

		check_model_doc(args.fix_and_overwrite)




