



'''simple docstring'''



from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import (
							    TFFunnelBaseModel,
							    TFFunnelForMaskedLM,
							    TFFunnelForMultipleChoice,
							    TFFunnelForPreTraining,
							    TFFunnelForQuestionAnswering,
							    TFFunnelForSequenceClassification,
							    TFFunnelForTokenClassification,
							    TFFunnelModel,
							)
class 						lowerCamelCase_				:







						def __init__(	self :   Union[str, Any]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   List[Any]=13					,     lowerCAmelCase__ :   Dict=7					,     lowerCAmelCase__ :   int=True					,     lowerCAmelCase__ :   List[str]=True					,     lowerCAmelCase__ :   Tuple=True					,     lowerCAmelCase__ :   Dict=True					,     lowerCAmelCase__ :   Dict=99					,     lowerCAmelCase__ :   Dict=[1, 1, 2]					,     lowerCAmelCase__ :   Tuple=1					,     lowerCAmelCase__ :   Union[str, Any]=32					,     lowerCAmelCase__ :   Dict=4					,     lowerCAmelCase__ :   int=8					,     lowerCAmelCase__ :   Dict=37					,     lowerCAmelCase__ :   Tuple="gelu_new"					,     lowerCAmelCase__ :   Dict=0.1					,     lowerCAmelCase__ :   Optional[Any]=0.1					,     lowerCAmelCase__ :   List[Any]=0.0					,     lowerCAmelCase__ :   int=5_12					,     lowerCAmelCase__ :   Optional[int]=3					,     lowerCAmelCase__ :   int=0.02					,     lowerCAmelCase__ :   int=3					,     lowerCAmelCase__ :   Optional[int]=4					,     lowerCAmelCase__ :   Dict=None					,     lowerCAmelCase__ :   Tuple=False					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      parent
													SCREAMING_SNAKE_CASE       :   str         =      batch_size
													SCREAMING_SNAKE_CASE       :   List[Any]         =      seq_length
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      is_training
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      use_input_mask
													SCREAMING_SNAKE_CASE       :   str         =      use_token_type_ids
													SCREAMING_SNAKE_CASE       :   Any         =      use_labels
													SCREAMING_SNAKE_CASE       :   Any         =      vocab_size
													SCREAMING_SNAKE_CASE       :   Any         =      block_sizes
													SCREAMING_SNAKE_CASE       :   List[Any]         =      num_decoder_layers
													SCREAMING_SNAKE_CASE       :   int         =      d_model
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      n_head
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      d_head
													SCREAMING_SNAKE_CASE       :   Dict         =      d_inner
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      hidden_act
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      hidden_dropout
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      attention_dropout
													SCREAMING_SNAKE_CASE       :   Dict         =      activation_dropout
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      max_position_embeddings
													SCREAMING_SNAKE_CASE       :   int         =      type_vocab_size
													SCREAMING_SNAKE_CASE       :   str         =      2
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      num_labels
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      num_choices
													SCREAMING_SNAKE_CASE       :   Dict         =      scope
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      initializer_std

													# Used in the tests to check the size of the first attention layer
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      n_head
													# Used in the tests to check the size of the first hidden state
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      self.d_model
													# Used in the tests to check the number of output hidden states/attentions
													SCREAMING_SNAKE_CASE       :   List[str]         =      sum(self.block_sizes					) + (0 if base else self.num_decoder_layers)
													# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
													# the last hidden state of the first block (which is the first hidden state of the decoder).
													if not base:
																				SCREAMING_SNAKE_CASE       :   Dict         =      self.num_hidden_layers + 2







						def        __lowercase     (	self :   Optional[int]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size					)

													SCREAMING_SNAKE_CASE       :   Any         =      None
													if self.use_input_mask:
																				SCREAMING_SNAKE_CASE       :   Any         =      random_attention_mask([self.batch_size, self.seq_length]					)

													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      None
													if self.use_token_type_ids:
																				SCREAMING_SNAKE_CASE       :   Dict         =      ids_tensor([self.batch_size, self.seq_length]					,     self.type_vocab_size					)

													SCREAMING_SNAKE_CASE       :   List[Any]         =      None
													SCREAMING_SNAKE_CASE       :   Dict         =      None
													SCREAMING_SNAKE_CASE       :   Tuple         =      None
													if self.use_labels:
																				SCREAMING_SNAKE_CASE       :   Optional[int]         =      ids_tensor([self.batch_size]					,     self.type_sequence_label_size					)
																				SCREAMING_SNAKE_CASE       :   Dict         =      ids_tensor([self.batch_size, self.seq_length]					,     self.num_labels					)
																				SCREAMING_SNAKE_CASE       :   List[Any]         =      ids_tensor([self.batch_size]					,     self.num_choices					)

													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      FunnelConfig(
													    vocab_size=self.vocab_size					,     block_sizes=self.block_sizes					,     num_decoder_layers=self.num_decoder_layers					,     d_model=self.d_model					,     n_head=self.n_head					,     d_head=self.d_head					,     d_inner=self.d_inner					,     hidden_act=self.hidden_act					,     hidden_dropout=self.hidden_dropout					,     attention_dropout=self.attention_dropout					,     activation_dropout=self.activation_dropout					,     max_position_embeddings=self.max_position_embeddings					,     type_vocab_size=self.type_vocab_size					,     initializer_std=self.initializer_std					,     )

													return (
													    config,
													    input_ids,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													)







						def        __lowercase     (	self :   Optional[int]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Union[str, Any]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      TFFunnelModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   Any         =      model(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   int         =      [input_ids, input_mask]
													SCREAMING_SNAKE_CASE       :   Any         =      model(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.d_model)					)

													SCREAMING_SNAKE_CASE       :   List[Any]         =      False
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      TFFunnelModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.d_model)					)

													SCREAMING_SNAKE_CASE       :   Dict         =      False
													SCREAMING_SNAKE_CASE       :   int         =      TFFunnelModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   List[Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.d_model)					)







						def        __lowercase     (	self :   Optional[int]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Tuple					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      TFFunnelBaseModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Tuple         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      model(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      [input_ids, input_mask]
													SCREAMING_SNAKE_CASE       :   List[Any]         =      model(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   List[Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, 2, self.d_model)					)

													SCREAMING_SNAKE_CASE       :   int         =      False
													SCREAMING_SNAKE_CASE       :   int         =      TFFunnelBaseModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, 3, self.d_model)					)

													SCREAMING_SNAKE_CASE       :   Optional[int]         =      False
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      TFFunnelBaseModel(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   List[str]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, 2, self.d_model)					)







						def        __lowercase     (	self :   List[Any]					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   List[str]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      TFFunnelForPreTraining(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   str         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   Tuple         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length)					)







						def        __lowercase     (	self :   Optional[Any]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   List[Any]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      TFFunnelForMaskedLM(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   List[str]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.vocab_size)					)







						def        __lowercase     (	self :   List[str]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   List[str]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      self.num_labels
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      TFFunnelForSequenceClassification(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Any         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   str         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.num_labels)					)







						def        __lowercase     (	self :   Optional[int]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   List[str]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      self.num_choices
													SCREAMING_SNAKE_CASE       :   Dict         =      TFFunnelForMultipleChoice(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      tf.tile(tf.expand_dims(lowerCAmelCase__					,     1					)					,     (1, self.num_choices, 1)					)
													SCREAMING_SNAKE_CASE       :   Dict         =      tf.tile(tf.expand_dims(lowerCAmelCase__					,     1					)					,     (1, self.num_choices, 1)					)
													SCREAMING_SNAKE_CASE       :   List[Any]         =      tf.tile(tf.expand_dims(lowerCAmelCase__					,     1					)					,     (1, self.num_choices, 1)					)
													SCREAMING_SNAKE_CASE       :   int         =      {
													    '''input_ids''': multiple_choice_inputs_ids,
													    '''attention_mask''': multiple_choice_input_mask,
													    '''token_type_ids''': multiple_choice_token_type_ids,
													}
													SCREAMING_SNAKE_CASE       :   List[Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.num_choices)					)







						def        __lowercase     (	self :   Dict					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Optional[int]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Tuple         =      self.num_labels
													SCREAMING_SNAKE_CASE       :   Tuple         =      TFFunnelForTokenClassification(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   int         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   Dict         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.num_labels)					)







						def        __lowercase     (	self :   int					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   str					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      TFFunnelForQuestionAnswering(config=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													SCREAMING_SNAKE_CASE       :   List[str]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.start_logits.shape					,     (self.batch_size, self.seq_length)					)
													self.parent.assertEqual(result.end_logits.shape					,     (self.batch_size, self.seq_length)					)







						def        __lowercase     (	self :   Tuple					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      self.prepare_config_and_inputs()
													(
													    (
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,(
													    SCREAMING_SNAKE_CASE
													)       ,
													)       :   List[Any]         =      config_and_inputs
													SCREAMING_SNAKE_CASE       :   int         =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
													return config, inputs_dict


@require_tf
class 						lowerCamelCase_				(       snake_case_     ,					snake_case_     ,					unittest.TestCase      ):
						_lowerCAmelCase  : str						  =					(
						    (
						        TFFunnelModel,
						        TFFunnelForMaskedLM,
						        TFFunnelForPreTraining,
						        TFFunnelForQuestionAnswering,
						        TFFunnelForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_lowerCAmelCase  : int						  =					(
						    {
						        'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
						        'fill-mask': TFFunnelForMaskedLM,
						        'question-answering': TFFunnelForQuestionAnswering,
						        'text-classification': TFFunnelForSequenceClassification,
						        'token-classification': TFFunnelForTokenClassification,
						        'zero-shot': TFFunnelForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						_lowerCAmelCase  : int						  =					False
						_lowerCAmelCase  : Optional[int]						  =					False







						def        __lowercase     (	self :   Optional[int]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      TFFunnelModelTester(self					)
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      ConfigTester(self					,     config_class=lowerCAmelCase__					)







						def        __lowercase     (	self :   List[Any]					):

													"""simple docstring"""
													self.config_tester.run_common_tests()







						def        __lowercase     (	self :   List[Any]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[Any]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_pretraining(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[Any]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[Any]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__					)







						def        __lowercase     (	self :   Any					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__					)


@require_tf
class 						lowerCamelCase_				(       snake_case_     ,					unittest.TestCase      ):
						_lowerCAmelCase  : Optional[int]						  =					(
						    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
						)
						_lowerCAmelCase  : Any						  =					False
						_lowerCAmelCase  : int						  =					False







						def        __lowercase     (	self :   List[str]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Tuple         =      TFFunnelModelTester(self					,     base=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      ConfigTester(self					,     config_class=lowerCAmelCase__					)







						def        __lowercase     (	self :   Any					):

													"""simple docstring"""
													self.config_tester.run_common_tests()







						def        __lowercase     (	self :   str					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_base_model(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[str]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Any         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[str]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__					)









'''simple docstring'''



import argparse
from collections import defaultdict

import yaml


lowerCAmelCase_  :							Tuple             =    'docs/source/en/_toctree.yml'
def        UpperCAmelCase (    A	:					Union[str, Any]					):
							SCREAMING_SNAKE_CASE       :   Dict         =      defaultdict(A					)
							for doc in model_doc:
														counts[doc["local"]] += 1
							SCREAMING_SNAKE_CASE       :   Tuple         =      [key for key, value in counts.items() if value > 1]

							SCREAMING_SNAKE_CASE       :   Tuple         =      []
							for duplicate_key in duplicates:
														SCREAMING_SNAKE_CASE       :   Optional[int]         =      list({doc['''title'''] for doc in model_doc if doc['''local'''] == duplicate_key}					)
														if len(A					) > 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(A       ,		key=lambda A					: s["title"].lower()					)
def        UpperCAmelCase (    A	:					Any=False					):
							with open(A       ,		encoding='''utf-8'''					) as f:
														SCREAMING_SNAKE_CASE       :   str         =      yaml.safe_load(f.read()					)

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

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

							SCREAMING_SNAKE_CASE       :   Dict         =      api_doc[model_idx]['''sections''']

							SCREAMING_SNAKE_CASE       :   List[Any]         =      [(idx, section) for idx, section in enumerate(A					) if '''sections''' in section]
							SCREAMING_SNAKE_CASE       :   int         =      False
							for idx, modality_doc in modalities_docs:
														SCREAMING_SNAKE_CASE       :   List[str]         =      modality_doc['''sections''']
														SCREAMING_SNAKE_CASE       :   List[str]         =      clean_model_doc_toc(A					)

														if old_modality_doc != new_modality_doc:
																					SCREAMING_SNAKE_CASE       :   Dict         =      True
																					if overwrite:
																												SCREAMING_SNAKE_CASE       :   int         =      new_modality_doc

							if diff:
														if overwrite:
																					SCREAMING_SNAKE_CASE       :   List[Any]         =      model_doc
																					SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      api_doc
																					with open(A       ,		'''w'''       ,		encoding='''utf-8'''					) as f:
																												f.write(yaml.dump(A       ,		allow_unicode=A					)					)
														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__":
							lowerCAmelCase_  :							Optional[int]             =    argparse.ArgumentParser()
							parser.add_argument('--fix_and_overwrite', action='store_true', help='Whether to fix inconsistencies.')
							lowerCAmelCase_  :							Any             =    parser.parse_args()

							check_model_doc(args.fix_and_overwrite)




