




'''simple docstring'''


from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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.models.distilbert.modeling_tf_distilbert import (
				    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFDistilBertForMaskedLM,
				    TFDistilBertForMultipleChoice,
				    TFDistilBertForQuestionAnswering,
				    TFDistilBertForSequenceClassification,
				    TFDistilBertForTokenClassification,
				    TFDistilBertModel,
				)

class      A       :







							def __init__(    self			:    List[str]				,     lowerCAmelCase_			:    Any				,     )     ->				Tuple:


														"""simple docstring"""


														_a      	=							parent
														_a      	=							13
														_a      	=							7
														_a      	=							True
														_a      	=							True
														_a      	=							False
														_a      	=							True
														_a      	=							99
														_a      	=							32
														_a      	=							2
														_a      	=							4
														_a      	=							37
														_a      	=							'''gelu'''
														_a      	=							0.1
														_a      	=							0.1
														_a      	=							5_12
														_a      	=							16
														_a      	=							2
														_a      	=							0.0_2
														_a      	=							3
														_a      	=							4
														_a      	=							None







							def   __lowerCAmelCase     (    self			:    List[Any]   )     ->				str:


														"""simple docstring"""


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

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

														_a      	=							None
														_a      	=							None
														_a      	=							None
														if self.use_labels:
																					_a      	=							ids_tensor([self.batch_size]				,     self.type_sequence_label_size   )
																					_a      	=							ids_tensor([self.batch_size, self.seq_length]				,     self.num_labels   )
																					_a      	=							ids_tensor([self.batch_size]				,     self.num_choices   )

														_a      	=							DistilBertConfig(
														    vocab_size=self.vocab_size				,     dim=self.hidden_size				,     n_layers=self.num_hidden_layers				,     n_heads=self.num_attention_heads				,     hidden_dim=self.intermediate_size				,     hidden_act=self.hidden_act				,     dropout=self.hidden_dropout_prob				,     attention_dropout=self.attention_probs_dropout_prob				,     max_position_embeddings=self.max_position_embeddings				,     initializer_range=self.initializer_range				,     )

														return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







							def   __lowerCAmelCase     (    self			:    Optional[Any]				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Optional[Any]   )     ->				List[Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertModel(config=lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}

														_a      	=							model(lowerCAmelCase_   )

														_a      	=							[input_ids, input_mask]

														_a      	=							model(lowerCAmelCase_   )

														self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)   )







							def   __lowerCAmelCase     (    self			:    Dict				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Optional[int]   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertForMaskedLM(config=lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)   )







							def   __lowerCAmelCase     (    self			:    str				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Optional[Any]				,     lowerCAmelCase_			:    str   )     ->				List[Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertForQuestionAnswering(config=lowerCAmelCase_   )
														_a      	=							{
														    '''input_ids''': input_ids,
														    '''attention_mask''': input_mask,
														}
														_a      	=							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   __lowerCAmelCase     (    self			:    Any				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    Optional[Any]				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Union[str, Any]   )     ->				Optional[int]:


														"""simple docstring"""


														_a      	=							self.num_labels
														_a      	=							TFDistilBertForSequenceClassification(lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_labels)   )







							def   __lowerCAmelCase     (    self			:    Optional[Any]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    List[str]   )     ->				Dict:


														"""simple docstring"""


														_a      	=							self.num_choices
														_a      	=							TFDistilBertForMultipleChoice(lowerCAmelCase_   )
														_a      	=							tf.tile(tf.expand_dims(lowerCAmelCase_				,     1   )				,     (1, self.num_choices, 1)   )
														_a      	=							tf.tile(tf.expand_dims(lowerCAmelCase_				,     1   )				,     (1, self.num_choices, 1)   )
														_a      	=							{
														    '''input_ids''': multiple_choice_inputs_ids,
														    '''attention_mask''': multiple_choice_input_mask,
														}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices)   )







							def   __lowerCAmelCase     (    self			:    Dict				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    Optional[Any]   )     ->				Optional[Any]:


														"""simple docstring"""


														_a      	=							self.num_labels
														_a      	=							TFDistilBertForTokenClassification(lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.num_labels)   )







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


														"""simple docstring"""


														_a      	=							self.prepare_config_and_inputs()
														((_a)	,				(_a)	,				(_a)	,				(_a)	,				(_a)	,				(_a))      	=							config_and_inputs
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														return config, inputs_dict



@require_tf
class      A       (						_a	,_a	,unittest.TestCase       ):
							lowercase_							     =							(
							    (
							        TFDistilBertModel,
							        TFDistilBertForMaskedLM,
							        TFDistilBertForQuestionAnswering,
							        TFDistilBertForSequenceClassification,
							        TFDistilBertForTokenClassification,
							        TFDistilBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else None
							)
							lowercase_							     =							(
							    {
							        'feature-extraction': TFDistilBertModel,
							        'fill-mask': TFDistilBertForMaskedLM,
							        'question-answering': TFDistilBertForQuestionAnswering,
							        'text-classification': TFDistilBertForSequenceClassification,
							        'token-classification': TFDistilBertForTokenClassification,
							        'zero-shot': TFDistilBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							lowercase_							     =							False
							lowercase_							     =							False







							def   __lowerCAmelCase     (    self			:    List[str]   )     ->				Dict:


														"""simple docstring"""


														_a      	=							TFDistilBertModelTester(self   )
														_a      	=							ConfigTester(self				,     config_class=lowerCAmelCase_				,     dim=37   )







							def   __lowerCAmelCase     (    self			:    Any   )     ->				int:


														"""simple docstring"""


														self.config_tester.run_common_tests()







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				str:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_model(*lowerCAmelCase_   )







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


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_masked_lm(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				List[str]:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_question_answering(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Dict   )     ->				Any:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Optional[Any]   )     ->				str:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_token_classification(*lowerCAmelCase_   )







							@slow
							def   __lowerCAmelCase     (    self			:    str   )     ->				Optional[Any]:


														"""simple docstring"""


														for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]   ):
																					_a      	=							TFDistilBertModel.from_pretrained(lowerCAmelCase_   )
																					self.assertIsNotNone(lowerCAmelCase_   )



@require_tf
class      A       (						unittest.TestCase       ):







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


														"""simple docstring"""


														_a      	=							TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''   )
														_a      	=							tf.constant([[0, 1, 2, 3, 4, 5]]   )
														_a      	=							model(lowerCAmelCase_   )[0]

														_a      	=							[1, 6, 7_68]
														self.assertEqual(output.shape				,     lowerCAmelCase_   )

														_a      	=							tf.constant(
														    [
														        [
														            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
														            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
														            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
														        ]
														    ]   )
														tf.debugging.assert_near(output[:, :3, :3]				,     lowerCAmelCase_				,     atol=1e-4   )







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_snake_case : str  				=						{
    'configuration_layoutlmv3': [
        'LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'LayoutLMv3Config',
        'LayoutLMv3OnnxConfig',
    ],
    'processing_layoutlmv3': ['LayoutLMv3Processor'],
    'tokenization_layoutlmv3': ['LayoutLMv3Tokenizer'],
}

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case : List[str]  				=						['LayoutLMv3TokenizerFast']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case : Optional[int]  				=						[
				    'LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'LayoutLMv3ForQuestionAnswering',
				    'LayoutLMv3ForSequenceClassification',
				    'LayoutLMv3ForTokenClassification',
				    'LayoutLMv3Model',
				    'LayoutLMv3PreTrainedModel',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case : Tuple  				=						[
				    'TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'TFLayoutLMv3ForQuestionAnswering',
				    'TFLayoutLMv3ForSequenceClassification',
				    'TFLayoutLMv3ForTokenClassification',
				    'TFLayoutLMv3Model',
				    'TFLayoutLMv3PreTrainedModel',
				]

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case : List[Any]  				=						['LayoutLMv3FeatureExtractor']
				_snake_case : Tuple  				=						['LayoutLMv3ImageProcessor']


if TYPE_CHECKING:
				from .configuration_layoutlmva import (
				    LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    LayoutLMvaConfig,
				    LayoutLMvaOnnxConfig,
				)
				from .processing_layoutlmva import LayoutLMvaProcessor
				from .tokenization_layoutlmva import LayoutLMvaTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_layoutlmva import (
								    LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
								    LayoutLMvaForQuestionAnswering,
								    LayoutLMvaForSequenceClassification,
								    LayoutLMvaForTokenClassification,
								    LayoutLMvaModel,
								    LayoutLMvaPreTrainedModel,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_layoutlmva import (
								    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFLayoutLMvaForQuestionAnswering,
								    TFLayoutLMvaForSequenceClassification,
								    TFLayoutLMvaForTokenClassification,
								    TFLayoutLMvaModel,
								    TFLayoutLMvaPreTrainedModel,
								)

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor
								from .image_processing_layoutlmva import LayoutLMvaImageProcessor

else:
				import sys

				_snake_case : Any  				=						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

