




'''simple docstring'''


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_ 		=      sys.version_info >= (3, 10)


def 						SCREAMING_SNAKE_CASE       (      a_	:							List[Any]=None				,					a_	:							Optional[int]=None			):
  return field(default_factory=lambda: default				,					metadata=a_			)





@dataclass
class    __lowercase						:
   _a							=      42
   _a							=      42
   _a							=      42
   _a							=      42





@dataclass
class    __lowercase						:
   _a							=      42
   _a							=      field(default="""toto"""       ,							metadata={"""help""": """help message"""} )





@dataclass
class    __lowercase						:
   _a							=      False
   _a							=      True
   _a							=      None





class    __lowercase						(  __magic_name__ ):
   _a							=      """titi"""
   _a							=      """toto"""





class    __lowercase						(  __magic_name__ ):
   _a							=      """titi"""
   _a							=      """toto"""
   _a							=      42





@dataclass
class    __lowercase						:
   _a							=      """toto"""







   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					BasicEnum(self.foo      )





@dataclass
class    __lowercase						:
   _a							=      """toto"""







   def 		UpperCamelCase__			(	self      )				->    Union[str, Any]:
     __a			=					MixedTypeEnum(self.foo      )





@dataclass
class    __lowercase						:
   _a							=      None
   _a							=      field(default=__magic_name__       ,							metadata={"""help""": """help message"""} )
   _a							=      None
   _a							=      list_field(default=[] )
   _a							=      list_field(default=[] )





@dataclass
class    __lowercase						:
   _a							=      list_field(default=[] )
   _a							=      list_field(default=[1, 2, 3] )
   _a							=      list_field(default=["""Hallo""", """Bonjour""", """Hello"""] )
   _a							=      list_field(default=[0.1, 0.2, 0.3] )





@dataclass
class    __lowercase						:
   _a							=      field()
   _a							=      field()
   _a							=      field()







   def 		UpperCamelCase__			(	self      )				->    Tuple:
     __a			=					BasicEnum(self.required_enum      )





@dataclass
class    __lowercase						:
   _a							=      42
   _a							=      field()
   _a							=      None
   _a							=      field(default="""toto"""       ,							metadata={"""help""": """help message"""} )
   _a							=      list_field(default=["""Hallo""", """Bonjour""", """Hello"""] )


if is_python_no_less_than_3_10:





  @dataclass
  class    __lowercase						:
     _a							=      False
     _a							=      True
     _a							=      None





  @dataclass
  class    __lowercase						:
     _a							=      None
     _a							=      field(default=__magic_name__       ,							metadata={"""help""": """help message"""} )
     _a							=      None
     _a							=      list_field(default=[] )
     _a							=      list_field(default=[] )





class    __lowercase						(  unittest.TestCase ):







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

       self.assertEqual(UpperCamelCase      ,							UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    Tuple:
     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					argparse.ArgumentParser()
     expected.add_argument('--foo'      ,							type=UpperCamelCase      ,							required=UpperCamelCase      )
     expected.add_argument('--bar'      ,							type=UpperCamelCase      ,							required=UpperCamelCase      )
     expected.add_argument('--baz'      ,							type=UpperCamelCase      ,							required=UpperCamelCase      )
     expected.add_argument('--flag'      ,							type=UpperCamelCase      ,							default=UpperCamelCase      ,							const=UpperCamelCase      ,							nargs='?'      )
     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

     __a			=					['--foo', '1', '--baz', 'quux', '--bar', '0.5']
     ((__a       )	,              )			=					parser.parse_args_into_dataclasses(UpperCamelCase      ,							look_for_args_file=UpperCamelCase      )
     self.assertFalse(example.flag      )







   def 		UpperCamelCase__			(	self      )				->    Optional[int]:
     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					argparse.ArgumentParser()
     expected.add_argument('--foo'      ,							default=42      ,							type=UpperCamelCase      )
     expected.add_argument('--baz'      ,							default='toto'      ,							type=UpperCamelCase      ,							help='help message'      )
     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    List[Any]:
     __a			=					argparse.ArgumentParser()
     expected.add_argument('--foo'      ,							type=UpperCamelCase      ,							default=UpperCamelCase      ,							const=UpperCamelCase      ,							nargs='?'      )
     expected.add_argument('--baz'      ,							type=UpperCamelCase      ,							default=UpperCamelCase      ,							const=UpperCamelCase      ,							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=UpperCamelCase      ,							dest='baz'      )
     expected.add_argument('--opt'      ,							type=UpperCamelCase      ,							default=UpperCamelCase      )

     __a			=					[WithDefaultBoolExample]
     if is_python_no_less_than_3_10:
       dataclass_types.append(UpperCamelCase      )

     for dataclass_type in dataclass_types:
       __a			=					HfArgumentParser(UpperCamelCase      )
       self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

       __a			=					parser.parse_args([]      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							baz=UpperCamelCase      ,							opt=UpperCamelCase      )      )

       __a			=					parser.parse_args(['--foo', '--no_baz']      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							baz=UpperCamelCase      ,							opt=UpperCamelCase      )      )

       __a			=					parser.parse_args(['--foo', '--baz']      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							baz=UpperCamelCase      ,							opt=UpperCamelCase      )      )

       __a			=					parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							baz=UpperCamelCase      ,							opt=UpperCamelCase      )      )

       __a			=					parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							baz=UpperCamelCase      ,							opt=UpperCamelCase      )      )







   def 		UpperCamelCase__			(	self      )				->    List[Any]:
     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					argparse.ArgumentParser()
     expected.add_argument(
         '--foo'      ,							default='toto'      ,							choices=['titi', 'toto', 42]      ,							type=make_choice_type_function(['titi', 'toto', 42]      )      ,							)
     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

     __a			=					parser.parse_args([]      )
     self.assertEqual(args.foo      ,							'toto'      )
     __a			=					parser.parse_args_into_dataclasses([]      )[0]
     self.assertEqual(enum_ex.foo      ,							MixedTypeEnum.toto      )

     __a			=					parser.parse_args(['--foo', 'titi']      )
     self.assertEqual(args.foo      ,							'titi'      )
     __a			=					parser.parse_args_into_dataclasses(['--foo', 'titi']      )[0]
     self.assertEqual(enum_ex.foo      ,							MixedTypeEnum.titi      )

     __a			=					parser.parse_args(['--foo', '42']      )
     self.assertEqual(args.foo      ,							42      )
     __a			=					parser.parse_args_into_dataclasses(['--foo', '42']      )[0]
     self.assertEqual(enum_ex.foo      ,							MixedTypeEnum.fourtytwo      )







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





     @dataclass
     class    __lowercase						:
        _a							=      """toto"""

     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					argparse.ArgumentParser()
     expected.add_argument(
         '--foo'      ,							default='toto'      ,							choices=('titi', 'toto', 42)      ,							type=make_choice_type_function(['titi', 'toto', 42]      )      ,							)
     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

     __a			=					parser.parse_args([]      )
     self.assertEqual(args.foo      ,							'toto'      )

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

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







   def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
     __a			=					HfArgumentParser(UpperCamelCase      )

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

     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

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

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







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

     __a			=					[OptionalExample]
     if is_python_no_less_than_3_10:
       dataclass_types.append(UpperCamelCase      )

     for dataclass_type in dataclass_types:
       __a			=					HfArgumentParser(UpperCamelCase      )

       self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )

       __a			=					parser.parse_args([]      )
       self.assertEqual(UpperCamelCase      ,							Namespace(foo=UpperCamelCase      ,							bar=UpperCamelCase      ,							baz=UpperCamelCase      ,							ces=[]      ,							des=[]      )      )

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







   def 		UpperCamelCase__			(	self      )				->    Dict:
     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					argparse.ArgumentParser()
     expected.add_argument('--required_list'      ,							nargs='+'      ,							type=UpperCamelCase      ,							required=UpperCamelCase      )
     expected.add_argument('--required_str'      ,							type=UpperCamelCase      ,							required=UpperCamelCase      )
     expected.add_argument(
         '--required_enum'      ,							type=make_choice_type_function(['titi', 'toto']      )      ,							choices=['titi', 'toto']      ,							required=UpperCamelCase      ,							)
     self.argparsersEqual(UpperCamelCase      ,							UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
     __a			=					HfArgumentParser(UpperCamelCase      )

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







   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					HfArgumentParser(UpperCamelCase      )

     __a			=					{
         'foo': 12,
         'bar': 3.14,
         'baz': '42',
         'flag': True,
     }

     __a			=					parser.parse_dict(UpperCamelCase      )[0]
     __a			=					BasicExample(**UpperCamelCase      )
     self.assertEqual(UpperCamelCase      ,							UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					HfArgumentParser(UpperCamelCase      )

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

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







   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					HfArgumentParser(UpperCamelCase      )

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

     __a			=					BasicExample(**UpperCamelCase      )
     self.assertEqual(UpperCamelCase      ,							UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					HfArgumentParser(UpperCamelCase      )

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







   def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
     __a			=					HfArgumentParser(UpperCamelCase      )
     self.assertIsNotNone(UpperCamelCase      )









'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

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


UpperCAmelCase_ 		=      logging.get_logger(__name__)

UpperCAmelCase_ 		=      {
    "distilbert-base-uncased": "https://huggingface.co/distilbert-base-uncased/resolve/main/config.json",
    "distilbert-base-uncased-distilled-squad": (
        "https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-cased": "https://huggingface.co/distilbert-base-cased/resolve/main/config.json",
    "distilbert-base-cased-distilled-squad": (
        "https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-german-cased": "https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json",
    "distilbert-base-multilingual-cased": (
        "https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json"
    ),
    "distilbert-base-uncased-finetuned-sst-2-english": (
        "https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json"
    ),
}





class    __lowercase						(  __magic_name__ ):
   _a							=      """distilbert"""
   _a							=      {
       """hidden_size""": """dim""",
       """num_attention_heads""": """n_heads""",
       """num_hidden_layers""": """n_layers""",
   }







   def __init__(	self      ,							UpperCamelCase=3_0522      ,							UpperCamelCase=512      ,							UpperCamelCase=False      ,							UpperCamelCase=6      ,							UpperCamelCase=12      ,							UpperCamelCase=768      ,							UpperCamelCase=4 * 768      ,							UpperCamelCase=0.1      ,							UpperCamelCase=0.1      ,							UpperCamelCase="gelu"      ,							UpperCamelCase=0.02      ,							UpperCamelCase=0.1      ,							UpperCamelCase=0.2      ,							UpperCamelCase=0      ,							**UpperCamelCase      ,							)				->    int:
     __a			=					vocab_size
     __a			=					max_position_embeddings
     __a			=					sinusoidal_pos_embds
     __a			=					n_layers
     __a			=					n_heads
     __a			=					dim
     __a			=					hidden_dim
     __a			=					dropout
     __a			=					attention_dropout
     __a			=					activation
     __a			=					initializer_range
     __a			=					qa_dropout
     __a			=					seq_classif_dropout
     super().__init__(**UpperCamelCase      ,							pad_token_id=UpperCamelCase      )





class    __lowercase						(  __magic_name__ ):







   @property
   def 		UpperCamelCase__			(	self      )				->    Mapping[str, Mapping[int, str]]:
     if self.task == "multiple-choice":
       __a			=					{0: 'batch', 1: 'choice', 2: 'sequence'}
     else:
       __a			=					{0: 'batch', 1: 'sequence'}
     return OrderedDict(
         [
             ('input_ids', dynamic_axis),
             ('attention_mask', dynamic_axis),
         ]      )



