


"""simple docstring"""
import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


SCREAMING_SNAKE_CASE__   =					logging.get_logger(__name__)

# General docstring
SCREAMING_SNAKE_CASE__   =					"PoolFormerConfig"

# Base docstring
SCREAMING_SNAKE_CASE__   =					"sail/poolformer_s12"
SCREAMING_SNAKE_CASE__   =					[1, 512, 7, 7]

# Image classification docstring
SCREAMING_SNAKE_CASE__   =					"sail/poolformer_s12"
SCREAMING_SNAKE_CASE__   =					"tabby, tabby cat"

SCREAMING_SNAKE_CASE__   =					[
    "sail/poolformer_s12",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]





def 				lowerCAmelCase__      (     _UpperCamelCase    :			Tuple	,     _UpperCamelCase    :			float = 0.0	,     _UpperCamelCase    :			bool = False   )   ->			Optional[Any]:





						"""simple docstring"""






						if drop_prob == 0.0 or not training:
												return input
						snake_case        =     1 - drop_prob
						snake_case        =     (input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
						snake_case        =     keep_prob + torch.rand(_UpperCamelCase	,     dtype=input.dtype	,     device=input.device   )
						random_tensor.floor_()  # binarize
						snake_case        =     input.div(_UpperCamelCase   ) * random_tensor
						return output



class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase = None      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     drop_prob

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										return drop_path(lowerCAmelCase						,      self.drop_prob						,      self.training      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										return "p={}".format(self.drop_prob      )





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase=None      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     patch_size if isinstance(lowerCAmelCase						,      collections.abc.Iterable      ) else (patch_size, patch_size)
										snake_case        =     stride if isinstance(lowerCAmelCase						,      collections.abc.Iterable      ) else (stride, stride)
										snake_case        =     padding if isinstance(lowerCAmelCase						,      collections.abc.Iterable      ) else (padding, padding)

										snake_case        =     nn.Convad(lowerCAmelCase						,      lowerCAmelCase						,      kernel_size=lowerCAmelCase						,      stride=lowerCAmelCase						,      padding=lowerCAmelCase      )
										snake_case        =     norm_layer(lowerCAmelCase      ) if norm_layer else nn.Identity()

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.projection(lowerCAmelCase      )
										snake_case        =     self.norm(lowerCAmelCase      )
										return embeddings





class 					lowerCAmelCase_      (     nn.GroupNorm   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase						,      **lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__(1						,      lowerCAmelCase						,      **lowerCAmelCase      )





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     nn.AvgPoolad(lowerCAmelCase						,      stride=1						,      padding=pool_size // 2						,      count_include_pad=lowerCAmelCase      )

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										return self.pool(lowerCAmelCase      ) - hidden_states





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     nn.Convad(lowerCAmelCase						,      lowerCAmelCase						,      1      )
										snake_case        =     nn.Convad(lowerCAmelCase						,      lowerCAmelCase						,      1      )
										snake_case        =     PoolFormerDropPath(lowerCAmelCase      )
										if isinstance(config.hidden_act						,      lowerCAmelCase      ):
																snake_case        =     ACTaFN[config.hidden_act]
										else:
																snake_case        =     config.hidden_act

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.conva(lowerCAmelCase      )
										snake_case        =     self.act_fn(lowerCAmelCase      )
										snake_case        =     self.drop(lowerCAmelCase      )
										snake_case        =     self.conva(lowerCAmelCase      )
										snake_case        =     self.drop(lowerCAmelCase      )

										return hidden_states





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     PoolFormerPooling(lowerCAmelCase      )
										snake_case        =     PoolFormerOutput(lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      )
										snake_case        =     PoolFormerGroupNorm(lowerCAmelCase      )
										snake_case        =     PoolFormerGroupNorm(lowerCAmelCase      )

										# Useful for training neural nets
										snake_case        =     PoolFormerDropPath(lowerCAmelCase      ) if drop_path > 0.0 else nn.Identity()
										snake_case        =     config.use_layer_scale
										if config.use_layer_scale:
																snake_case        =     nn.Parameter(
																    config.layer_scale_init_value * torch.ones((lowerCAmelCase)      )						,      requires_grad=lowerCAmelCase      )
																snake_case        =     nn.Parameter(
																    config.layer_scale_init_value * torch.ones((lowerCAmelCase)      )						,      requires_grad=lowerCAmelCase      )

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										if self.use_layer_scale:
																snake_case        =     self.pooling(self.before_norm(lowerCAmelCase      )      )
																snake_case        =     self.layer_scale_a.unsqueeze(-1      ).unsqueeze(-1      ) * pooling_output
																# First residual connection
																snake_case        =     hidden_states + self.drop_path(lowerCAmelCase      )
																snake_case        =     ()

																snake_case        =     self.output(self.after_norm(lowerCAmelCase      )      )
																snake_case        =     self.layer_scale_a.unsqueeze(-1      ).unsqueeze(-1      ) * layer_output
																# Second residual connection
																snake_case        =     hidden_states + self.drop_path(lowerCAmelCase      )

																snake_case        =     (output,) + outputs
																return outputs

										else:
																snake_case        =     self.drop_path(self.pooling(self.before_norm(lowerCAmelCase      )      )      )
																# First residual connection
																snake_case        =     pooling_output + hidden_states
																snake_case        =     ()

																# Second residual connection inside the PoolFormerOutput block
																snake_case        =     self.drop_path(self.output(self.after_norm(lowerCAmelCase      )      )      )
																snake_case        =     hidden_states + layer_output

																snake_case        =     (output,) + outputs
																return outputs





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     config
										# stochastic depth decay rule
										snake_case        =     [x.item() for x in torch.linspace(0						,      config.drop_path_rate						,      sum(config.depths      )      )]

										# patch embeddings
										snake_case        =     []
										for i in range(config.num_encoder_blocks      ):
																embeddings.append(
																    PoolFormerEmbeddings(
																        patch_size=config.patch_sizes[i]						,      stride=config.strides[i]						,      padding=config.padding[i]						,      num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]						,      hidden_size=config.hidden_sizes[i]						,      )      )
										snake_case        =     nn.ModuleList(lowerCAmelCase      )

										# Transformer blocks
										snake_case        =     []
										snake_case        =     0
										for i in range(config.num_encoder_blocks      ):
																# each block consists of layers
																snake_case        =     []
																if i != 0:
																						cur += config.depths[i - 1]
																for j in range(config.depths[i]      ):
																						layers.append(
																						    PoolFormerLayer(
																						        lowerCAmelCase						,      num_channels=config.hidden_sizes[i]						,      pool_size=config.pool_size						,      hidden_size=config.hidden_sizes[i]						,      intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio      )						,      drop_path=dpr[cur + j]						,      )      )
																blocks.append(nn.ModuleList(lowerCAmelCase      )      )

										snake_case        =     nn.ModuleList(lowerCAmelCase      )

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase=False						,      lowerCAmelCase=True      ):






										"""simple docstring"""

										snake_case        =     () if output_hidden_states else None

										snake_case        =     pixel_values
										for idx, layers in enumerate(zip(self.patch_embeddings						,      self.block      )      ):
																snake_case   ,snake_case        =     layers
																# Get patch embeddings from hidden_states
																snake_case        =     embedding_layer(lowerCAmelCase      )
																# Send the embeddings through the blocks
																for _, blk in enumerate(lowerCAmelCase      ):
																						snake_case        =     blk(lowerCAmelCase      )
																						snake_case        =     layer_outputs[0]

																if output_hidden_states:
																						snake_case        =     all_hidden_states + (hidden_states,)

										if not return_dict:
																return tuple(v for v in [hidden_states, all_hidden_states] if v is not None      )

										return BaseModelOutputWithNoAttention(last_hidden_state=lowerCAmelCase						,      hidden_states=lowerCAmelCase      )





class 					lowerCAmelCase_      (     lowerCAmelCase   ):



				"""simple docstring"""
				_lowerCAmelCase       :      str     					=  PoolFormerConfig
				_lowerCAmelCase       :      List[Any]     					=  """poolformer"""
				_lowerCAmelCase       :      Tuple     					=  """pixel_values"""
				_lowerCAmelCase       :      Any     					=  True

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										if isinstance(lowerCAmelCase						,      (nn.Linear, nn.Convad)      ):
																module.weight.data.normal_(mean=0.0						,      std=self.config.initializer_range      )
																if module.bias is not None:
																						module.bias.data.zero_()
										elif isinstance(lowerCAmelCase						,      nn.LayerNorm      ):
																module.bias.data.zero_()
																module.weight.data.fill_(1.0      )

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase=False      ):






										"""simple docstring"""

										if isinstance(lowerCAmelCase						,      lowerCAmelCase      ):
																snake_case        =     value





SCREAMING_SNAKE_CASE__   =					R"\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n"

SCREAMING_SNAKE_CASE__   =					R"\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`PoolFormerImageProcessor.__call__`] for details.\n"



@add_start_docstrings(
    """The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top."""       ,      lowerCAmelCase       ,      )
class 					lowerCAmelCase_      (     lowerCAmelCase   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__(lowerCAmelCase      )
										snake_case        =     config

										snake_case        =     PoolFormerEncoder(lowerCAmelCase      )

										# Initialize weights and apply final processing
										self.post_init()

				def 						snake_case	(			self      ):






										"""simple docstring"""

										return self.embeddings.patch_embeddings

				@add_start_docstrings_to_model_forward(lowerCAmelCase      )
				@add_code_sample_docstrings(
				    checkpoint=_CHECKPOINT_FOR_DOC						,      output_type=lowerCAmelCase						,      config_class=_CONFIG_FOR_DOC						,      modality='vision'						,      expected_output=_EXPECTED_OUTPUT_SHAPE						,      )
				def 						snake_case	(			self						,      lowerCAmelCase = None						,      lowerCAmelCase = None						,      lowerCAmelCase = None						,      ):






										"""simple docstring"""

										snake_case        =     (
										    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
										)
										snake_case        =     return_dict if return_dict is not None else self.config.use_return_dict

										if pixel_values is None:
																raise ValueError('You have to specify pixel_values'      )

										snake_case        =     self.encoder(
										    lowerCAmelCase						,      output_hidden_states=lowerCAmelCase						,      return_dict=lowerCAmelCase						,      )
										snake_case        =     encoder_outputs[0]

										if not return_dict:
																return (sequence_output, None) + encoder_outputs[1:]

										return BaseModelOutputWithNoAttention(
										    last_hidden_state=lowerCAmelCase						,      hidden_states=encoder_outputs.hidden_states						,      )





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__()
										snake_case        =     nn.Linear(config.hidden_size						,      config.hidden_size      )

				def 						snake_case	(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.dense(lowerCAmelCase      )
										return output





@add_start_docstrings(
    """
    PoolFormer Model transformer with an image classification head on top
    """       ,      lowerCAmelCase       ,      )
class 					lowerCAmelCase_      (     lowerCAmelCase   ):



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										super().__init__(lowerCAmelCase      )
										snake_case        =     config.num_labels
										snake_case        =     PoolFormerModel(lowerCAmelCase      )

										# Final norm
										snake_case        =     PoolFormerGroupNorm(config.hidden_sizes[-1]      )
										# Classifier head
										snake_case        =     (
										    nn.Linear(config.hidden_sizes[-1]						,      config.num_labels      ) if config.num_labels > 0 else nn.Identity()
										)

										# Initialize weights and apply final processing
										self.post_init()

				@add_start_docstrings_to_model_forward(lowerCAmelCase      )
				@add_code_sample_docstrings(
				    checkpoint=_IMAGE_CLASS_CHECKPOINT						,      output_type=lowerCAmelCase						,      config_class=_CONFIG_FOR_DOC						,      expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT						,      )
				def 						snake_case	(			self						,      lowerCAmelCase = None						,      lowerCAmelCase = None						,      lowerCAmelCase = None						,      lowerCAmelCase = None						,      ):






										"""simple docstring"""

										snake_case        =     return_dict if return_dict is not None else self.config.use_return_dict

										snake_case        =     self.poolformer(
										    lowerCAmelCase						,      output_hidden_states=lowerCAmelCase						,      return_dict=lowerCAmelCase						,      )

										snake_case        =     outputs[0]

										snake_case        =     self.classifier(self.norm(lowerCAmelCase      ).mean([-2, -1]      )      )

										snake_case        =     None
										if labels is not None:
																if self.config.problem_type is None:
																						if self.num_labels == 1:
																												snake_case        =     'regression'
																						elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																												snake_case        =     'single_label_classification'
																						else:
																												snake_case        =     'multi_label_classification'

																if self.config.problem_type == "regression":
																						snake_case        =     MSELoss()
																						if self.num_labels == 1:
																												snake_case        =     loss_fct(logits.squeeze()						,      labels.squeeze()      )
																						else:
																												snake_case        =     loss_fct(lowerCAmelCase						,      lowerCAmelCase      )
																elif self.config.problem_type == "single_label_classification":
																						snake_case        =     CrossEntropyLoss()
																						snake_case        =     loss_fct(logits.view(-1						,      self.num_labels      )						,      labels.view(-1      )      )
																elif self.config.problem_type == "multi_label_classification":
																						snake_case        =     BCEWithLogitsLoss()
																						snake_case        =     loss_fct(lowerCAmelCase						,      lowerCAmelCase      )

										if not return_dict:
																snake_case        =     (logits,) + outputs[2:]
																return ((loss,) + output) if loss is not None else output

										return ImageClassifierOutputWithNoAttention(loss=lowerCAmelCase						,      logits=lowerCAmelCase						,      hidden_states=outputs.hidden_states      )



"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 import (
					    TFDebertaVaForMaskedLM,
					    TFDebertaVaForQuestionAnswering,
					    TFDebertaVaForSequenceClassification,
					    TFDebertaVaForTokenClassification,
					    TFDebertaVaModel,
					)



class 					lowerCAmelCase_      :



				"""simple docstring"""

				def __init__(			self						,      lowerCAmelCase						,      lowerCAmelCase=13						,      lowerCAmelCase=7						,      lowerCAmelCase=True						,      lowerCAmelCase=True						,      lowerCAmelCase=True						,      lowerCAmelCase=True						,      lowerCAmelCase=99						,      lowerCAmelCase=32						,      lowerCAmelCase=2						,      lowerCAmelCase=4						,      lowerCAmelCase=37						,      lowerCAmelCase="gelu"						,      lowerCAmelCase=0.1						,      lowerCAmelCase=0.1						,      lowerCAmelCase=5_12						,      lowerCAmelCase=16						,      lowerCAmelCase=2						,      lowerCAmelCase=0.02						,      lowerCAmelCase=False						,      lowerCAmelCase=True						,      lowerCAmelCase="None"						,      lowerCAmelCase=3						,      lowerCAmelCase=4						,      lowerCAmelCase=None						,      ):






										"""simple docstring"""

										snake_case        =     parent
										snake_case        =     batch_size
										snake_case        =     seq_length
										snake_case        =     is_training
										snake_case        =     use_input_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_labels
										snake_case        =     num_choices
										snake_case        =     relative_attention
										snake_case        =     position_biased_input
										snake_case        =     pos_att_type
										snake_case        =     scope

				def 						snake_case	(			self      ):






										"""simple docstring"""

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

										snake_case        =     None
										if self.use_input_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        =     None
										snake_case        =     None
										snake_case        =     None
										if self.use_labels:
																snake_case        =     ids_tensor([self.batch_size]						,      self.type_sequence_label_size      )
																snake_case        =     ids_tensor([self.batch_size, self.seq_length]						,      self.num_labels      )

										snake_case        =     DebertaVaConfig(
										    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						,      relative_attention=self.relative_attention						,      position_biased_input=self.position_biased_input						,      initializer_range=self.initializer_range						,      return_dict=lowerCAmelCase						,      )

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

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaModel(config=lowerCAmelCase      )
										snake_case        =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

										snake_case        =     [input_ids, input_mask]
										snake_case        =     model(lowerCAmelCase      )

										snake_case        =     model(lowerCAmelCase      )

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

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaForMaskedLM(config=lowerCAmelCase      )
										snake_case        =     {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										snake_case        =     model(lowerCAmelCase      )
										self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.seq_length, self.vocab_size)      )

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.num_labels
										snake_case        =     TFDebertaVaForSequenceClassification(config=lowerCAmelCase      )
										snake_case        =     {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										snake_case        =     model(lowerCAmelCase      )
										self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.num_labels)      )

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.num_labels
										snake_case        =     TFDebertaVaForTokenClassification(config=lowerCAmelCase      )
										snake_case        =     {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										snake_case        =     model(lowerCAmelCase      )
										self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.seq_length, self.num_labels)      )

				def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaForQuestionAnswering(config=lowerCAmelCase      )
										snake_case        =     {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										snake_case        =     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 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.prepare_config_and_inputs()
										(
										    (
										    snake_case
										)   ,(
										    snake_case
										)   ,(
										    snake_case
										)   ,(
										    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': input_mask}
										return config, inputs_dict





@require_tf
class 					lowerCAmelCase_      (     lowerCAmelCase       ,      lowerCAmelCase       ,      unittest.TestCase   ):



				"""simple docstring"""
				_lowerCAmelCase       :      Optional[int]     					=  (
				    (
				        TFDebertaVaModel,
				        TFDebertaVaForMaskedLM,
				        TFDebertaVaForQuestionAnswering,
				        TFDebertaVaForSequenceClassification,
				        TFDebertaVaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				_lowerCAmelCase       :      Any     					=  (
				    {
				        """feature-extraction""": TFDebertaVaModel,
				        """fill-mask""": TFDebertaVaForMaskedLM,
				        """question-answering""": TFDebertaVaForQuestionAnswering,
				        """text-classification""": TFDebertaVaForSequenceClassification,
				        """token-classification""": TFDebertaVaForTokenClassification,
				        """zero-shot""": TFDebertaVaForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)

				_lowerCAmelCase       :      Optional[Any]     					=  False
				_lowerCAmelCase       :      List[Any]     					=  False

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaModelTester(self      )
										snake_case        =     ConfigTester(self						,      config_class=lowerCAmelCase						,      hidden_size=37      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										self.config_tester.run_common_tests()

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase      )

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase      )

				@slow
				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
										self.assertIsNotNone(lowerCAmelCase      )





@require_tf
class 					lowerCAmelCase_      (     unittest.TestCase   ):



				"""simple docstring"""

				@unittest.skip(reason='Model not available yet'      )
				def 						snake_case	(			self      ):






										"""simple docstring"""

										pass

				@slow
				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
										snake_case        =     tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]      )
										snake_case        =     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
										snake_case        =     model(lowerCAmelCase						,      attention_mask=lowerCAmelCase      )[0]

										snake_case        =     tf.constant(
										    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]      )
										tf.debugging.assert_near(output[:, 1:4, 1:4]						,      lowerCAmelCase						,      atol=1E-4      )


