




import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
UpperCamelCase__ :   Any						=							sys.version_info >= (3, 10)





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[int]=None  ,							lowerCamelCase_ :     Optional[Any]=None  )       ->  List[str]:







			"""simple docstring"""





			return field(default_factory=lambda: default  ,							metadata=__UpperCAmelCase  )







@dataclass
class 				lowerCAmelCase_       :
				__a     :       List[Any]						=     42
				__a     :       Any						=     42
				__a     :       List[str]						=     42
				__a     :       Optional[int]						=     42







@dataclass
class 				lowerCAmelCase_       :
				__a     :       List[str]						=     42
				__a     :       int						=     field(default="toto"						,     metadata={"help": "help message"}							)







@dataclass
class 				lowerCAmelCase_       :
				__a     :       Tuple						=     False
				__a     :       int						=     True
				__a     :       Any						=     None







class 				lowerCAmelCase_       (					_lowerCamelCase							):
				__a     :       List[str]						=     "titi"
				__a     :       List[str]						=     "toto"







class 				lowerCAmelCase_       (					_lowerCamelCase							):
				__a     :       str						=     "titi"
				__a     :       Union[str, Any]						=     "toto"
				__a     :       str						=     42







@dataclass
class 				lowerCAmelCase_       :
				__a     :       int						=     "toto"






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Tuple					  =      BasicEnum(self.foo )







@dataclass
class 				lowerCAmelCase_       :
				__a     :       Union[str, Any]						=     "toto"






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Tuple					  =      MixedTypeEnum(self.foo )







@dataclass
class 				lowerCAmelCase_       :
				__a     :       Dict						=     None
				__a     :       List[Any]						=     field(default=_lowerCamelCase						,     metadata={"help": "help message"}							)
				__a     :       Dict						=     None
				__a     :       Dict						=     list_field(default=[]							)
				__a     :       List[Any]						=     list_field(default=[]							)







@dataclass
class 				lowerCAmelCase_       :
				__a     :       List[str]						=     list_field(default=[]							)
				__a     :       List[Any]						=     list_field(default=[1, 2, 3]							)
				__a     :       Tuple						=     list_field(default=["Hallo", "Bonjour", "Hello"]							)
				__a     :       Union[str, Any]						=     list_field(default=[0.1, 0.2, 0.3]							)







@dataclass
class 				lowerCAmelCase_       :
				__a     :       Tuple						=     field()
				__a     :       Union[str, Any]						=     field()
				__a     :       List[str]						=     field()






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      BasicEnum(self.required_enum )







@dataclass
class 				lowerCAmelCase_       :
				__a     :       int						=     42
				__a     :       List[str]						=     field()
				__a     :       Optional[Any]						=     None
				__a     :       Optional[Any]						=     field(default="toto"						,     metadata={"help": "help message"}							)
				__a     :       Tuple						=     list_field(default=["Hallo", "Bonjour", "Hello"]							)


if is_python_no_less_than_3_10:







						@dataclass
						class 				lowerCAmelCase_       :
										__a     :       Optional[int]						=     False
										__a     :       Union[str, Any]						=     True
										__a     :       Optional[int]						=     None







						@dataclass
						class 				lowerCAmelCase_       :
										__a     :       Tuple						=     None
										__a     :       Optional[int]						=     field(default=_lowerCamelCase						,     metadata={"help": "help message"}							)
										__a     :       str						=     None
										__a     :       Optional[Any]						=     list_field(default=[]							)
										__a     :       Union[str, Any]						=     list_field(default=[]							)







class 				lowerCAmelCase_       (					unittest.TestCase							):






				def 		snake_case	(			self      ,snake_case__      ,snake_case__ ):
							self.assertEqual(len(a._actions )      ,len(b._actions ) )
							for x, y in zip(a._actions      ,b._actions ):
										SCREAMING_SNAKE_CASE_   : List[str]					  =      {k: v for k, v in vars(lowercase_ ).items() if k != 'container'}
										SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      {k: v for k, v in vars(lowercase_ ).items() if k != 'container'}

										# Choices with mixed type have custom function as "type"
										# So we need to compare results directly for equality
										if xx.get('choices'      ,lowercase_ ) and yy.get('choices'      ,lowercase_ ):
													for expected_choice in yy["choices"] + xx["choices"]:
																self.assertEqual(xx['type'](lowercase_ )      ,yy['type'](lowercase_ ) )
													del xx["type"], yy["type"]

										self.assertEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[str]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      argparse.ArgumentParser()
							expected.add_argument('--foo'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument('--bar'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument('--baz'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument('--flag'      ,type=lowercase_      ,default=lowercase_      ,const=lowercase_      ,nargs='?' )
							self.argparsersEqual(lowercase_      ,lowercase_ )

							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
							((SCREAMING_SNAKE_CASE_)  ,    )   : Optional[int]					  =      parser.parse_args_into_dataclasses(lowercase_      ,look_for_args_file=lowercase_ )
							self.assertFalse(example.flag )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Dict					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : str					  =      argparse.ArgumentParser()
							expected.add_argument('--foo'      ,default=42      ,type=lowercase_ )
							expected.add_argument('--baz'      ,default='toto'      ,type=lowercase_      ,help='help message' )
							self.argparsersEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      argparse.ArgumentParser()
							expected.add_argument('--foo'      ,type=lowercase_      ,default=lowercase_      ,const=lowercase_      ,nargs='?' )
							expected.add_argument('--baz'      ,type=lowercase_      ,default=lowercase_      ,const=lowercase_      ,nargs='?' )
							# A boolean no_* argument always has to come after its "default: True" regular counter-part
							# and its default must be set to False
							expected.add_argument('--no_baz'      ,action='store_false'      ,default=lowercase_      ,dest='baz' )
							expected.add_argument('--opt'      ,type=lowercase_      ,default=lowercase_ )

							SCREAMING_SNAKE_CASE_   : Tuple					  =      [WithDefaultBoolExample]
							if is_python_no_less_than_3_10:
										dataclass_types.append(lowercase_ )

							for dataclass_type in dataclass_types:
										SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      HfArgumentParser(lowercase_ )
										self.argparsersEqual(lowercase_      ,lowercase_ )

										SCREAMING_SNAKE_CASE_   : List[str]					  =      parser.parse_args([] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,baz=lowercase_      ,opt=lowercase_ ) )

										SCREAMING_SNAKE_CASE_   : Any					  =      parser.parse_args(['--foo', '--no_baz'] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,baz=lowercase_      ,opt=lowercase_ ) )

										SCREAMING_SNAKE_CASE_   : str					  =      parser.parse_args(['--foo', '--baz'] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,baz=lowercase_      ,opt=lowercase_ ) )

										SCREAMING_SNAKE_CASE_   : Optional[int]					  =      parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True'] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,baz=lowercase_      ,opt=lowercase_ ) )

										SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False'] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,baz=lowercase_      ,opt=lowercase_ ) )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[str]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      argparse.ArgumentParser()
							expected.add_argument(
							    '--foo'      ,default='toto'      ,choices=['titi', 'toto', 42]      ,type=make_choice_type_function(['titi', 'toto', 42] )      ,)
							self.argparsersEqual(lowercase_      ,lowercase_ )

							SCREAMING_SNAKE_CASE_   : Any					  =      parser.parse_args([] )
							self.assertEqual(args.foo      ,'toto' )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      parser.parse_args_into_dataclasses([] )[0]
							self.assertEqual(enum_ex.foo      ,MixedTypeEnum.toto )

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      parser.parse_args(['--foo', 'titi'] )
							self.assertEqual(args.foo      ,'titi' )
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      parser.parse_args_into_dataclasses(['--foo', 'titi'] )[0]
							self.assertEqual(enum_ex.foo      ,MixedTypeEnum.titi )

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      parser.parse_args(['--foo', '42'] )
							self.assertEqual(args.foo      ,42 )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      parser.parse_args_into_dataclasses(['--foo', '42'] )[0]
							self.assertEqual(enum_ex.foo      ,MixedTypeEnum.fourtytwo )






				def 		snake_case	(			self ):







							@dataclass
							class 				lowerCAmelCase_       :
											__a     :       int						=     "toto"



							SCREAMING_SNAKE_CASE_   : Tuple					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Tuple					  =      argparse.ArgumentParser()
							expected.add_argument(
							    '--foo'      ,default='toto'      ,choices=('titi', 'toto', 42)      ,type=make_choice_type_function(['titi', 'toto', 42] )      ,)
							self.argparsersEqual(lowercase_      ,lowercase_ )

							SCREAMING_SNAKE_CASE_   : List[str]					  =      parser.parse_args([] )
							self.assertEqual(args.foo      ,'toto' )

							SCREAMING_SNAKE_CASE_   : Any					  =      parser.parse_args(['--foo', 'titi'] )
							self.assertEqual(args.foo      ,'titi' )

							SCREAMING_SNAKE_CASE_   : Any					  =      parser.parse_args(['--foo', '42'] )
							self.assertEqual(args.foo      ,42 )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : str					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Tuple					  =      argparse.ArgumentParser()
							expected.add_argument('--foo_int'      ,nargs='+'      ,default=[]      ,type=lowercase_ )
							expected.add_argument('--bar_int'      ,nargs='+'      ,default=[1, 2, 3]      ,type=lowercase_ )
							expected.add_argument('--foo_str'      ,nargs='+'      ,default=['Hallo', 'Bonjour', 'Hello']      ,type=lowercase_ )
							expected.add_argument('--foo_float'      ,nargs='+'      ,default=[0.1, 0.2, 0.3]      ,type=lowercase_ )

							self.argparsersEqual(lowercase_      ,lowercase_ )

							SCREAMING_SNAKE_CASE_   : Dict					  =      parser.parse_args([] )
							self.assertEqual(
							    lowercase_      ,Namespace(foo_int=[]      ,bar_int=[1, 2, 3]      ,foo_str=['Hallo', 'Bonjour', 'Hello']      ,foo_float=[0.1, 0.2, 0.3] )      ,)

							SCREAMING_SNAKE_CASE_   : int					  =      parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split() )
							self.assertEqual(lowercase_      ,Namespace(foo_int=[1]      ,bar_int=[2, 3]      ,foo_str=['a', 'b', 'c']      ,foo_float=[0.1, 0.7] ) )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      argparse.ArgumentParser()
							expected.add_argument('--foo'      ,default=lowercase_      ,type=lowercase_ )
							expected.add_argument('--bar'      ,default=lowercase_      ,type=lowercase_      ,help='help message' )
							expected.add_argument('--baz'      ,default=lowercase_      ,type=lowercase_ )
							expected.add_argument('--ces'      ,nargs='+'      ,default=[]      ,type=lowercase_ )
							expected.add_argument('--des'      ,nargs='+'      ,default=[]      ,type=lowercase_ )

							SCREAMING_SNAKE_CASE_   : Any					  =      [OptionalExample]
							if is_python_no_less_than_3_10:
										dataclass_types.append(lowercase_ )

							for dataclass_type in dataclass_types:
										SCREAMING_SNAKE_CASE_   : Tuple					  =      HfArgumentParser(lowercase_ )

										self.argparsersEqual(lowercase_      ,lowercase_ )

										SCREAMING_SNAKE_CASE_   : int					  =      parser.parse_args([] )
										self.assertEqual(lowercase_      ,Namespace(foo=lowercase_      ,bar=lowercase_      ,baz=lowercase_      ,ces=[]      ,des=[] ) )

										SCREAMING_SNAKE_CASE_   : List[str]					  =      parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split() )
										self.assertEqual(lowercase_      ,Namespace(foo=12      ,bar=3.14      ,baz='42'      ,ces=['a', 'b', 'c']      ,des=[1, 2, 3] ) )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Dict					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : List[Any]					  =      argparse.ArgumentParser()
							expected.add_argument('--required_list'      ,nargs='+'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument('--required_str'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument(
							    '--required_enum'      ,type=make_choice_type_function(['titi', 'toto'] )      ,choices=['titi', 'toto']      ,required=lowercase_      ,)
							self.argparsersEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : int					  =      argparse.ArgumentParser()
							expected.add_argument('--foo'      ,type=lowercase_      ,required=lowercase_ )
							expected.add_argument(
							    '--required_enum'      ,type=make_choice_type_function(['titi', 'toto'] )      ,choices=['titi', 'toto']      ,required=lowercase_      ,)
							expected.add_argument('--opt'      ,type=lowercase_      ,default=lowercase_ )
							expected.add_argument('--baz'      ,default='toto'      ,type=lowercase_      ,help='help message' )
							expected.add_argument('--foo_str'      ,nargs='+'      ,default=['Hallo', 'Bonjour', 'Hello']      ,type=lowercase_ )
							self.argparsersEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      {
							    'foo': 12,
							    'bar': 3.14,
							    'baz': '42',
							    'flag': True,
							}

							SCREAMING_SNAKE_CASE_   : Any					  =      parser.parse_dict(lowercase_ )[0]
							SCREAMING_SNAKE_CASE_   : int					  =      BasicExample(**lowercase_ )
							self.assertEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : Any					  =      {
							    'foo': 12,
							    'bar': 3.14,
							    'baz': '42',
							    'flag': True,
							    'extra': 42,
							}

							self.assertRaises(lowercase_      ,parser.parse_dict      ,lowercase_      ,allow_extra_keys=lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : List[Any]					  =      {
							    'foo': 12,
							    'bar': 3.14,
							    'baz': '42',
							    'flag': True,
							}
							with tempfile.TemporaryDirectory() as tmp_dir:
										SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      os.path.join(lowercase_      ,'temp_json' )
										os.mkdir(lowercase_ )
										with open(temp_local_path + '.json'      ,'w+' ) as f:
													json.dump(lowercase_      ,lowercase_ )
										SCREAMING_SNAKE_CASE_   : Tuple					  =      parser.parse_yaml_file(Path(temp_local_path + '.json' ) )[0]

							SCREAMING_SNAKE_CASE_   : Dict					  =      BasicExample(**lowercase_ )
							self.assertEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[str]					  =      HfArgumentParser(lowercase_ )

							SCREAMING_SNAKE_CASE_   : List[str]					  =      {
							    'foo': 12,
							    'bar': 3.14,
							    'baz': '42',
							    'flag': True,
							}
							with tempfile.TemporaryDirectory() as tmp_dir:
										SCREAMING_SNAKE_CASE_   : List[str]					  =      os.path.join(lowercase_      ,'temp_yaml' )
										os.mkdir(lowercase_ )
										with open(temp_local_path + '.yaml'      ,'w+' ) as f:
													yaml.dump(lowercase_      ,lowercase_ )
										SCREAMING_SNAKE_CASE_   : int					  =      parser.parse_yaml_file(Path(temp_local_path + '.yaml' ) )[0]
							SCREAMING_SNAKE_CASE_   : int					  =      BasicExample(**lowercase_ )
							self.assertEqual(lowercase_      ,lowercase_ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : str					  =      HfArgumentParser(lowercase_ )
							self.assertIsNotNone(lowercase_ )









'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, 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 numpy as np
							import tensorflow as tf

							from transformers import (
							    TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
							    FlaubertConfig,
							    TFFlaubertForMultipleChoice,
							    TFFlaubertForQuestionAnsweringSimple,
							    TFFlaubertForSequenceClassification,
							    TFFlaubertForTokenClassification,
							    TFFlaubertModel,
							    TFFlaubertWithLMHeadModel,
							)






class 		a							:


				def __init__(						self       :   Tuple			,							lowercase_       :   Any			,							):
									snake_case_		     =							parent
									snake_case_		     =							13
									snake_case_		     =							7
									snake_case_		     =							True
									snake_case_		     =							True
									snake_case_		     =							True
									snake_case_		     =							True
									snake_case_		     =							True
									snake_case_		     =							False
									snake_case_		     =							False
									snake_case_		     =							False
									snake_case_		     =							2
									snake_case_		     =							99
									snake_case_		     =							0
									snake_case_		     =							32
									snake_case_		     =							2
									snake_case_		     =							4
									snake_case_		     =							0.1
									snake_case_		     =							0.1
									snake_case_		     =							512
									snake_case_		     =							16
									snake_case_		     =							2
									snake_case_		     =							0.02
									snake_case_		     =							3
									snake_case_		     =							4
									snake_case_		     =							'''last'''
									snake_case_		     =							True
									snake_case_		     =							None
									snake_case_		     =							0


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size   )
									snake_case_		     =							random_attention_mask([self.batch_size, self.seq_length]			,							dtype=tf.floataa   )

									snake_case_		     =							None
									if self.use_input_lengths:
														snake_case_		     =							(
														    ids_tensor([self.batch_size]			,							vocab_size=2   ) + self.seq_length - 2
														)  # small variation of seq_length

									snake_case_		     =							None
									if self.use_token_type_ids:
														snake_case_		     =							ids_tensor([self.batch_size, self.seq_length]			,							self.n_langs   )

									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_		     =							ids_tensor([self.batch_size]			,							2			,							dtype=tf.floataa   )
														snake_case_		     =							ids_tensor([self.batch_size]			,							self.num_choices   )

									snake_case_		     =							FlaubertConfig(
									    vocab_size=self.vocab_size			,							n_special=self.n_special			,							emb_dim=self.hidden_size			,							n_layers=self.num_hidden_layers			,							n_heads=self.num_attention_heads			,							dropout=self.hidden_dropout_prob			,							attention_dropout=self.attention_probs_dropout_prob			,							gelu_activation=self.gelu_activation			,							sinusoidal_embeddings=self.sinusoidal_embeddings			,							asm=self.asm			,							causal=self.causal			,							n_langs=self.n_langs			,							max_position_embeddings=self.max_position_embeddings			,							initializer_range=self.initializer_range			,							summary_type=self.summary_type			,							use_proj=self.use_proj			,							bos_token_id=self.bos_token_id			,							)

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


				def     A_					(						self       :   List[Any]			,							lowercase_       :   Dict			,							lowercase_       :   Optional[int]			,							lowercase_       :   Any			,							lowercase_       :   List[Any]			,							lowercase_       :   Optional[int]			,							lowercase_       :   int			,							lowercase_       :   int			,							lowercase_       :   str			,							lowercase_       :   int			,							):
									snake_case_		     =							TFFlaubertModel(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''lengths''': input_lengths, '''langs''': token_type_ids}
									snake_case_		     =							model(lowercase_   )

									snake_case_		     =							[input_ids, input_mask]
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.last_hidden_state.shape			,							(self.batch_size, self.seq_length, self.hidden_size)   )


				def     A_					(						self       :   List[str]			,							lowercase_       :   int			,							lowercase_       :   List[str]			,							lowercase_       :   Optional[Any]			,							lowercase_       :   str			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							lowercase_       :   Any			,							lowercase_       :   Dict			,							lowercase_       :   List[Any]			,							):
									snake_case_		     =							TFFlaubertWithLMHeadModel(lowercase_   )

									snake_case_		     =							{'''input_ids''': input_ids, '''lengths''': input_lengths, '''langs''': token_type_ids}
									snake_case_		     =							model(lowercase_   )

									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.vocab_size)   )


				def     A_					(						self       :   str			,							lowercase_       :   Dict			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Dict			,							lowercase_       :   Any			,							lowercase_       :   str			,							lowercase_       :   List[str]			,							lowercase_       :   List[Any]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   str			,							):
									snake_case_		     =							TFFlaubertForQuestionAnsweringSimple(lowercase_   )

									snake_case_		     =							{'''input_ids''': input_ids, '''lengths''': input_lengths}

									snake_case_		     =							model(lowercase_   )

									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     A_					(						self       :   Optional[Any]			,							lowercase_       :   Any			,							lowercase_       :   int			,							lowercase_       :   List[Any]			,							lowercase_       :   Any			,							lowercase_       :   Optional[Any]			,							lowercase_       :   str			,							lowercase_       :   int			,							lowercase_       :   int			,							lowercase_       :   Dict			,							):
									snake_case_		     =							TFFlaubertForSequenceClassification(lowercase_   )

									snake_case_		     =							{'''input_ids''': input_ids, '''lengths''': input_lengths}

									snake_case_		     =							model(lowercase_   )

									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.type_sequence_label_size)   )


				def     A_					(						self       :   List[Any]			,							lowercase_       :   Optional[Any]			,							lowercase_       :   Any			,							lowercase_       :   Any			,							lowercase_       :   List[Any]			,							lowercase_       :   List[Any]			,							lowercase_       :   Dict			,							lowercase_       :   int			,							lowercase_       :   Tuple			,							lowercase_       :   Union[str, Any]			,							):
									snake_case_		     =							self.num_labels
									snake_case_		     =							TFFlaubertForTokenClassification(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.num_labels)   )


				def     A_					(						self       :   Dict			,							lowercase_       :   Tuple			,							lowercase_       :   Optional[int]			,							lowercase_       :   Any			,							lowercase_       :   List[Any]			,							lowercase_       :   int			,							lowercase_       :   Tuple			,							lowercase_       :   List[str]			,							lowercase_       :   List[Any]			,							lowercase_       :   Any			,							):
									snake_case_		     =							self.num_choices
									snake_case_		     =							TFFlaubertForMultipleChoice(config=lowercase_   )
									snake_case_		     =							tf.tile(tf.expand_dims(lowercase_			,							1   )			,							(1, self.num_choices, 1)   )
									snake_case_		     =							tf.tile(tf.expand_dims(lowercase_			,							1   )			,							(1, self.num_choices, 1)   )
									snake_case_		     =							tf.tile(tf.expand_dims(lowercase_			,							1   )			,							(1, self.num_choices, 1)   )
									snake_case_		     =							{
									    '''input_ids''': multiple_choice_inputs_ids,
									    '''attention_mask''': multiple_choice_input_mask,
									    '''token_type_ids''': multiple_choice_token_type_ids,
									}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_choices)   )


				def     A_					(						self       :   Dict   ):
									snake_case_		     =							self.prepare_config_and_inputs()
									(
									    (
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    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,
									    '''langs''': token_type_ids,
									    '''lengths''': input_lengths,
									}
									return config, inputs_dict







@require_tf
class 		a							(  _lowerCamelCase  ,	_lowerCamelCase  ,	unittest.TestCase	):
				snake_case_           =						(
				    (
				        TFFlaubertModel,
				        TFFlaubertWithLMHeadModel,
				        TFFlaubertForSequenceClassification,
				        TFFlaubertForQuestionAnsweringSimple,
				        TFFlaubertForTokenClassification,
				        TFFlaubertForMultipleChoice,
				    )
				    if is_tf_available()
				    else ()
				)
				snake_case_           =						(
				    (TFFlaubertWithLMHeadModel,) if is_tf_available() else ()
				)  # TODO (PVP): Check other models whether language generation is also applicable
				snake_case_           =						(
				    {
				        "feature-extraction": TFFlaubertModel,
				        "fill-mask": TFFlaubertWithLMHeadModel,
				        "question-answering": TFFlaubertForQuestionAnsweringSimple,
				        "text-classification": TFFlaubertForSequenceClassification,
				        "token-classification": TFFlaubertForTokenClassification,
				        "zero-shot": TFFlaubertForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				snake_case_           =						False
				snake_case_           =						False


				def     A_					(						self       :   str			,							lowercase_       :   Optional[Any]			,							lowercase_       :   Optional[Any]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Optional[Any]   ):
									if (
									    pipeline_test_casse_name == "QAPipelineTests"
									    and tokenizer_name is not None
									    and not tokenizer_name.endswith('''Fast'''   )
									):
														# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
														# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
														# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
														return True

									return False


				def     A_					(						self       :   int   ):
									snake_case_		     =							TFFlaubertModelTester(self   )
									snake_case_		     =							ConfigTester(self			,							config_class=lowercase_			,							emb_dim=37   )


				def     A_					(						self       :   List[str]   ):
									self.config_tester.run_common_tests()


				def     A_					(						self       :   Optional[Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_model(*lowercase_   )


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_lm_head(*lowercase_   )


				def     A_					(						self       :   Tuple   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_qa(*lowercase_   )


				def     A_					(						self       :   Tuple   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_sequence_classif(*lowercase_   )


				def     A_					(						self       :   List[str]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_for_token_classification(*lowercase_   )


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_for_multiple_choice(*lowercase_   )


				@slow
				def     A_					(						self       :   Optional[int]   ):
									for model_name in TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														snake_case_		     =							TFFlaubertModel.from_pretrained(lowercase_   )
														self.assertIsNotNone(lowercase_   )







@require_tf
@require_sentencepiece
@require_tokenizers
class 		a							(  unittest.TestCase	):


				@slow
				def     A_					(						self       :   int   ):
									snake_case_		     =							TFFlaubertModel.from_pretrained('''jplu/tf-flaubert-small-cased'''   )

									snake_case_		     =							tf.convert_to_tensor(
									    [[0, 158, 735, 2592, 1424, 6727, 82, 1]]			,							dtype=tf.intaa			,							)  # "J'aime flaubert !"

									snake_case_		     =							model(lowercase_   )[0]
									snake_case_		     =							tf.TensorShape((1, 8, 512)   )
									self.assertEqual(output.shape			,							lowercase_   )
									# compare the actual values for a slice.
									snake_case_		     =							tf.convert_to_tensor(
									    [
									        [
									            [-1.876_8773, -1.56_6555, 0.2707_2418],
									            [-1.692_0038, -0.587_3505, 1.932_9599],
									            [-2.956_3985, -1.699_3835, 1.797_2052],
									        ]
									    ]			,							dtype=tf.floataa			,							)

									self.assertTrue(np.allclose(output[:, :3, :3].numpy()			,							expected_slice.numpy()			,							atol=1e-4   )   )

