


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

SCREAMING_SNAKE_CASE					:       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 						lowercase				(	cls		: Dict	)	->str:
				"""simple docstring"""





				return cls






def 						lowercase				(	_snake_case		: Union[Tuple, List]	,  _snake_case		: Optional[Union[List["torch.Generator"], "torch.Generator"]] = None	,  _snake_case		: Optional["torch.device"] = None	,  _snake_case		: Optional["torch.dtype"] = None	,  _snake_case		: Optional["torch.layout"] = None	,  )	->Any:
	"""simple docstring"""





	__snake_case      :		List[Any]         =							device
	__snake_case      :		Optional[int]         =							shape[0]

	__snake_case      :		Dict         =							layout or torch.strided
	__snake_case      :		Optional[Any]         =							device or torch.device('''cpu'''	)

	if generator is not None:
		__snake_case      :		Dict         =							generator.device.type if not isinstance(_snake_case	,  _snake_case	) else generator[0].device.type
		if gen_device_type != device.type and gen_device_type == "cpu":
			__snake_case      :		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(_snake_case	,  _snake_case	):
		__snake_case      :		List[Any]         =							(1,) + shape[1:]
		__snake_case      :		Dict         =							[
		    torch.randn(_snake_case	,  generator=generator[i]	,  device=_snake_case	,  dtype=_snake_case	,  layout=_snake_case	)
		    for i in range(_snake_case	)
		]
		__snake_case      :		Dict         =							torch.cat(_snake_case	,  dim=0	).to(_snake_case	)
	else:
		__snake_case      :		Union[str, Any]         =							torch.randn(_snake_case	,  generator=_snake_case	,  device=_snake_case	,  dtype=_snake_case	,  layout=_snake_case	).to(_snake_case	)

	return latents






def 						lowercase				(	_snake_case		: Union[str, Any]	)	->Tuple:
	"""simple docstring"""





	if is_torch_version('''<'''	,  '''2.0.0'''	) or not hasattr(_snake_case	,  '''_dynamo'''	):
		return False
	return isinstance(_snake_case	,  torch._dynamo.eval_frame.OptimizedModule	)









'''simple docstring'''




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


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

_lowerCAmelCase	:		int		  =						{
    'facebook/opt-125m': 'https://huggingface.co/facebook/opt-125m/blob/main/config.json',
    'facebook/opt-350m': 'https://huggingface.co/facebook/opt-350m/blob/main/config.json',
    'facebook/opt-1.3b': 'https://huggingface.co/facebook/opt-1.3b/blob/main/config.json',
    'facebook/opt-2.7b': 'https://huggingface.co/facebook/opt-2.7b/blob/main/config.json',
    'facebook/opt-6.7b': 'https://huggingface.co/facebook/opt-6.7b/blob/main/config.json',
    'facebook/opt-13b': 'https://huggingface.co/facebook/opt-13b/blob/main/config.json',
}



class 			lowerCAmelCase					(					a				):
	_lowerCamelCase :       Dict         =			"""opt"""
	_lowerCamelCase :       Optional[Any]         =			["""past_key_values"""]



	def __init__(       self			,       snake_case__=5_0272			,       snake_case__=768			,       snake_case__=12			,       snake_case__=3072			,       snake_case__=2048			,       snake_case__=True			,       snake_case__=False			,       snake_case__=None			,       snake_case__=0.1			,       snake_case__=0.0			,       snake_case__=12			,       snake_case__="relu"			,       snake_case__=0.0			,       snake_case__=0.0_2			,       snake_case__=True			,       snake_case__=1			,       snake_case__=2			,       snake_case__=2			,       snake_case__=True			,       snake_case__=True			,       **snake_case__			,       ):
		super().__init__(
		    pad_token_id=snake_case__			,       bos_token_id=snake_case__			,       eos_token_id=snake_case__			,       **snake_case__			,       )
		lowerCAmelCase       :     Union[str, Any]   				=			vocab_size
		lowerCAmelCase       :     List[Any]   				=			max_position_embeddings
		lowerCAmelCase       :     List[str]   				=			num_attention_heads
		lowerCAmelCase       :     Dict   				=			word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
		lowerCAmelCase       :     Optional[Any]   				=			ffn_dim
		lowerCAmelCase       :     Optional[int]   				=			hidden_size
		lowerCAmelCase       :     List[str]   				=			num_hidden_layers
		lowerCAmelCase       :     Union[str, Any]   				=			dropout
		lowerCAmelCase       :     List[str]   				=			attention_dropout
		lowerCAmelCase       :     Union[str, Any]   				=			activation_function
		lowerCAmelCase       :     Optional[Any]   				=			init_std
		lowerCAmelCase       :     List[str]   				=			layerdrop
		lowerCAmelCase       :     Dict   				=			use_cache
		lowerCAmelCase       :     List[Any]   				=			do_layer_norm_before
		# We keep these variables at `True` for backward compatibility.
		lowerCAmelCase       :     List[str]   				=			enable_bias
		lowerCAmelCase       :     Dict   				=			layer_norm_elementwise_affine

		# Note that the only purpose of `_remove_final_layer_norm` is to keep backward compatibility
		# with checkpoints that have been fine-tuned before transformers v4.20.1
		# see https://github.com/facebookresearch/metaseq/pull/164
		lowerCAmelCase       :     Tuple   				=			_remove_final_layer_norm
