


# 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 	_lowerCAmelCase					( UpperCamelCase__:  Any				,       UpperCamelCase__:  Optional[int]				,       UpperCamelCase__:  Any				,       UpperCamelCase__:  Dict    )			-> Union[str, Any]:





	"""simple docstring"""







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

	A             =					multiprocessing.Process(target=UpperCamelCase__				,       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 	_lowerCAmelCase					( UpperCamelCase__:  Tuple				,       UpperCamelCase__:  int				,       UpperCamelCase__:  Optional[Any]    )			-> str:





	"""simple docstring"""







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

		A             =					shutil.rmtree
		A             =					os.rmdir
		A             =					os.chdir

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

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

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





@contextlib.contextmanager
def 	_lowerCAmelCase					( UpperCamelCase__:  Optional[int]    )			-> str:





	"""simple docstring"""







	def signal_handler(UpperCamelCase__:  int				,       UpperCamelCase__:  Optional[Any]    ):
		raise TimeoutException("""Timed out!"""    )

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





@contextlib.contextmanager
def 	_lowerCAmelCase					( )			-> Optional[int]:





	"""simple docstring"""







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





@contextlib.contextmanager
def 	_lowerCAmelCase					( )			-> Tuple:





	"""simple docstring"""







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






class    _UpperCamelCase     (       __snake_case					):

				"""simple docstring"""







				pass






class    _UpperCamelCase     (       io.StringIO					):

				"""simple docstring"""







				def   _UpperCAmelCase       (    self					, *a__					, **a__ )						->					int:
					raise OSError

				def   _UpperCAmelCase       (    self					, *a__					, **a__ )						->					Any:
					raise OSError

				def   _UpperCAmelCase       (    self					, *a__					, **a__ )						->					Union[str, Any]:
					raise OSError

				def   _UpperCAmelCase       (    self					, *a__					, **a__ )						->					Union[str, Any]:
					return False






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

				"""simple docstring"""







				lowerCAmelCase					=			'stdin'





@contextlib.contextmanager
def 	_lowerCAmelCase					( UpperCamelCase__:  str    )			-> Tuple:





	"""simple docstring"""







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





def 	_lowerCAmelCase					( UpperCamelCase__:  str=None    )			-> str:





	"""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

	A             =					None
	A             =					None

	import os

	A             =					"""1"""

	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None

	import shutil

	A             =					None
	A             =					None
	A             =					None

	import subprocess

	A             =					None  # type: ignore

	A             =					None

	import sys

	A             =					None
	A             =					None
	A             =					None
	A             =					None
	A             =					None







from typing import List

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


_lowercase							:   Any						=						logging.get_logger(__name__)

_lowercase							:   Union[str, Any]						=						{
    "snap-research/efficientformer-l1-300": (
        "https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json"
    ),
}






class    _UpperCamelCase     (       __snake_case					):

				"""simple docstring"""







				lowerCAmelCase					=			'efficientformer'

				def __init__(    self					, a__ = [3, 2, 6, 4]					, a__ = [48, 96, 224, 448]					, a__ = [True, True, True, True]					, a__ = 448					, a__ = 32					, a__ = 4					, a__ = 7					, a__ = 5					, a__ = 8					, a__ = 4					, a__ = 0.0					, a__ = 16					, a__ = 3					, a__ = 3					, a__ = 3					, a__ = 2					, a__ = 1					, a__ = 0.0					, a__ = 1					, a__ = True					, a__ = True					, a__ = 1e-5					, a__ = "gelu"					, a__ = 0.02					, a__ = 1e-12					, a__ = 224					, a__ = 1e-05					, **a__					, )						->					None:
					super().__init__(**a__ )

					A             =					hidden_act
					A             =					hidden_dropout_prob
					A             =					hidden_sizes
					A             =					num_hidden_layers
					A             =					num_attention_heads
					A             =					initializer_range
					A             =					layer_norm_eps
					A             =					patch_size
					A             =					num_channels
					A             =					depths
					A             =					mlp_expansion_ratio
					A             =					downsamples
					A             =					dim
					A             =					key_dim
					A             =					attention_ratio
					A             =					resolution
					A             =					pool_size
					A             =					downsample_patch_size
					A             =					downsample_stride
					A             =					downsample_pad
					A             =					drop_path_rate
					A             =					num_metaad_blocks
					A             =					distillation
					A             =					use_layer_scale
					A             =					layer_scale_init_value
					A             =					image_size
					A             =					batch_norm_eps



