


from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
						import torch

A__						:						Union[str, Any]          =      logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
						from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):


						def     UpperCamelCase(						cls							:	Dict				):
								return cls


def     UpperCamelCase(						__UpperCamelCase							:	Union[Tuple, List]  ,__UpperCamelCase							:	Optional[Union[List["torch.Generator"], "torch.Generator"]] = None  ,__UpperCamelCase							:	Optional["torch.device"] = None  ,__UpperCamelCase							:	Optional["torch.dtype"] = None  ,__UpperCamelCase							:	Optional["torch.layout"] = None  ,):
		lowerCAmelCase_    :  Optional[int]             =				device
		lowerCAmelCase_    :  List[str]             =				shape[0]

		lowerCAmelCase_    :  str             =				layout or torch.strided
		lowerCAmelCase_    :  Union[str, Any]             =				device or torch.device('''cpu'''				)

		if generator is not None:
				lowerCAmelCase_    :  Any             =				generator.device.type if not isinstance(__UpperCamelCase  ,__UpperCamelCase				) else generator[0].device.type
				if gen_device_type != device.type and gen_device_type == "cpu":
						lowerCAmelCase_    :  str             =				'''cpu'''
						if device != "mps":
								logger.info(
								    f"""The passed generator was created on 'cpu' even though a tensor on {device} was expected."""
								    f""" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"""
								    f""" slighly speed up this function by passing a generator that was created on the {device} device."""				)
				elif gen_device_type != device.type and gen_device_type == "cuda":
						raise ValueError(f"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""				)

		if isinstance(__UpperCamelCase  ,__UpperCamelCase				):
				lowerCAmelCase_    :  Optional[int]             =				(1,) + shape[1:]
				lowerCAmelCase_    :  Optional[int]             =				[
				    torch.randn(__UpperCamelCase  ,generator=generator[i]  ,device=__UpperCamelCase  ,dtype=__UpperCamelCase  ,layout=__UpperCamelCase				)
				    for i in range(__UpperCamelCase				)
				]
				lowerCAmelCase_    :  Optional[Any]             =				torch.cat(__UpperCamelCase  ,dim=0				).to(__UpperCamelCase				)
		else:
				lowerCAmelCase_    :  Union[str, Any]             =				torch.randn(__UpperCamelCase  ,generator=__UpperCamelCase  ,device=__UpperCamelCase  ,dtype=__UpperCamelCase  ,layout=__UpperCamelCase				).to(__UpperCamelCase				)

		return latents





def     UpperCamelCase(						__UpperCamelCase							:	List[Any]				):
		if is_torch_version('''<'''  ,'''2.0.0'''				) or not hasattr(__UpperCamelCase  ,'''_dynamo'''				):
				return False
		return isinstance(__UpperCamelCase  ,torch._dynamo.eval_frame.OptimizedModule				)










from collections import OrderedDict
from typing import Mapping

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


A__						:						int          =      logging.get_logger(__name__)

A__						:						Dict          =      {
    '''mnaylor/mega-base-wikitext''': '''https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json''',
}



class        __snake_case		(  UpperCamelCase_		):
							_a       =				'''mega'''




							def __init__( self  : Any       ,       A_  : Dict=3_0_5_2_2       ,       A_  : int=1_2_8       ,       A_  : str=4       ,       A_  : int=2_5_6       ,       A_  : int=1_6       ,       A_  : str=True       ,       A_  : List[str]=6_4       ,       A_  : Optional[Any]=False       ,       A_  : str=-1       ,       A_  : Optional[int]=None       ,       A_  : Tuple=True       ,       A_  : Tuple="scalenorm"       ,       A_  : Optional[Any]=True       ,       A_  : int="silu"       ,       A_  : Optional[int]="softmax"       ,       A_  : Optional[int]=0.1       ,       A_  : Union[str, Any]=0.1       ,       A_  : Any=0.1       ,       A_  : Dict=False       ,       A_  : int=True       ,       A_  : Tuple=2_5_6       ,       A_  : int=True       ,       A_  : List[Any]=0.1       ,       A_  : Optional[Any]=2_0_4_8       ,       A_  : Dict=False       ,       A_  : Dict=2       ,       A_  : Tuple=0.02       ,       A_  : List[Any]=0.2       ,       A_  : str=0.02       ,       A_  : List[str]=1.0       ,       A_  : Union[str, Any]=1       ,       A_  : List[Any]=0       ,       A_  : int=2       ,       A_  : Tuple="rotary"       ,       A_  : Any=None       ,       A_  : Tuple=True       ,       A_  : Any=True       ,       **A_  : Optional[int]       ,       ):
									super().__init__(pad_token_id=A_       ,       bos_token_id=A_       ,       eos_token_id=A_       ,       **A_)

									lowerCAmelCase_    :  Tuple             =				vocab_size
									lowerCAmelCase_    :  str             =				hidden_size
									lowerCAmelCase_    :  Any             =				num_hidden_layers
									lowerCAmelCase_    :  Optional[int]             =				activation
									lowerCAmelCase_    :  Any             =				attention_activation
									lowerCAmelCase_    :  List[Any]             =				intermediate_size
									lowerCAmelCase_    :  Any             =				ema_projection_size
									lowerCAmelCase_    :  Optional[int]             =				bidirectional
									lowerCAmelCase_    :  Tuple             =				shared_representation_size
									lowerCAmelCase_    :  Any             =				use_chunking
									lowerCAmelCase_    :  List[str]             =				chunk_size
									lowerCAmelCase_    :  int             =				truncation
									lowerCAmelCase_    :  Tuple             =				normalize_before_mega
									lowerCAmelCase_    :  Tuple             =				normalization_type
									lowerCAmelCase_    :  List[str]             =				norm_affine
									lowerCAmelCase_    :  List[str]             =				dropout_prob
									lowerCAmelCase_    :  List[str]             =				hidden_dropout_prob
									lowerCAmelCase_    :  Tuple             =				attention_probs_dropout_prob
									lowerCAmelCase_    :  str             =				use_feature_dropout
									lowerCAmelCase_    :  Union[str, Any]             =				use_normalized_ffn
									lowerCAmelCase_    :  Union[str, Any]             =				nffn_hidden_size
									lowerCAmelCase_    :  int             =				normalize_before_ffn
									lowerCAmelCase_    :  Tuple             =				nffn_activation_dropout_prob
									lowerCAmelCase_    :  List[str]             =				max_positions
									lowerCAmelCase_    :  Union[str, Any]             =				add_token_type_embeddings
									lowerCAmelCase_    :  str             =				type_vocab_size
									lowerCAmelCase_    :  int             =				initializer_range
									lowerCAmelCase_    :  str             =				ema_delta_alpha_range
									lowerCAmelCase_    :  Tuple             =				ema_beta_range
									lowerCAmelCase_    :  Any             =				ema_gamma_omega_range
									lowerCAmelCase_    :  Any             =				relative_positional_bias
									lowerCAmelCase_    :  Optional[int]             =				use_cache
									lowerCAmelCase_    :  int             =				classifier_dropout
									lowerCAmelCase_    :  List[Any]             =				add_lm_hidden_dense_layer
									lowerCAmelCase_    :  Optional[Any]             =				1  # not used but required by Hugging Face





class        __snake_case		(  UpperCamelCase_		):




							@property
							def      UpperCAmelCase__    ( self  : Any):
									if self.task == "multiple-choice":
											lowerCAmelCase_    :  Dict             =				{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
									else:
											lowerCAmelCase_    :  int             =				{0: '''batch''', 1: '''sequence'''}
									return OrderedDict(
									    [
									        ('''input_ids''', dynamic_axis),
									        ('''attention_mask''', dynamic_axis),
									    ])





