code: 
  
  
  
  """simple docstring"""
  import importlib
  import inspect
  from functools import wraps
  from typing import TYPE_CHECKING, Optional, Union
  
  from .download.streaming_download_manager import (
      xbasename,
      xdirname,
      xet_parse,
      xexists,
      xgetsize,
      xglob,
      xgzip_open,
      xisdir,
      xisfile,
      xjoin,
      xlistdir,
      xnumpy_load,
      xopen,
      xpandas_read_csv,
      xpandas_read_excel,
      xPath,
      xrelpath,
      xsio_loadmat,
      xsplit,
      xsplitext,
      xwalk,
      xxml_dom_minidom_parse,
  )
  from .utils.logging import get_logger
  from .utils.patching import patch_submodule
  from .utils.py_utils import get_imports
  
  
  _lowerCAmelCase					:Union[str, Any]  =      get_logger(__name__)
  
  
  if TYPE_CHECKING:
    from .builder import DatasetBuilder
  
  
  
  
  
  def 				lowerCamelCase_		(UpperCamelCase__	:	List[Any]  , UpperCamelCase__	:	Optional[Union[str, bool]] = None							):
      _UpperCAmelCase							:						Any       							=					importlib.import_module(UpperCamelCase__							)
  
      # TODO(QL): always update the module to add subsequent new authentication
      if hasattr(UpperCamelCase__  , '''_patched_for_streaming'''							) and module._patched_for_streaming:
          return
  
      def wrap_auth(UpperCamelCase__	:	List[str]							):
          @wraps(UpperCamelCase__							)
          def wrapper(*UpperCamelCase__	:	Union[str, Any]  , **UpperCamelCase__	:	List[Any]							):
              return function(*UpperCamelCase__  , use_auth_token=UpperCamelCase__  , **UpperCamelCase__							)
  
          _UpperCAmelCase							:						Optional[int]       							=					'''wrap_auth'''
          return wrapper
  
      # open files in a streaming fashion
      patch_submodule(UpperCamelCase__  , '''open'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''os.listdir'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''os.walk'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''glob.glob'''  , wrap_auth(UpperCamelCase__							)							).start()
      # allow to navigate in remote zip files
      patch_submodule(UpperCamelCase__  , '''os.path.join'''  , UpperCamelCase__							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.dirname'''  , UpperCamelCase__							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.basename'''  , UpperCamelCase__							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.relpath'''  , UpperCamelCase__							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.split'''  , UpperCamelCase__							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.splitext'''  , UpperCamelCase__							).start()
      # allow checks on paths
      patch_submodule(UpperCamelCase__  , '''os.path.exists'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.isdir'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.isfile'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''os.path.getsize'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''pathlib.Path'''  , UpperCamelCase__							).start()
      # file readers
      patch_submodule(UpperCamelCase__  , '''gzip.open'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''numpy.load'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''pandas.read_csv'''  , wrap_auth(UpperCamelCase__							)  , attrs=['''__version__''']							).start()
      patch_submodule(UpperCamelCase__  , '''pandas.read_excel'''  , wrap_auth(UpperCamelCase__							)  , attrs=['''__version__''']							).start()
      patch_submodule(UpperCamelCase__  , '''scipy.io.loadmat'''  , wrap_auth(UpperCamelCase__							)  , attrs=['''__version__''']							).start()
      patch_submodule(UpperCamelCase__  , '''xml.etree.ElementTree.parse'''  , wrap_auth(UpperCamelCase__							)							).start()
      patch_submodule(UpperCamelCase__  , '''xml.dom.minidom.parse'''  , wrap_auth(UpperCamelCase__							)							).start()
      _UpperCAmelCase							:						Optional[Any]       							=					True
  
  
  
  
  
  def 				lowerCamelCase_		(UpperCamelCase__	:	"DatasetBuilder"							):
      extend_module_for_streaming(builder.__module__  , use_auth_token=builder.use_auth_token							)
      # if needed, we also have to extend additional internal imports (like wmt14 -> wmt_utils)
      if not builder.__module__.startswith('''datasets.'''							):  # check that it's not a packaged builder like csv
          for imports in get_imports(inspect.getfile(builder.__class__							)							):
              if imports[0] == "internal":
                  _UpperCAmelCase							:						Any       							=					imports[1]
                  _UpperCAmelCase							:						List[Any]       							=					'''.'''.join(builder.__module__.split('''.'''							)[:-1] + [internal_import_name]							)
                  extend_module_for_streaming(UpperCamelCase__  , use_auth_token=builder.use_auth_token							)
  
      # builders can inherit from other builders that might use streaming functionality
      # (for example, ImageFolder and AudioFolder inherit from FolderBuilder which implements examples generation)
      # but these parents builders are not patched automatically as they are not instantiated, so we patch them here
      from .builder import DatasetBuilder
  
      _UpperCAmelCase							:						Tuple       							=					[
          cls.__module__
          for cls in type(UpperCamelCase__							).__mro__[1:]  # make sure it's not the same module we've already patched
          if issubclass(cls  , UpperCamelCase__							) and cls.__module__ != DatasetBuilder.__module__
      ]  # check it's not a standard builder from datasets.builder
      for module in parent_builder_modules:
          extend_module_for_streaming(UpperCamelCase__  , use_auth_token=builder.use_auth_token							)
  
  
  
style_context: 
  
  
  
  """simple docstring"""
  from collections import OrderedDict
  from typing import Any, List, Mapping, Optional
  
  from ... import PreTrainedTokenizer, TensorType, is_torch_available
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfigWithPast, PatchingSpec
  from ...utils import logging
  
  
  _lowerCAmelCase					:Union[str, Any]  =      logging.get_logger(__name__)
  
  _lowerCAmelCase					:List[str]  =      {
      'gpt2': 'https://huggingface.co/gpt2/resolve/main/config.json',
      'gpt2-medium': 'https://huggingface.co/gpt2-medium/resolve/main/config.json',
      'gpt2-large': 'https://huggingface.co/gpt2-large/resolve/main/config.json',
      'gpt2-xl': 'https://huggingface.co/gpt2-xl/resolve/main/config.json',
      'distilgpt2': 'https://huggingface.co/distilgpt2/resolve/main/config.json',
  }
  class 							_UpperCAmelCase							(				a   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       a__             ='''gpt2'''
       a__             =['''past_key_values''']
       a__             ={
           '''hidden_size''': '''n_embd''',
           '''max_position_embeddings''': '''n_positions''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }
  
  
  
  
  
       def __init__(      self ,			A=5_0_2_5_7 ,			A=1_0_2_4 ,			A=7_6_8 ,			A=1_2 ,			A=1_2 ,			A=None ,			A="gelu_new" ,			A=0.1 ,			A=0.1 ,			A=0.1 ,			A=1E-5 ,			A=0.02 ,			A="cls_index" ,			A=True ,			A=None ,			A=True ,			A=0.1 ,			A=True ,			A=True ,			A=5_0_2_5_6 ,			A=5_0_2_5_6 ,			A=False ,			A=False ,			**A ,			)							->      Union[str, Any]:
           _UpperCAmelCase							:						Optional[int]       							=					vocab_size
           _UpperCAmelCase							:						Union[str, Any]       							=					n_positions
           _UpperCAmelCase							:						Optional[Any]       							=					n_embd
           _UpperCAmelCase							:						Tuple       							=					n_layer
           _UpperCAmelCase							:						Any       							=					n_head
           _UpperCAmelCase							:						Union[str, Any]       							=					n_inner
           _UpperCAmelCase							:						Optional[int]       							=					activation_function
           _UpperCAmelCase							:						Optional[int]       							=					resid_pdrop
           _UpperCAmelCase							:						Dict       							=					embd_pdrop
           _UpperCAmelCase							:						List[Any]       							=					attn_pdrop
           _UpperCAmelCase							:						Tuple       							=					layer_norm_epsilon
           _UpperCAmelCase							:						Optional[int]       							=					initializer_range
           _UpperCAmelCase							:						List[str]       							=					summary_type
           _UpperCAmelCase							:						Tuple       							=					summary_use_proj
           _UpperCAmelCase							:						List[Any]       							=					summary_activation
           _UpperCAmelCase							:						Optional[int]       							=					summary_first_dropout
           _UpperCAmelCase							:						int       							=					summary_proj_to_labels
           _UpperCAmelCase							:						Union[str, Any]       							=					scale_attn_weights
           _UpperCAmelCase							:						Any       							=					use_cache
           _UpperCAmelCase							:						Tuple       							=					scale_attn_by_inverse_layer_idx
           _UpperCAmelCase							:						Optional[Any]       							=					reorder_and_upcast_attn
  
           _UpperCAmelCase							:						Union[str, Any]       							=					bos_token_id
           _UpperCAmelCase							:						Optional[int]       							=					eos_token_id
  
           super().__init__(bos_token_id=A ,			eos_token_id=A ,			**A	)
  
  
  
  class 							_UpperCAmelCase							(				a   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       def __init__(      self ,			A ,			A = "default" ,			A = None ,			A = False ,			)							->      str:
           super().__init__(A ,			task=A ,			patching_specs=A ,			use_past=A	)
           if not getattr(self._config ,			'''pad_token_id''' ,			A	):
               # TODO: how to do that better?
               _UpperCAmelCase							:						Optional[int]       							=					0
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      Mapping[str, Mapping[int, str]]:
           _UpperCAmelCase							:						List[str]       							=					OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}	)
           if self.use_past:
               self.fill_with_past_key_values_(A ,			direction='''inputs'''	)
               _UpperCAmelCase							:						Union[str, Any]       							=					{0: '''batch''', 1: '''past_sequence + sequence'''}
           else:
               _UpperCAmelCase							:						Tuple       							=					{0: '''batch''', 1: '''sequence'''}
  
           return common_inputs
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return self._config.n_layer
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return self._config.n_head
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
           _UpperCAmelCase							:						int       							=					super(A ,			self	).generate_dummy_inputs(
               A ,			batch_size=A ,			seq_length=A ,			is_pair=A ,			framework=A	)
  
           # We need to order the input in the way they appears in the forward()
           _UpperCAmelCase							:						List[Any]       							=					OrderedDict({'''input_ids''': common_inputs['''input_ids''']}	)
  
           # Need to add the past_keys
           if self.use_past:
               if not is_torch_available():
                   raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''	)
               else:
                   import torch
  
                   _UpperCAmelCase							,       _UpperCAmelCase							:						Optional[Any]       							=					common_inputs['''input_ids'''].shape
                   # Not using the same length for past_key_values
                   _UpperCAmelCase							:						Optional[Any]       							=					seqlen + 2
                   _UpperCAmelCase							:						Union[str, Any]       							=					(
                       batch,
                       self.num_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // self.num_attention_heads,
                   )
                   _UpperCAmelCase							:						List[Any]       							=					[
                       (torch.zeros(A	), torch.zeros(A	)) for _ in range(self.num_layers	)
                   ]
  
           _UpperCAmelCase							:						int       							=					common_inputs['''attention_mask''']
           if self.use_past:
               _UpperCAmelCase							:						int       							=					ordered_inputs['''attention_mask'''].dtype
               _UpperCAmelCase							:						Dict       							=					torch.cat(
                   [ordered_inputs['''attention_mask'''], torch.ones(A ,			A ,			dtype=A	)] ,			dim=1	)
  
           return ordered_inputs
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return 1_3
  
  
  