





# 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      _UpperCamelCase  (a__ :int ,      a__ :Optional[Any] ,      a__ :Any ,      a__ :List[Any]							):






							"""simple docstring"""





							UpperCamelCase__					  =      multiprocessing.Manager()
							UpperCamelCase__					  =      manager.list()

							UpperCamelCase__					  =      multiprocessing.Process(target=a__ ,      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      _UpperCamelCase  (a__ :str ,      a__ :Optional[int] ,      a__ :str							):






							"""simple docstring"""





							with create_tempdir():
														# These system calls are needed when cleaning up tempdir.
														import os
														import shutil

														UpperCamelCase__					  =      shutil.rmtree
														UpperCamelCase__					  =      os.rmdir
														UpperCamelCase__					  =      os.chdir

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

														# Run program.
														try:
																					UpperCamelCase__					  =      {}
																					with swallow_io():
																												with time_limit(a__							):
																																			exec(a__ ,      a__							)
																					result.append("""passed"""							)
														except TimeoutException:
																					result.append("""timed out"""							)
														except BaseException as e:
																					result.append(f"""failed: {e}"""							)

														# Needed for cleaning up.
														UpperCamelCase__					  =      rmtree
														UpperCamelCase__					  =      rmdir
														UpperCamelCase__					  =      chdir





@contextlib.contextmanager
def      _UpperCamelCase  (a__ :Optional[int]							):






							"""simple docstring"""





							def signal_handler(a__ :List[str] ,      a__ :str							):
														raise TimeoutException("""Timed out!"""							)

							signal.setitimer(signal.ITIMER_REAL ,      a__							)
							signal.signal(signal.SIGALRM ,      a__							)
							try:
														yield
							finally:
														signal.setitimer(signal.ITIMER_REAL ,      0							)





@contextlib.contextmanager
def      _UpperCamelCase  ():






							"""simple docstring"""





							UpperCamelCase__					  =      WriteOnlyStringIO()
							with contextlib.redirect_stdout(a__							):
														with contextlib.redirect_stderr(a__							):
																					with redirect_stdin(a__							):
																												yield





@contextlib.contextmanager
def      _UpperCamelCase  ():






							"""simple docstring"""





							with tempfile.TemporaryDirectory() as dirname:
														with chdir(a__							):
																					yield dirname

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							pass






class 							__SCREAMING_SNAKE_CASE       (  io.StringIO							):






							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														raise OSError






							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														raise OSError






							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														raise OSError







							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														return False






class 							__SCREAMING_SNAKE_CASE       (  contextlib._RedirectStream							):  # type: ignore
							snake_case  :   Union[str, Any]      =							"""stdin"""






@contextlib.contextmanager
def      _UpperCamelCase  (a__ :str							):






							"""simple docstring"""





							if root == ".":
														yield
														return
							UpperCamelCase__					  =      os.getcwd()
							os.chdir(a__							)
							try:
														yield
							except BaseException as exc:
														raise exc
							finally:
														os.chdir(a__							)





def      _UpperCamelCase  (a__ :List[Any]=None							):






							"""simple docstring"""





							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__					  =      None
							UpperCamelCase__					  =      None

							import os

							UpperCamelCase__					  =      """1"""

							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None

							import shutil

							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None

							import subprocess

							UpperCamelCase__					  =      None  # type: ignore

							UpperCamelCase__					  =      None

							import sys

							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None
							UpperCamelCase__					  =      None











from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__           =			logging.get_logger(__name__)

UpperCamelCase__           =			{
    "tanreinama/GPTSAN-2.8B-spout_is_uniform": (
        "https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"
    ),
}

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Optional[Any]      =							"""gptsan-japanese"""
							snake_case  :   Any      =							[
							    """past_key_values""",
							]
							snake_case  :   str      =							{
							    """hidden_size""": """d_model""",
							    """num_attention_heads""": """num_heads""",
							    """num_hidden_layers""": """num_layers""",
							}






							def __init__(    self	,			__lowerCAmelCase=36000	,			__lowerCAmelCase=1280	,			__lowerCAmelCase=1024	,			__lowerCAmelCase=8192	,			__lowerCAmelCase=4096	,			__lowerCAmelCase=128	,			__lowerCAmelCase=10	,			__lowerCAmelCase=0	,			__lowerCAmelCase=16	,			__lowerCAmelCase=16	,			__lowerCAmelCase=128	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=1E-5	,			__lowerCAmelCase=False	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase="float32"	,			__lowerCAmelCase=False	,			__lowerCAmelCase=False	,			__lowerCAmelCase=False	,			__lowerCAmelCase=0.002	,			__lowerCAmelCase=False	,			__lowerCAmelCase=True	,			__lowerCAmelCase=35998	,			__lowerCAmelCase=35995	,			__lowerCAmelCase=35999	,			**__lowerCAmelCase	,			):
														UpperCamelCase__					  =      vocab_size
														UpperCamelCase__					  =      max_position_embeddings
														UpperCamelCase__					  =      d_model
														UpperCamelCase__					  =      d_ff
														UpperCamelCase__					  =      d_ext
														UpperCamelCase__					  =      d_spout
														UpperCamelCase__					  =      num_switch_layers
														UpperCamelCase__					  =      num_ext_layers
														UpperCamelCase__					  =      num_switch_layers + num_ext_layers
														UpperCamelCase__					  =      num_heads
														UpperCamelCase__					  =      num_experts
														UpperCamelCase__					  =      expert_capacity
														UpperCamelCase__					  =      dropout_rate
														UpperCamelCase__					  =      layer_norm_epsilon
														UpperCamelCase__					  =      router_bias
														UpperCamelCase__					  =      router_jitter_noise
														UpperCamelCase__					  =      router_dtype
														UpperCamelCase__					  =      router_ignore_padding_tokens
														UpperCamelCase__					  =      output_hidden_states
														UpperCamelCase__					  =      output_attentions
														UpperCamelCase__					  =      initializer_factor
														UpperCamelCase__					  =      output_router_logits
														UpperCamelCase__					  =      use_cache

														super().__init__(
														    separator_token_id=__lowerCAmelCase	,			pad_token_id=__lowerCAmelCase	,			eos_token_id=__lowerCAmelCase	,			**__lowerCAmelCase	,			)




