



'''simple docstring'''







import os
import tempfile
from pathlib import Path
from unittest import TestCase

import pyarrow as pa
import pytest

from datasets.arrow_dataset import Dataset
from datasets.arrow_reader import ArrowReader, BaseReader, FileInstructions, ReadInstruction, make_file_instructions
from datasets.info import DatasetInfo
from datasets.splits import NamedSplit, Split, SplitDict, SplitInfo

from .utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases

class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  Dict   ,		__A		:  Union[str, Any]   ,		__A		:  List[Any]=False					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__  =   (
								    filename_skip_take["""filename"""],
								    filename_skip_take["""skip"""] if """skip""" in filename_skip_take else None,
								    filename_skip_take["""take"""] if """take""" in filename_skip_take else None,
								)
								open(os.path.join(__A					)   ,		"""wb"""					).close()
								lowerCAmelCase__  =   pa.Table.from_pydict({"""filename""": [Path(__A					).name] * 100}					)
								if take == -1:
															lowerCAmelCase__  =   len(__A					) - skip
								if skip is not None and take is not None:
															lowerCAmelCase__  =   pa_table.slice(__A   ,		__A					)
								return pa_table





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  List[Any]					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   """my_name"""
								lowerCAmelCase__  =   SplitInfo(name="""train"""   ,		num_examples=100					)
								lowerCAmelCase__  =   SplitInfo(name="""test"""   ,		num_examples=100					)
								lowerCAmelCase__  =   [train_info, test_info]
								lowerCAmelCase__  =   SplitDict()
								split_dict.add(__A					)
								split_dict.add(__A					)
								lowerCAmelCase__  =   DatasetInfo(splits=__A					)

								with tempfile.TemporaryDirectory() as tmp_dir:
															lowerCAmelCase__  =   ReaderTest(__A   ,		__A					)

															lowerCAmelCase__  =   """test[:33%]"""
															lowerCAmelCase__  =   Dataset(**reader.read(__A   ,		__A   ,		__A					)					)
															self.assertEqual(dset["""filename"""][0]   ,		f'''{name}-test'''					)
															self.assertEqual(dset.num_rows   ,		33					)
															self.assertEqual(dset.num_columns   ,		1					)

															lowerCAmelCase__  =   ["""train""", """test[:33%]"""]
															lowerCAmelCase__  =   [Split.TRAIN, ReadInstruction.from_spec("""test[:33%]"""					)]
															for instructions in [instructionsa, instructionsa]:
																						lowerCAmelCase__  =   [reader.read(__A   ,		__A   ,		__A					) for instr in instructions]
																						lowerCAmelCase__  ,lowerCAmelCase__  =   (Dataset(**__A					) for dataset_kwargs in datasets_kwargs)
																						self.assertEqual(train_dset["""filename"""][0]   ,		f'''{name}-train'''					)
																						self.assertEqual(train_dset.num_rows   ,		100					)
																						self.assertEqual(train_dset.num_columns   ,		1					)
																						self.assertIsInstance(train_dset.split   ,		__A					)
																						self.assertEqual(str(train_dset.split					)   ,		"""train"""					)
																						self.assertEqual(test_dset["""filename"""][0]   ,		f'''{name}-test'''					)
																						self.assertEqual(test_dset.num_rows   ,		33					)
																						self.assertEqual(test_dset.num_columns   ,		1					)
																						self.assertIsInstance(test_dset.split   ,		__A					)
																						self.assertEqual(str(test_dset.split					)   ,		"""test[:33%]"""					)
																						del train_dset, test_dset




	def      lowercase__							(  self		:  int					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   """my_name"""
								lowerCAmelCase__  =   SplitInfo(name="""train"""   ,		num_examples=1000   ,		shard_lengths=[100] * 10					)
								lowerCAmelCase__  =   [train_info]
								lowerCAmelCase__  =   SplitDict()
								split_dict.add(__A					)
								lowerCAmelCase__  =   DatasetInfo(splits=__A					)

								with tempfile.TemporaryDirectory() as tmp_dir:
															lowerCAmelCase__  =   ReaderTest(__A   ,		__A					)

															lowerCAmelCase__  =   """train[:33%]"""
															lowerCAmelCase__  =   Dataset(**reader.read(__A   ,		__A   ,		__A					)					)
															self.assertEqual(dset["""filename"""][0]   ,		f'''{name}-train-00000-of-00010'''					)
															self.assertEqual(dset["""filename"""][-1]   ,		f'''{name}-train-00003-of-00010'''					)
															self.assertEqual(dset.num_rows   ,		330					)
															self.assertEqual(dset.num_columns   ,		1					)




	def      lowercase__							(  self		:  Optional[int]					)     ->			List[str]:




								'''simple docstring'''





								lowerCAmelCase__  =   SplitInfo(name="""train"""   ,		num_examples=100					)
								lowerCAmelCase__  =   SplitInfo(name="""test"""   ,		num_examples=100					)
								lowerCAmelCase__  =   SplitDict()
								split_dict.add(__A					)
								split_dict.add(__A					)
								lowerCAmelCase__  =   DatasetInfo(splits=__A					)

								with tempfile.TemporaryDirectory() as tmp_dir:
															lowerCAmelCase__  =   ReaderTest(__A   ,		__A					)

															lowerCAmelCase__  =   [
															    {"""filename""": os.path.join(__A   ,		"""train"""					)},
															    {"""filename""": os.path.join(__A   ,		"""test"""					), """skip""": 10, """take""": 10},
															]
															lowerCAmelCase__  =   Dataset(**reader.read_files(__A   ,		original_instructions="""train+test[10:20]"""					)					)
															self.assertEqual(dset.num_rows   ,		110					)
															self.assertEqual(dset.num_columns   ,		1					)
															del dset





@pytest.mark.parametrize("""in_memory"""					, [False, True]						)
def 			_lowerCAmelCase(      UpperCAmelCase_      :	Union[str, Any]					, UpperCAmelCase_      :	Optional[Any]					, UpperCAmelCase_      :	Dict						) ->							Tuple:
							lowerCAmelCase__  =   arrow_file
							with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
														lowerCAmelCase__  =   ArrowReader.read_table(UpperCAmelCase_					, in_memory=UpperCAmelCase_						)
							assert table.shape == dataset.data.shape
							assert set(table.column_names						) == set(dataset.data.column_names						)
							assert dict(table.to_pydict()						) == dict(dataset.data.to_pydict()						)  # to_pydict returns OrderedDict
@pytest.mark.parametrize("""in_memory"""					, [False, True]						)
def 			_lowerCAmelCase(      UpperCAmelCase_      :	str					, UpperCAmelCase_      :	Tuple					, UpperCAmelCase_      :	List[Any]						) ->							Dict:
							lowerCAmelCase__  =   arrow_file
							lowerCAmelCase__  =   ArrowReader(""""""					, UpperCAmelCase_						)
							with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
														lowerCAmelCase__  =   reader.read_files([{"""filename""": filename}]					, in_memory=UpperCAmelCase_						)
							assert dataset_kwargs.keys() == {"arrow_table", "info", "split"}
							lowerCAmelCase__  =   dataset_kwargs["""arrow_table"""]
							assert table.shape == dataset.data.shape
							assert set(table.column_names						) == set(dataset.data.column_names						)
							assert dict(table.to_pydict()						) == dict(dataset.data.to_pydict()						)  # to_pydict returns OrderedDict
def 			_lowerCAmelCase(      ) ->							Dict:
							assert ReadInstruction("""train"""					, to=10					, unit="""abs"""						).to_spec() == "train[:10]"
							assert ReadInstruction("""train"""					, from_=-80					, to=10					, unit="""%"""						).to_spec() == "train[-80%:10%]"

							lowerCAmelCase__  =   """train+test"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == spec_train_test

							lowerCAmelCase__  =   """train[2:10]"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == spec_train_abs

							lowerCAmelCase__  =   """train[15%:-20%]"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == spec_train_pct

							lowerCAmelCase__  =   """train[:10%](closest)"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == "train[:10%]"

							lowerCAmelCase__  =   """train[:10%](pct1_dropremainder)"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == spec_train_pct_rounding

							lowerCAmelCase__  =   """train[:10%](pct1_dropremainder)+test[-10%:](pct1_dropremainder)"""
							assert ReadInstruction.from_spec(UpperCAmelCase_						).to_spec() == spec_train_test_pct_rounding
def 			_lowerCAmelCase(      ) ->							Any:
							lowerCAmelCase__  =   """dummy"""
							lowerCAmelCase__  =   [SplitInfo(name="""train"""					, num_examples=100						)]
							lowerCAmelCase__  =   """train[:33%]"""
							lowerCAmelCase__  =   """arrow"""
							lowerCAmelCase__  =   """prefix"""

							lowerCAmelCase__  =   make_file_instructions(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_						)
							assert isinstance(UpperCAmelCase_					, UpperCAmelCase_						)
							assert file_instructions.num_examples == 33
							assert file_instructions.file_instructions == [
							    {"filename": os.path.join(UpperCAmelCase_					, F'''{name}-train.arrow'''						), "skip": 0, "take": 33}
							]

							lowerCAmelCase__  =   [SplitInfo(name="""train"""					, num_examples=100					, shard_lengths=[10] * 10						)]
							lowerCAmelCase__  =   make_file_instructions(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_						)
							assert isinstance(UpperCAmelCase_					, UpperCAmelCase_						)
							assert file_instructions.num_examples == 33
							assert file_instructions.file_instructions == [
							    {"filename": os.path.join(UpperCAmelCase_					, F'''{name}-train-00000-of-00010.arrow'''						), "skip": 0, "take": -1},
							    {"filename": os.path.join(UpperCAmelCase_					, F'''{name}-train-00001-of-00010.arrow'''						), "skip": 0, "take": -1},
							    {"filename": os.path.join(UpperCAmelCase_					, F'''{name}-train-00002-of-00010.arrow'''						), "skip": 0, "take": -1},
							    {"filename": os.path.join(UpperCAmelCase_					, F'''{name}-train-00003-of-00010.arrow'''						), "skip": 0, "take": 3},
							]






@pytest.mark.parametrize("""name, expected_exception"""					, [(None, TypeError), ("""""", ValueError)]						)
def 			_lowerCAmelCase(      UpperCAmelCase_      :	Optional[Any]					, UpperCAmelCase_      :	str						) ->							Tuple:
							lowerCAmelCase__  =   [SplitInfo(name="""train"""					, num_examples=100						)]
							lowerCAmelCase__  =   """train"""
							lowerCAmelCase__  =   """arrow"""
							lowerCAmelCase__  =   """prefix_path"""
							with pytest.raises(UpperCAmelCase_						):
														lowerCAmelCase__  =   make_file_instructions(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_						)










'''simple docstring'''







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      lowerCamelCase__     :






	'''simple docstring'''

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




								'''simple docstring'''





								lowerCAmelCase__  =   parent
								lowerCAmelCase__  =   13
								lowerCAmelCase__  =   7
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   99
								lowerCAmelCase__  =   16
								lowerCAmelCase__  =   32
								lowerCAmelCase__  =   2
								lowerCAmelCase__  =   4
								lowerCAmelCase__  =   37
								lowerCAmelCase__  =   """gelu"""
								lowerCAmelCase__  =   0.1
								lowerCAmelCase__  =   0.1
								lowerCAmelCase__  =   512
								lowerCAmelCase__  =   16
								lowerCAmelCase__  =   2
								lowerCAmelCase__  =   0.0_2
								lowerCAmelCase__  =   3
								lowerCAmelCase__  =   4
								lowerCAmelCase__  =   None




	def      lowercase__							(  self		:  Optional[int]					)     ->			int:




								'''simple docstring'''





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

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

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

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

								lowerCAmelCase__  =   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      lowercase__							(  self		:  Optional[Any]   ,		__A		:  Optional[Any]   ,		__A		:  Tuple   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Dict   ,		__A		:  Optional[int]   ,		__A		:  List[Any]					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertModel(config=__A					)
								# inputs = {'input_ids': input_ids,
								#           'attention_mask': input_mask,
								#           'token_type_ids': token_type_ids}
								# sequence_output, pooled_output = model(**inputs)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)

								lowerCAmelCase__  =   [input_ids, input_mask]
								lowerCAmelCase__  =   model(__A					)

								lowerCAmelCase__  =   model(__A					)

								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      lowercase__							(  self		:  List[str]   ,		__A		:  Optional[int]   ,		__A		:  Any   ,		__A		:  List[str]   ,		__A		:  Optional[int]   ,		__A		:  List[Any]   ,		__A		:  Optional[int]   ,		__A		:  Union[str, Any]					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   self.num_labels
								lowerCAmelCase__  =   TFAlbertForPreTraining(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)
								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      lowercase__							(  self		:  str   ,		__A		:  Dict   ,		__A		:  Any   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Union[str, Any]   ,		__A		:  int   ,		__A		:  str					)     ->			str:




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertForMaskedLM(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)
								self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.seq_length, self.vocab_size)					)




	def      lowercase__							(  self		:  Dict   ,		__A		:  List[Any]   ,		__A		:  Union[str, Any]   ,		__A		:  Union[str, Any]   ,		__A		:  Optional[Any]   ,		__A		:  Optional[Any]   ,		__A		:  str   ,		__A		:  List[str]					)     ->			List[Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   self.num_labels
								lowerCAmelCase__  =   TFAlbertForSequenceClassification(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)
								self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.num_labels)					)




	def      lowercase__							(  self		:  Dict   ,		__A		:  Any   ,		__A		:  Tuple   ,		__A		:  Union[str, Any]   ,		__A		:  List[Any]   ,		__A		:  List[Any]   ,		__A		:  Any   ,		__A		:  Any					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertForQuestionAnswering(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)
								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		:  List[Any]   ,		__A		:  Union[str, Any]   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Dict   ,		__A		:  Tuple   ,		__A		:  List[str]   ,		__A		:  Dict					)     ->			List[Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   self.num_choices
								lowerCAmelCase__  =   TFAlbertForMultipleChoice(config=__A					)
								lowerCAmelCase__  =   tf.tile(tf.expand_dims(__A   ,		1					)   ,		(1, self.num_choices, 1)					)
								lowerCAmelCase__  =   tf.tile(tf.expand_dims(__A   ,		1					)   ,		(1, self.num_choices, 1)					)
								lowerCAmelCase__  =   tf.tile(tf.expand_dims(__A   ,		1					)   ,		(1, self.num_choices, 1)					)
								lowerCAmelCase__  =   {
								    """input_ids""": multiple_choice_inputs_ids,
								    """attention_mask""": multiple_choice_input_mask,
								    """token_type_ids""": multiple_choice_token_type_ids,
								}
								lowerCAmelCase__  =   model(__A					)
								self.parent.assertListEqual(list(result["""logits"""].shape					)   ,		[self.batch_size, self.num_choices]					)




	def      lowercase__							(  self		:  int   ,		__A		:  Tuple   ,		__A		:  Optional[Any]   ,		__A		:  Any   ,		__A		:  Union[str, Any]   ,		__A		:  Tuple   ,		__A		:  str   ,		__A		:  Optional[Any]					)     ->			str:




								'''simple docstring'''





								lowerCAmelCase__  =   self.num_labels
								lowerCAmelCase__  =   TFAlbertForTokenClassification(config=__A					)
								lowerCAmelCase__  =   {
								    """input_ids""": input_ids,
								    """attention_mask""": input_mask,
								    """token_type_ids""": token_type_ids,
								}
								lowerCAmelCase__  =   model(__A					)
								self.parent.assertListEqual(list(result["""logits"""].shape					)   ,		[self.batch_size, self.seq_length, self.num_labels]					)




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




								'''simple docstring'''





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





@require_tf
class      lowerCamelCase__     (     _A,     _A,     unittest.TestCase				):






	'''simple docstring'''

	A__		=	(
	    (
	        TFAlbertModel,
	        TFAlbertForPreTraining,
	        TFAlbertForMaskedLM,
	        TFAlbertForSequenceClassification,
	        TFAlbertForQuestionAnswering,
	        TFAlbertForTokenClassification,
	        TFAlbertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	A__		=	(
	    {
	        '''feature-extraction''': TFAlbertModel,
	        '''fill-mask''': TFAlbertForMaskedLM,
	        '''question-answering''': TFAlbertForQuestionAnswering,
	        '''text-classification''': TFAlbertForSequenceClassification,
	        '''token-classification''': TFAlbertForTokenClassification,
	        '''zero-shot''': TFAlbertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	A__		=	False
	A__		=	False




	def      lowercase__							(  self		:  Any   ,		__A		:  List[str]   ,		__A		:  int   ,		__A		:  Union[str, Any]=False					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   super()._prepare_for_class(__A   ,		__A   ,		return_labels=__A					)

								if return_labels:
															if model_class in get_values(__A					):
																						lowerCAmelCase__  =   tf.zeros(self.model_tester.batch_size   ,		dtype=tf.intaa					)

								return inputs_dict




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




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertModelTester(self					)
								lowerCAmelCase__  =   ConfigTester(self   ,		config_class=__A   ,		hidden_size=37					)




	def      lowercase__							(  self		:  List[str]					)     ->			str:




								'''simple docstring'''





								self.config_tester.run_common_tests()




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_model(*__A					)




	def      lowercase__							(  self		:  Optional[int]					)     ->			str:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_pretraining(*__A					)




	def      lowercase__							(  self		:  List[Any]					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_masked_lm(*__A					)




	def      lowercase__							(  self		:  Optional[int]					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_multiple_choice(*__A					)




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_sequence_classification(*__A					)




	def      lowercase__							(  self		:  Any					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_question_answering(*__A					)




	@slow
	def      lowercase__							(  self		:  Tuple					)     ->			Dict:




								'''simple docstring'''





								for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															lowerCAmelCase__  =   TFAlbertModel.from_pretrained(__A					)
															self.assertIsNotNone(__A					)





@require_tf
class      lowerCamelCase__     (     unittest.TestCase				):






	'''simple docstring'''

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




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertForPreTraining.from_pretrained("""albert-base-v2"""					)
								lowerCAmelCase__  =   tf.constant([[0, 1, 2, 3, 4, 5]]					)
								lowerCAmelCase__  =   model(__A					)[0]

								lowerCAmelCase__  =   [1, 6, 3_0000]
								self.assertEqual(output.shape   ,		__A					)

								lowerCAmelCase__  =   tf.constant(
								    [
								        [
								            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
								            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
								            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
								        ]
								    ]					)
								tf.debugging.assert_near(output[:, :3, :3]   ,		__A   ,		atol=1E-4					)





