


import enum
import inspect
from typing import Iterable, List, Optional, Tuple, Union





class       _a							(       enum.Enum):
	_a						:						List[str]   					=							'''timm'''
	_a						:						Optional[Any]   					=							'''transformers'''






def   lowerCamelCase_					( _a			,     _a			,     _a ):




		"""simple docstring"""






		if stage_names is None:
				raise ValueError('''Stage_names must be set for transformers backbones''' )

		if out_features is not None:
				if not isinstance(_a			,     (list,) ):
						raise ValueError(f'out_features must be a list {type(_a )}' )
				if any(feat not in stage_names for feat in out_features ):
						raise ValueError(f'out_features must be a subset of stage_names: {stage_names} got {out_features}' )

		if out_indices is not None:
				if not isinstance(_a			,     (list, tuple) ):
						raise ValueError(f'out_indices must be a list or tuple, got {type(_a )}' )
				if any(idx >= len(_a ) for idx in out_indices ):
						raise ValueError('''out_indices must be valid indices for stage_names {stage_names}, got {out_indices}''' )

		if out_features is not None and out_indices is not None:
				if len(_a ) != len(_a ):
						raise ValueError('''out_features and out_indices should have the same length if both are set''' )
				if out_features != [stage_names[idx] for idx in out_indices]:
						raise ValueError('''out_features and out_indices should correspond to the same stages if both are set''' )






def   lowerCamelCase_					( _a			,     _a			,     _a			,     ):




		"""simple docstring"""






		if out_indices is None and out_features is None:
				lowerCAmelCase__     :    int					  =      [len(_a ) - 1]
				lowerCAmelCase__     :    int					  =      [stage_names[-1]]
		elif out_indices is None and out_features is not None:
				lowerCAmelCase__     :    int					  =      [stage_names.index(_a ) for layer in out_features]
		elif out_features is None and out_indices is not None:
				lowerCAmelCase__     :    Union[str, Any]					  =      [stage_names[idx] for idx in out_indices]
		return out_features, out_indices






def   lowerCamelCase_					( _a			,     _a			,     _a			,     ):




		"""simple docstring"""






		verify_out_features_out_indices(out_features=_a			,     out_indices=_a			,     stage_names=_a )
		lowerCAmelCase__  ,			lowerCAmelCase__     :    int					  =      _align_output_features_output_indices(
		    out_features=_a			,     out_indices=_a			,     stage_names=_a )
		# Verify that the aligned out_features and out_indices are valid
		verify_out_features_out_indices(out_features=_a			,     out_indices=_a			,     stage_names=_a )
		return output_features, output_indices





class       _a							:
	_a						:						Optional[BackboneType]   					=							None




	def 							UpperCAmelCase__(      self		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]	)-> None:
			if getattr(self	,      '''_backbone'''	,      _SCREAMING_SNAKE_CASE	) is None:
					raise ValueError('''self._backbone must be set before calling _init_timm_backbone'''	)

			# These will diagree with the defaults for the transformers models e.g. for resnet50
			# the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
			# the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']
			lowerCAmelCase__     :    Optional[int]					  =      [stage['''module'''] for stage in self._backbone.feature_info.info]
			lowerCAmelCase__     :    Optional[Any]					  =      [stage['''num_chs'''] for stage in self._backbone.feature_info.info]
			lowerCAmelCase__     :    int					  =      self._backbone.feature_info.out_indices
			lowerCAmelCase__     :    Optional[int]					  =      self._backbone.feature_info.module_name()

			# We verify the out indices and out features are valid
			verify_out_features_out_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=self.stage_names	)
			lowerCAmelCase__  ,			lowerCAmelCase__     :    Optional[Any]					  =      out_features, out_indices




	def 							UpperCAmelCase__(      self		:	Dict	,      _SCREAMING_SNAKE_CASE		:	List[Any]	)-> None:
			lowerCAmelCase__     :    Tuple					  =      getattr(_SCREAMING_SNAKE_CASE	,      '''stage_names'''	)
			lowerCAmelCase__     :    Any					  =      getattr(_SCREAMING_SNAKE_CASE	,      '''out_features'''	,      _SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    List[Any]					  =      getattr(_SCREAMING_SNAKE_CASE	,      '''out_indices'''	,      _SCREAMING_SNAKE_CASE	)

			lowerCAmelCase__     :    Optional[int]					  =      stage_names
			lowerCAmelCase__  ,			lowerCAmelCase__     :    Optional[int]					  =      get_aligned_output_features_output_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=_SCREAMING_SNAKE_CASE	)
			# Number of channels for each stage. This is set in the transformer backbone model init
			lowerCAmelCase__     :    Optional[int]					  =      None




	def 							UpperCAmelCase__(      self		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	Dict	)-> None:
			lowerCAmelCase__     :    int					  =      config

			lowerCAmelCase__     :    List[str]					  =      getattr(_SCREAMING_SNAKE_CASE	,      '''use_timm_backbone'''	,      _SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Any					  =      BackboneType.TIMM if self.use_timm_backbone else BackboneType.TRANSFORMERS

			if self.backbone_type == BackboneType.TIMM:
					self._init_timm_backbone(_SCREAMING_SNAKE_CASE	)
			elif self.backbone_type == BackboneType.TRANSFORMERS:
					self._init_transformers_backbone(_SCREAMING_SNAKE_CASE	)
			else:
					raise ValueError(F'backbone_type {self.backbone_type} not supported.'	)




	@property
	def 							UpperCAmelCase__(      self		:	Union[str, Any]	)-> str:
			return self._out_features




	@out_features.setter
	def 							UpperCAmelCase__(      self		:	str	,      _SCREAMING_SNAKE_CASE		:	List[str]	)-> Tuple:
			lowerCAmelCase__  ,			lowerCAmelCase__     :    str					  =      get_aligned_output_features_output_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=self.stage_names	)




	@property
	def 							UpperCAmelCase__(      self		:	List[str]	)-> Optional[Any]:
			return self._out_indices




	@out_indices.setter
	def 							UpperCAmelCase__(      self		:	int	,      _SCREAMING_SNAKE_CASE		:	Union[Tuple[int], List[int]]	)-> Tuple:
			lowerCAmelCase__  ,			lowerCAmelCase__     :    str					  =      get_aligned_output_features_output_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=self.stage_names	)




	@property
	def 							UpperCAmelCase__(      self		:	str	)-> Union[str, Any]:
			# the current backbones will output the number of channels for each stage
			# even if that stage is not in the out_features list.
			return {stage: self.num_features[i] for i, stage in enumerate(self.stage_names	)}




	@property
	def 							UpperCAmelCase__(      self		:	List[str]	)-> Optional[Any]:
			return [self.out_feature_channels[name] for name in self.out_features]




	def 							UpperCAmelCase__(      self		:	Tuple	,      *_SCREAMING_SNAKE_CASE		:	Optional[Any]	,      **_SCREAMING_SNAKE_CASE		:	Tuple	)-> int:
			lowerCAmelCase__     :    int					  =      dict(inspect.signature(self.forward	).parameters	)
			lowerCAmelCase__     :    int					  =      {k: v for k, v in kwargs.items() if k in signature}
			return self(*_SCREAMING_SNAKE_CASE	,      **_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	Optional[bool] = None	,      _SCREAMING_SNAKE_CASE		:	Optional[bool] = None	,      _SCREAMING_SNAKE_CASE		:	Optional[bool] = None	,      )-> int:
			raise NotImplementedError('''This method should be implemented by the derived class.'''	)




	def 							UpperCAmelCase__(      self		:	Dict	)-> Dict:
			lowerCAmelCase__     :    Optional[Any]					  =      super().to_dict()
			lowerCAmelCase__     :    Optional[int]					  =      output.pop('''_out_features'''	)
			lowerCAmelCase__     :    Any					  =      output.pop('''_out_indices'''	)
			return output





class       _a							:




	@property
	def 							UpperCAmelCase__(      self		:	List[str]	)-> str:
			return self._out_features




	@out_features.setter
	def 							UpperCAmelCase__(      self		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	List[str]	)-> List[Any]:
			lowerCAmelCase__  ,			lowerCAmelCase__     :    Optional[Any]					  =      get_aligned_output_features_output_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=self.stage_names	)




	@property
	def 							UpperCAmelCase__(      self		:	List[Any]	)-> Tuple:
			return self._out_indices




	@out_indices.setter
	def 							UpperCAmelCase__(      self		:	int	,      _SCREAMING_SNAKE_CASE		:	Union[Tuple[int], List[int]]	)-> List[str]:
			lowerCAmelCase__  ,			lowerCAmelCase__     :    Optional[Any]					  =      get_aligned_output_features_output_indices(
			    out_features=_SCREAMING_SNAKE_CASE	,      out_indices=_SCREAMING_SNAKE_CASE	,      stage_names=self.stage_names	)




	def 							UpperCAmelCase__(      self		:	int	)-> Optional[int]:
			lowerCAmelCase__     :    Optional[Any]					  =      super().to_dict()
			lowerCAmelCase__     :    List[str]					  =      output.pop('''_out_features'''	)
			lowerCAmelCase__     :    Any					  =      output.pop('''_out_indices'''	)
			return output








from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
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 TF_MODEL_FOR_PRETRAINING_MAPPING
		from transformers.models.albert.modeling_tf_albert import (
		    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFAlbertForMaskedLM,
		    TFAlbertForMultipleChoice,
		    TFAlbertForPreTraining,
		    TFAlbertForQuestionAnswering,
		    TFAlbertForSequenceClassification,
		    TFAlbertForTokenClassification,
		    TFAlbertModel,
		)





class       _a							:




	def __init__(      self		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	Tuple=13	,      _SCREAMING_SNAKE_CASE		:	Dict=7	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=True	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=True	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=True	,      _SCREAMING_SNAKE_CASE		:	int=True	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=99	,      _SCREAMING_SNAKE_CASE		:	int=16	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=32	,      _SCREAMING_SNAKE_CASE		:	Tuple=2	,      _SCREAMING_SNAKE_CASE		:	int=4	,      _SCREAMING_SNAKE_CASE		:	List[str]=37	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]="gelu"	,      _SCREAMING_SNAKE_CASE		:	List[Any]=0.1	,      _SCREAMING_SNAKE_CASE		:	List[Any]=0.1	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=512	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=16	,      _SCREAMING_SNAKE_CASE		:	str=2	,      _SCREAMING_SNAKE_CASE		:	Optional[int]=0.02	,      _SCREAMING_SNAKE_CASE		:	Any=3	,      _SCREAMING_SNAKE_CASE		:	Dict=4	,      _SCREAMING_SNAKE_CASE		:	int=None	,      )-> str:
			lowerCAmelCase__     :    Any					  =      parent
			lowerCAmelCase__     :    List[Any]					  =      13
			lowerCAmelCase__     :    int					  =      7
			lowerCAmelCase__     :    Optional[int]					  =      True
			lowerCAmelCase__     :    Optional[Any]					  =      True
			lowerCAmelCase__     :    List[str]					  =      True
			lowerCAmelCase__     :    Optional[Any]					  =      True
			lowerCAmelCase__     :    Tuple					  =      99
			lowerCAmelCase__     :    Optional[Any]					  =      16
			lowerCAmelCase__     :    str					  =      32
			lowerCAmelCase__     :    List[str]					  =      2
			lowerCAmelCase__     :    List[str]					  =      4
			lowerCAmelCase__     :    Union[str, Any]					  =      37
			lowerCAmelCase__     :    Tuple					  =      '''gelu'''
			lowerCAmelCase__     :    Any					  =      0.1
			lowerCAmelCase__     :    Optional[Any]					  =      0.1
			lowerCAmelCase__     :    Tuple					  =      512
			lowerCAmelCase__     :    int					  =      16
			lowerCAmelCase__     :    Tuple					  =      2
			lowerCAmelCase__     :    List[str]					  =      0.02
			lowerCAmelCase__     :    Tuple					  =      3
			lowerCAmelCase__     :    str					  =      4
			lowerCAmelCase__     :    Union[str, Any]					  =      None




	def 							UpperCAmelCase__(      self		:	List[str]	)-> Any:
			lowerCAmelCase__     :    str					  =      ids_tensor([self.batch_size, self.seq_length]	,      self.vocab_size	)

			lowerCAmelCase__     :    str					  =      None
			if self.use_input_mask:
					lowerCAmelCase__     :    Optional[int]					  =      random_attention_mask([self.batch_size, self.seq_length]	)

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

			lowerCAmelCase__     :    str					  =      None
			lowerCAmelCase__     :    Union[str, Any]					  =      None
			lowerCAmelCase__     :    Optional[Any]					  =      None
			if self.use_labels:
					lowerCAmelCase__     :    Union[str, Any]					  =      ids_tensor([self.batch_size]	,      self.type_sequence_label_size	)
					lowerCAmelCase__     :    str					  =      ids_tensor([self.batch_size, self.seq_length]	,      self.num_labels	)
					lowerCAmelCase__     :    str					  =      ids_tensor([self.batch_size]	,      self.num_choices	)

			lowerCAmelCase__     :    List[Any]					  =      AlbertConfig(
			    vocab_size=self.vocab_size	,      hidden_size=self.hidden_size	,      embedding_size=self.embedding_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	,      initializer_range=self.initializer_range	,      )

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




	def 							UpperCAmelCase__(      self		:	int	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]	,      _SCREAMING_SNAKE_CASE		:	str	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]	,      _SCREAMING_SNAKE_CASE		:	Any	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	List[Any]	)-> List[Any]:
			lowerCAmelCase__     :    int					  =      TFAlbertModel(config=_SCREAMING_SNAKE_CASE	)
			# inputs = {'input_ids': input_ids,
			#           'attention_mask': input_mask,
			#           'token_type_ids': token_type_ids}
			# sequence_output, pooled_output = model(**inputs)
			lowerCAmelCase__     :    str					  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
			lowerCAmelCase__     :    Any					  =      model(_SCREAMING_SNAKE_CASE	)

			lowerCAmelCase__     :    str					  =      [input_ids, input_mask]
			lowerCAmelCase__     :    Optional[Any]					  =      model(_SCREAMING_SNAKE_CASE	)

			lowerCAmelCase__     :    str					  =      model(_SCREAMING_SNAKE_CASE	)

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




	def 							UpperCAmelCase__(      self		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	Dict	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	Tuple	)-> Optional[Any]:
			lowerCAmelCase__     :    Any					  =      self.num_labels
			lowerCAmelCase__     :    Dict					  =      TFAlbertForPreTraining(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Tuple					  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
			lowerCAmelCase__     :    Any					  =      model(_SCREAMING_SNAKE_CASE	)
			self.parent.assertEqual(result.prediction_logits.shape	,      (self.batch_size, self.seq_length, self.vocab_size)	)
			self.parent.assertEqual(result.sop_logits.shape	,      (self.batch_size, self.num_labels)	)




	def 							UpperCAmelCase__(      self		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	Any	,      _SCREAMING_SNAKE_CASE		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	Any	)-> Optional[int]:
			lowerCAmelCase__     :    Any					  =      TFAlbertForMaskedLM(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Any					  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
			lowerCAmelCase__     :    Dict					  =      model(_SCREAMING_SNAKE_CASE	)
			self.parent.assertEqual(result.logits.shape	,      (self.batch_size, self.seq_length, self.vocab_size)	)




	def 							UpperCAmelCase__(      self		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Any	,      _SCREAMING_SNAKE_CASE		:	str	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	Any	)-> List[str]:
			lowerCAmelCase__     :    Union[str, Any]					  =      self.num_labels
			lowerCAmelCase__     :    List[str]					  =      TFAlbertForSequenceClassification(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    str					  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
			lowerCAmelCase__     :    int					  =      model(_SCREAMING_SNAKE_CASE	)
			self.parent.assertEqual(result.logits.shape	,      (self.batch_size, self.num_labels)	)




	def 							UpperCAmelCase__(      self		:	Dict	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	str	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	)-> int:
			lowerCAmelCase__     :    List[str]					  =      TFAlbertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    List[str]					  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
			lowerCAmelCase__     :    Optional[Any]					  =      model(_SCREAMING_SNAKE_CASE	)
			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 							UpperCAmelCase__(      self		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	str	,      _SCREAMING_SNAKE_CASE		:	Any	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]	,      _SCREAMING_SNAKE_CASE		:	int	)-> str:
			lowerCAmelCase__     :    str					  =      self.num_choices
			lowerCAmelCase__     :    Tuple					  =      TFAlbertForMultipleChoice(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Union[str, Any]					  =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE	,      1	)	,      (1, self.num_choices, 1)	)
			lowerCAmelCase__     :    Dict					  =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE	,      1	)	,      (1, self.num_choices, 1)	)
			lowerCAmelCase__     :    Tuple					  =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE	,      1	)	,      (1, self.num_choices, 1)	)
			lowerCAmelCase__     :    Tuple					  =      {
			    '''input_ids''': multiple_choice_inputs_ids,
			    '''attention_mask''': multiple_choice_input_mask,
			    '''token_type_ids''': multiple_choice_token_type_ids,
			}
			lowerCAmelCase__     :    Optional[Any]					  =      model(_SCREAMING_SNAKE_CASE	)
			self.parent.assertListEqual(list(result['''logits'''].shape	)	,      [self.batch_size, self.num_choices]	)




	def 							UpperCAmelCase__(      self		:	List[Any]	,      _SCREAMING_SNAKE_CASE		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	Optional[int]	,      _SCREAMING_SNAKE_CASE		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]	,      _SCREAMING_SNAKE_CASE		:	int	,      _SCREAMING_SNAKE_CASE		:	List[str]	)-> Tuple:
			lowerCAmelCase__     :    Union[str, Any]					  =      self.num_labels
			lowerCAmelCase__     :    Optional[int]					  =      TFAlbertForTokenClassification(config=_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Any					  =      {
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			    '''token_type_ids''': token_type_ids,
			}
			lowerCAmelCase__     :    Optional[Any]					  =      model(_SCREAMING_SNAKE_CASE	)
			self.parent.assertListEqual(list(result['''logits'''].shape	)	,      [self.batch_size, self.seq_length, self.num_labels]	)




	def 							UpperCAmelCase__(      self		:	Union[str, Any]	)-> Dict:
			lowerCAmelCase__     :    int					  =      self.prepare_config_and_inputs()
			(
			    (
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			(
			    lowerCAmelCase__
			)  ,			
			)     :    Union[str, Any]					  =      config_and_inputs
			lowerCAmelCase__     :    Tuple					  =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
			return config, inputs_dict





@require_tf
class       _a							(       _lowercase  ,		_lowercase  ,		unittest.TestCase):
	_a						:						Tuple   					=							(
	    (
	        TFAlbertModel,
	        TFAlbertForPreTraining,
	        TFAlbertForMaskedLM,
	        TFAlbertForSequenceClassification,
	        TFAlbertForQuestionAnswering,
	        TFAlbertForTokenClassification,
	        TFAlbertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	_a						:						Optional[Any]   					=							(
	    {
	        '''feature-extraction''': TFAlbertModel,
	        '''fill-mask''': TFAlbertForMaskedLM,
	        '''question-answering''': TFAlbertForQuestionAnswering,
	        '''text-classification''': TFAlbertForSequenceClassification,
	        '''token-classification''': TFAlbertForTokenClassification,
	        '''zero-shot''': TFAlbertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	_a						:						Union[str, Any]   					=							False
	_a						:						int   					=							False




	def 							UpperCAmelCase__(      self		:	Any	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Any	,      _SCREAMING_SNAKE_CASE		:	List[str]=False	)-> Union[str, Any]:
			lowerCAmelCase__     :    Any					  =      super()._prepare_for_class(_SCREAMING_SNAKE_CASE	,      _SCREAMING_SNAKE_CASE	,      return_labels=_SCREAMING_SNAKE_CASE	)

			if return_labels:
					if model_class in get_values(_SCREAMING_SNAKE_CASE	):
							lowerCAmelCase__     :    Optional[Any]					  =      tf.zeros(self.model_tester.batch_size	,      dtype=tf.intaa	)

			return inputs_dict




	def 							UpperCAmelCase__(      self		:	List[str]	)-> Tuple:
			lowerCAmelCase__     :    List[Any]					  =      TFAlbertModelTester(self	)
			lowerCAmelCase__     :    List[Any]					  =      ConfigTester(self	,      config_class=_SCREAMING_SNAKE_CASE	,      hidden_size=37	)




	def 							UpperCAmelCase__(      self		:	str	)-> Any:
			self.config_tester.run_common_tests()




	def 							UpperCAmelCase__(      self		:	Optional[Any]	)-> Dict:
			lowerCAmelCase__     :    Any					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_model(*_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	Any	)-> str:
			lowerCAmelCase__     :    Any					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_for_pretraining(*_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	Optional[Any]	)-> str:
			lowerCAmelCase__     :    List[str]					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_for_masked_lm(*_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	Union[str, Any]	)-> Union[str, Any]:
			lowerCAmelCase__     :    int					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_for_multiple_choice(*_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	List[Any]	)-> List[str]:
			lowerCAmelCase__     :    Union[str, Any]					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_for_sequence_classification(*_SCREAMING_SNAKE_CASE	)




	def 							UpperCAmelCase__(      self		:	str	)-> List[str]:
			lowerCAmelCase__     :    Dict					  =      self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_albert_for_question_answering(*_SCREAMING_SNAKE_CASE	)




	@slow
	def 							UpperCAmelCase__(      self		:	str	)-> Optional[int]:
			for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCAmelCase__     :    Optional[int]					  =      TFAlbertModel.from_pretrained(_SCREAMING_SNAKE_CASE	)
					self.assertIsNotNone(_SCREAMING_SNAKE_CASE	)





@require_tf
class       _a							(       unittest.TestCase):




	@slow
	def 							UpperCAmelCase__(      self		:	str	)-> str:
			lowerCAmelCase__     :    Tuple					  =      TFAlbertForPreTraining.from_pretrained('''albert-base-v2'''	)
			lowerCAmelCase__     :    Tuple					  =      tf.constant([[0, 1, 2, 3, 4, 5]]	)
			lowerCAmelCase__     :    List[str]					  =      model(_SCREAMING_SNAKE_CASE	)[0]

			lowerCAmelCase__     :    Union[str, Any]					  =      [1, 6, 3_0000]
			self.assertEqual(output.shape	,      _SCREAMING_SNAKE_CASE	)

			lowerCAmelCase__     :    int					  =      tf.constant(
			    [
			        [
			            [4.59_5668, 0.7446_2754, -1.81_8147],
			            [4.595_4347, 0.745_4184, -1.818_8258],
			            [4.595_4905, 0.744_8235, -1.818_2316],
			        ]
			    ]	)
			tf.debugging.assert_near(output[:, :3, :3]	,      _SCREAMING_SNAKE_CASE	,      atol=1E-4	)




