


from typing import Mapping

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


__UpperCamelCase				:  List[str]      					=							logging.get_logger(__name__)

__UpperCamelCase				:  Optional[int]      					=							{
    '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  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     Optional[int]			= 't5'
    A_  :     Optional[Any]			= ['past_key_values']
    A_  :     str			= {'hidden_size': 'd_model', 'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}





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





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   vocab_size
       UpperCAmelCase_							:      Tuple						=   d_model
       UpperCAmelCase_							:      int						=   d_kv
       UpperCAmelCase_							:      str						=   d_ff
       UpperCAmelCase_							:      str						=   num_layers
       UpperCAmelCase_							:      str						=   (
           num_decoder_layers if num_decoder_layers is not None else self.num_layers
       )  # default = symmetry
       UpperCAmelCase_							:      List[str]						=   num_heads
       UpperCAmelCase_							:      Optional[int]						=   relative_attention_num_buckets
       UpperCAmelCase_							:      int						=   relative_attention_max_distance
       UpperCAmelCase_							:      List[Any]						=   dropout_rate
       UpperCAmelCase_							:      Optional[Any]						=   layer_norm_epsilon
       UpperCAmelCase_							:      int						=   initializer_factor
       UpperCAmelCase_							:      List[str]						=   feed_forward_proj
       UpperCAmelCase_							:      Optional[int]						=   use_cache

       UpperCAmelCase_							:      Any						=   self.feed_forward_proj.split('''-'''	)
       UpperCAmelCase_							:      Dict						=   act_info[-1]
       UpperCAmelCase_							:      int						=   act_info[0] == '''gated'''

       if len(__snake_case	) > 1 and act_info[0] != "gated" or len(__snake_case	) > 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":
          UpperCAmelCase_							:      int						=   '''gelu_new'''

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





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    @property
    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   {
           '''input_ids''': {0: '''batch''', 1: '''encoder_sequence'''},
           '''attention_mask''': {0: '''batch''', 1: '''encoder_sequence'''},
       }
       if self.use_past:
          UpperCAmelCase_							:      List[Any]						=   '''past_encoder_sequence + sequence'''
          UpperCAmelCase_							:      Dict						=   {0: '''batch'''}
          UpperCAmelCase_							:      Union[str, Any]						=   {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
       else:
          UpperCAmelCase_							:      List[str]						=   {0: '''batch''', 1: '''decoder_sequence'''}
          UpperCAmelCase_							:      Optional[int]						=   {0: '''batch''', 1: '''decoder_sequence'''}

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

       return common_inputs





    @property
    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       return 13



# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile
def      snake_case_						( __lowercase			,       __lowercase			,       __lowercase			,       __lowercase       ):
   UpperCAmelCase_							:      int						=   multiprocessing.Manager()
   UpperCAmelCase_							:      Union[str, Any]						=   manager.list()

   UpperCAmelCase_							:      int						=   multiprocessing.Process(target=__lowercase			,       args=(check_program, result, timeout)       )
   p.start()
   p.join(timeout=timeout + 1       )
   if p.is_alive():
      p.kill()

   if not result:
      result.append('''timed out'''       )

   return {
       "task_id": task_id,
       "passed": result[0] == "passed",
       "result": result[0],
       "completion_id": completion_id,
   }
def      snake_case_						( __lowercase			,       __lowercase			,       __lowercase       ):
   with create_tempdir():
      # These system calls are needed when cleaning up tempdir.
      import os
      import shutil

      UpperCAmelCase_							:      str						=   shutil.rmtree
      UpperCAmelCase_							:      Tuple						=   os.rmdir
      UpperCAmelCase_							:      Dict						=   os.chdir

      # Disable functionalities that can make destructive changes to the test.
      reliability_guard()

      # Run program.
      try:
         UpperCAmelCase_							:      Optional[int]						=   {}
         with swallow_io():
            with time_limit(__lowercase       ):
               exec(__lowercase			,       __lowercase       )
         result.append('''passed'''       )
      except TimeoutException:
         result.append('''timed out'''       )
      except BaseException as e:
         result.append(F'''failed: {e}'''       )

      # Needed for cleaning up.
      UpperCAmelCase_							:      Optional[int]						=   rmtree
      UpperCAmelCase_							:      Optional[Any]						=   rmdir
      UpperCAmelCase_							:      Optional[Any]						=   chdir
@contextlib.contextmanager
def      snake_case_						( __lowercase       ):
   def signal_handler(__lowercase			,       __lowercase       ):
      raise TimeoutException('''Timed out!'''       )

   signal.setitimer(signal.ITIMER_REAL			,       __lowercase       )
   signal.signal(signal.SIGALRM			,       __lowercase       )
   try:
      yield
   finally:
      signal.setitimer(signal.ITIMER_REAL			,       0       )
@contextlib.contextmanager
def      snake_case_						( ):
   UpperCAmelCase_							:      Optional[Any]						=   WriteOnlyStringIO()
   with contextlib.redirect_stdout(__lowercase       ):
      with contextlib.redirect_stderr(__lowercase       ):
         with redirect_stdin(__lowercase       ):
            yield
@contextlib.contextmanager
def      snake_case_						( ):
   with tempfile.TemporaryDirectory() as dirname:
      with chdir(__lowercase       ):
         yield dirname





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    pass





class  lowerCAmelCase__(    io.StringIO						):






    '''simple docstring'''





    def 					_lowerCamelCase (	self				:   Dict       ,   *__snake_case				:   List[Any]       ,   **__snake_case				:   int	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   Dict       ,   *__snake_case				:   int       ,   **__snake_case				:   Any	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   int       ,   *__snake_case				:   List[str]       ,   **__snake_case				:   Optional[Any]	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   Union[str, Any]       ,   *__snake_case				:   Optional[Any]       ,   **__snake_case				:   List[Any]	):





       '''simple docstring'''
       return False





class  lowerCAmelCase__(    contextlib._RedirectStream						):  # type: ignore






    '''simple docstring'''





    A_  :     Optional[Any]			= 'stdin'





@contextlib.contextmanager
def      snake_case_						( __lowercase       ):
   if root == ".":
      yield
      return
   UpperCAmelCase_							:      Tuple						=   os.getcwd()
   os.chdir(__lowercase       )
   try:
      yield
   except BaseException as exc:
      raise exc
   finally:
      os.chdir(__lowercase       )


def      snake_case_						( __lowercase=None       ):

   if maximum_memory_bytes is not None:
      import resource

      resource.setrlimit(resource.RLIMIT_AS			,       (maximum_memory_bytes, maximum_memory_bytes)       )
      resource.setrlimit(resource.RLIMIT_DATA			,       (maximum_memory_bytes, maximum_memory_bytes)       )
      if not platform.uname().system == "Darwin":
         resource.setrlimit(resource.RLIMIT_STACK			,       (maximum_memory_bytes, maximum_memory_bytes)       )

   faulthandler.disable()

   import builtins

   UpperCAmelCase_							:      Any						=   None
   UpperCAmelCase_							:      Any						=   None

   import os

   UpperCAmelCase_							:      Union[str, Any]						=   '''1'''

   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Any						=   None
   UpperCAmelCase_							:      Optional[int]						=   None
   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      str						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      int						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      int						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Any						=   None

   import shutil

   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Tuple						=   None

   import subprocess

   UpperCAmelCase_							:      Dict						=   None  # type: ignore

   UpperCAmelCase_							:      Union[str, Any]						=   None

   import sys

   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      Dict						=   None