


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
SCREAMING_SNAKE_CASE       :      Optional[int]												= sys.version_info >= (3, 10)



def 				UpperCamelCase_(      lowerCamelCase_=None							, lowerCamelCase_=None )    ->						Optional[int]:
    return field(default_factory=lambda: default							, metadata=lowerCamelCase_ )






@dataclass
class _lowerCamelCase:
       lowercase_ :	int
       lowercase_ :	float
       lowercase_ :	str
       lowercase_ :	bool






@dataclass
class _lowerCamelCase:
       lowercase_ :	int     =			42
       lowercase_ :	str     =			field(default="""toto""", metadata={"""help""": """help message"""}   )






@dataclass
class _lowerCamelCase:
       lowercase_ :	bool     =			False
       lowercase_ :	bool     =			True
       lowercase_ :	Optional[bool]     =			None






class _lowerCamelCase(						_a   ):
       lowercase_ :	Tuple     =			"""titi"""
       lowercase_ :	Optional[Any]     =			"""toto"""






class _lowerCamelCase(						_a   ):
       lowercase_ :	Optional[Any]     =			"""titi"""
       lowercase_ :	Any     =			"""toto"""
       lowercase_ :	List[str]     =			42






@dataclass
class _lowerCamelCase:
       lowercase_ :	BasicEnum     =			"toto"
       def 			UpperCamelCase     (					self)       ->   str:




           """simple docstring"""

           _lowercase       :							Dict      		=		BasicEnum(self.foo)






@dataclass
class _lowerCamelCase:
       lowercase_ :	MixedTypeEnum     =			"toto"
       def 			UpperCamelCase     (					self)       ->   Union[str, Any]:




           """simple docstring"""

           _lowercase       :							int      		=		MixedTypeEnum(self.foo)






@dataclass
class _lowerCamelCase:
       lowercase_ :	Optional[int]     =			None
       lowercase_ :	Optional[float]     =			field(default=_a, metadata={"""help""": """help message"""}   )
       lowercase_ :	Optional[str]     =			None
       lowercase_ :	Optional[List[str]]     =			list_field(default=[]   )
       lowercase_ :	Optional[List[int]]     =			list_field(default=[]   )






@dataclass
class _lowerCamelCase:
       lowercase_ :	List[int]     =			list_field(default=[]   )
       lowercase_ :	List[int]     =			list_field(default=[1, 2, 3]   )
       lowercase_ :	List[str]     =			list_field(default=["""Hallo""", """Bonjour""", """Hello"""]   )
       lowercase_ :	List[float]     =			list_field(default=[0.1, 0.2, 0.3]   )






@dataclass
class _lowerCamelCase:
       lowercase_ :	List[int]     =			field()
       lowercase_ :	str     =			field()
       lowercase_ :	BasicEnum     =			field()
       def 			UpperCamelCase     (					self)       ->   List[Any]:




           """simple docstring"""

           _lowercase       :							int      		=		BasicEnum(self.required_enum)






@dataclass
class _lowerCamelCase:
       lowercase_ :	int
       lowercase_ :	"BasicEnum"     =			field()
       lowercase_ :	"Optional[bool]"     =			None
       lowercase_ :	"str"     =			field(default="""toto""", metadata={"""help""": """help message"""}   )
       lowercase_ :	"List[str]"     =			list_field(default=["""Hallo""", """Bonjour""", """Hello"""]   )


if is_python_no_less_than_3_10:






 @dataclass
 class _lowerCamelCase:
        lowercase_ :	bool     =			False
        lowercase_ :	bool     =			True
        lowercase_ :	bool | None     =			None






 @dataclass
 class _lowerCamelCase:
        lowercase_ :	int | None     =			None
        lowercase_ :	float | None     =			field(default=_a, metadata={"""help""": """help message"""}   )
        lowercase_ :	str | None     =			None
        lowercase_ :	list[str] | None     =			list_field(default=[]   )
        lowercase_ :	list[int] | None     =			list_field(default=[]   )






class _lowerCamelCase(						unittest.TestCase   ):
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase)       ->   List[str]:




           """simple docstring"""

           self.assertEqual(len(a._actions),      len(b._actions))
           for x, y in zip(a._actions,      b._actions):
               _lowercase       :							str      		=		{k: v for k, v in vars(lowerCamelCase).items() if k != 'container'}
               _lowercase       :							Any      		=		{k: v for k, v in vars(lowerCamelCase).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',      lowerCamelCase) and yy.get('choices',      lowerCamelCase):
                   for expected_choice in yy["choices"] + xx["choices"]:
                       self.assertEqual(xx['type'](lowerCamelCase),      yy['type'](lowerCamelCase))
                   del xx["type"], yy["type"]

               self.assertEqual(lowerCamelCase,      lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   List[str]:




           """simple docstring"""

           _lowercase       :							List[str]      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							str      		=		argparse.ArgumentParser()
           expected.add_argument('--foo',      type=lowerCamelCase,      required=lowerCamelCase)
           expected.add_argument('--bar',      type=lowerCamelCase,      required=lowerCamelCase)
           expected.add_argument('--baz',      type=lowerCamelCase,      required=lowerCamelCase)
           expected.add_argument('--flag',      type=lowerCamelCase,      default=lowerCamelCase,      const=lowerCamelCase,      nargs='?')
           self.argparsersEqual(lowerCamelCase,      lowerCamelCase)

           _lowercase       :							List[str]      		=		['--foo', '1', '--baz', 'quux', '--bar', '0.5']
           ((_lowercase)		,				)       :							Union[str, Any]      		=		parser.parse_args_into_dataclasses(lowerCamelCase,      look_for_args_file=lowerCamelCase)
           self.assertFalse(example.flag)
       def 			UpperCamelCase     (					self)       ->   Dict:




           """simple docstring"""

           _lowercase       :							Dict      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							Any      		=		argparse.ArgumentParser()
           expected.add_argument('--foo',      default=42,      type=lowerCamelCase)
           expected.add_argument('--baz',      default='toto',      type=lowerCamelCase,      help='help message')
           self.argparsersEqual(lowerCamelCase,      lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   Optional[int]:




           """simple docstring"""

           _lowercase       :							int      		=		argparse.ArgumentParser()
           expected.add_argument('--foo',      type=lowerCamelCase,      default=lowerCamelCase,      const=lowerCamelCase,      nargs='?')
           expected.add_argument('--baz',      type=lowerCamelCase,      default=lowerCamelCase,      const=lowerCamelCase,      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=lowerCamelCase,      dest='baz')
           expected.add_argument('--opt',      type=lowerCamelCase,      default=lowerCamelCase)

           _lowercase       :							Optional[Any]      		=		[WithDefaultBoolExample]
           if is_python_no_less_than_3_10:
               dataclass_types.append(lowerCamelCase)

           for dataclass_type in dataclass_types:
               _lowercase       :							List[str]      		=		HfArgumentParser(lowerCamelCase)
               self.argparsersEqual(lowerCamelCase,      lowerCamelCase)

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

               _lowercase       :							List[str]      		=		parser.parse_args(['--foo', '--no_baz'])
               self.assertEqual(lowerCamelCase,      Namespace(foo=lowerCamelCase,      baz=lowerCamelCase,      opt=lowerCamelCase))

               _lowercase       :							Tuple      		=		parser.parse_args(['--foo', '--baz'])
               self.assertEqual(lowerCamelCase,      Namespace(foo=lowerCamelCase,      baz=lowerCamelCase,      opt=lowerCamelCase))

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

               _lowercase       :							Union[str, Any]      		=		parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False'])
               self.assertEqual(lowerCamelCase,      Namespace(foo=lowerCamelCase,      baz=lowerCamelCase,      opt=lowerCamelCase))
       def 			UpperCamelCase     (					self)       ->   int:




           """simple docstring"""

           _lowercase       :							Tuple      		=		HfArgumentParser(lowerCamelCase)

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

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

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

           _lowercase       :							Optional[int]      		=		parser.parse_args(['--foo', '42'])
           self.assertEqual(args.foo,      42)
           _lowercase       :							List[str]      		=		parser.parse_args_into_dataclasses(['--foo', '42'])[0]
           self.assertEqual(enum_ex.foo,      MixedTypeEnum.fourtytwo)
       def 			UpperCamelCase     (					self)       ->   Tuple:




           """simple docstring"""

           @dataclass
           class _lowerCamelCase:
                  lowercase_ :	Literal["titi", "toto", 42]     =			"toto"


           _lowercase       :							Union[str, Any]      		=		HfArgumentParser(lowerCamelCase)

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

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

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

           _lowercase       :							Any      		=		parser.parse_args(['--foo', '42'])
           self.assertEqual(args.foo,      42)
       def 			UpperCamelCase     (					self)       ->   Union[str, Any]:




           """simple docstring"""

           _lowercase       :							List[str]      		=		HfArgumentParser(lowerCamelCase)

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

           self.argparsersEqual(lowerCamelCase,      lowerCamelCase)

           _lowercase       :							Optional[Any]      		=		parser.parse_args([])
           self.assertEqual(
               lowerCamelCase,      Namespace(foo_int=[],      bar_int=[1, 2, 3],      foo_str=['Hallo', 'Bonjour', 'Hello'],      foo_float=[0.1, 0.2, 0.3]),      )

           _lowercase       :							List[str]      		=		parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split())
           self.assertEqual(lowerCamelCase,      Namespace(foo_int=[1],      bar_int=[2, 3],      foo_str=['a', 'b', 'c'],      foo_float=[0.1, 0.7]))
       def 			UpperCamelCase     (					self)       ->   Optional[Any]:




           """simple docstring"""

           _lowercase       :							Dict      		=		argparse.ArgumentParser()
           expected.add_argument('--foo',      default=lowerCamelCase,      type=lowerCamelCase)
           expected.add_argument('--bar',      default=lowerCamelCase,      type=lowerCamelCase,      help='help message')
           expected.add_argument('--baz',      default=lowerCamelCase,      type=lowerCamelCase)
           expected.add_argument('--ces',      nargs='+',      default=[],      type=lowerCamelCase)
           expected.add_argument('--des',      nargs='+',      default=[],      type=lowerCamelCase)

           _lowercase       :							Any      		=		[OptionalExample]
           if is_python_no_less_than_3_10:
               dataclass_types.append(lowerCamelCase)

           for dataclass_type in dataclass_types:
               _lowercase       :							Dict      		=		HfArgumentParser(lowerCamelCase)

               self.argparsersEqual(lowerCamelCase,      lowerCamelCase)

               _lowercase       :							List[str]      		=		parser.parse_args([])
               self.assertEqual(lowerCamelCase,      Namespace(foo=lowerCamelCase,      bar=lowerCamelCase,      baz=lowerCamelCase,      ces=[],      des=[]))

               _lowercase       :							Union[str, Any]      		=		parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split())
               self.assertEqual(lowerCamelCase,      Namespace(foo=12,      bar=3.1_4,      baz='42',      ces=['a', 'b', 'c'],      des=[1, 2, 3]))
       def 			UpperCamelCase     (					self)       ->   str:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							Optional[int]      		=		argparse.ArgumentParser()
           expected.add_argument('--required_list',      nargs='+',      type=lowerCamelCase,      required=lowerCamelCase)
           expected.add_argument('--required_str',      type=lowerCamelCase,      required=lowerCamelCase)
           expected.add_argument(
               '--required_enum',      type=make_choice_type_function(['titi', 'toto']),      choices=['titi', 'toto'],      required=lowerCamelCase,      )
           self.argparsersEqual(lowerCamelCase,      lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   Dict:




           """simple docstring"""

           _lowercase       :							List[Any]      		=		HfArgumentParser(lowerCamelCase)

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




           """simple docstring"""

           _lowercase       :							Optional[int]      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							Any      		=		{
               'foo': 12,
               'bar': 3.1_4,
               'baz': '42',
               'flag': True,
           }

           _lowercase       :							Tuple      		=		parser.parse_dict(lowerCamelCase)[0]
           _lowercase       :							Dict      		=		BasicExample(**lowerCamelCase)
           self.assertEqual(lowerCamelCase,      lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   int:




           """simple docstring"""

           _lowercase       :							Dict      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							Any      		=		{
               'foo': 12,
               'bar': 3.1_4,
               'baz': '42',
               'flag': True,
               'extra': 42,
           }

           self.assertRaises(lowerCamelCase,      parser.parse_dict,      lowerCamelCase,      allow_extra_keys=lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   Tuple:




           """simple docstring"""

           _lowercase       :							Tuple      		=		HfArgumentParser(lowerCamelCase)

           _lowercase       :							Tuple      		=		{
               'foo': 12,
               'bar': 3.1_4,
               'baz': '42',
               'flag': True,
           }
           with tempfile.TemporaryDirectory() as tmp_dir:
               _lowercase       :							Optional[Any]      		=		os.path.join(lowerCamelCase,      'temp_json')
               os.mkdir(lowerCamelCase)
               with open(temp_local_path + '.json',      'w+') as f:
                   json.dump(lowerCamelCase,      lowerCamelCase)
               _lowercase       :							int      		=		parser.parse_yaml_file(Path(temp_local_path + '.json'))[0]

           _lowercase       :							int      		=		BasicExample(**lowerCamelCase)
           self.assertEqual(lowerCamelCase,      lowerCamelCase)
       def 			UpperCamelCase     (					self)       ->   int:




           """simple docstring"""

           _lowercase       :							int      		=		HfArgumentParser(lowerCamelCase)

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




       def 			UpperCamelCase     (					self)       ->   Dict:




           """simple docstring"""

           _lowercase       :							Tuple      		=		HfArgumentParser(lowerCamelCase)
           self.assertIsNotNone(lowerCamelCase)










from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


UpperCAmelCase__				   =		logging.get_logger(__name__)

UpperCAmelCase__				   =		{
    "t5-small": "https://huggingface.co/t5-small/resolve/main/config.json",
    "t5-base": "https://huggingface.co/t5-base/resolve/main/config.json",
    "t5-large": "https://huggingface.co/t5-large/resolve/main/config.json",
    "t5-3b": "https://huggingface.co/t5-3b/resolve/main/config.json",
    "t5-11b": "https://huggingface.co/t5-11b/resolve/main/config.json",
}






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      __snake_case       =  '''t5'''
      __snake_case       =  ['''past_key_values''']
      __snake_case       =  {'''hidden_size''': '''d_model''', '''num_attention_heads''': '''num_heads''', '''num_hidden_layers''': '''num_layers'''}







      def __init__(      self      :						Optional[Any] ,					__UpperCAmelCase      :						Optional[Any]=32_128 ,					__UpperCAmelCase      :						List[Any]=512 ,					__UpperCAmelCase      :						Dict=64 ,					__UpperCAmelCase      :						Tuple=2_048 ,					__UpperCAmelCase      :						int=6 ,					__UpperCAmelCase      :						Optional[int]=None ,					__UpperCAmelCase      :						Optional[int]=8 ,					__UpperCAmelCase      :						str=32 ,					__UpperCAmelCase      :						Tuple=128 ,					__UpperCAmelCase      :						Optional[Any]=0.1 ,					__UpperCAmelCase      :						int=1e-6 ,					__UpperCAmelCase      :						int=1.0 ,					__UpperCAmelCase      :						List[str]="relu" ,					__UpperCAmelCase      :						int=True ,					__UpperCAmelCase      :						int=True ,					__UpperCAmelCase      :						List[Any]=0 ,					__UpperCAmelCase      :						int=1 ,					**__UpperCAmelCase      :						str ,					)    ->Optional[Any]:




       """simple docstring"""


       a		  =      vocab_size
       a		  =      d_model
       a		  =      d_kv
       a		  =      d_ff
       a		  =      num_layers
       a		  =      (
           num_decoder_layers if num_decoder_layers is not None else self.num_layers
       )  # default = symmetry
       a		  =      num_heads
       a		  =      relative_attention_num_buckets
       a		  =      relative_attention_max_distance
       a		  =      dropout_rate
       a		  =      layer_norm_epsilon
       a		  =      initializer_factor
       a		  =      feed_forward_proj
       a		  =      use_cache

       a		  =      self.feed_forward_proj.split('''-'''  )
       a		  =      act_info[-1]
       a		  =      act_info[0] == '''gated'''

       if len(__UpperCAmelCase  ) > 1 and act_info[0] != "gated" or len(__UpperCAmelCase  ) > 2:
        raise ValueError(
            F"""`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."""
            '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
            '''\'gated-gelu\' or \'relu\''''  )

       # for backwards compatibility
       if feed_forward_proj == "gated-gelu":
        a		  =      '''gelu_new'''

       super().__init__(
           pad_token_id=__UpperCAmelCase ,					eos_token_id=__UpperCAmelCase ,					is_encoder_decoder=__UpperCAmelCase ,					**__UpperCAmelCase ,					)






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      @property
      def       __lowerCAmelCase					(      self      :						Optional[Any]  )    ->Mapping[str, Mapping[int, str]]:




       """simple docstring"""


       a		  =      {
           '''input_ids''': {0: '''batch''', 1: '''encoder_sequence'''},
           '''attention_mask''': {0: '''batch''', 1: '''encoder_sequence'''},
       }
       if self.use_past:
        a		  =      '''past_encoder_sequence + sequence'''
        a		  =      {0: '''batch'''}
        a		  =      {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
       else:
        a		  =      {0: '''batch''', 1: '''decoder_sequence'''}
        a		  =      {0: '''batch''', 1: '''decoder_sequence'''}

       if self.use_past:
        self.fill_with_past_key_values_(__UpperCAmelCase ,					direction='''inputs'''  )

       return common_inputs







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




       """simple docstring"""


       return 13


