




from functools import partial
from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload

import torch
import torch.nn as nn
import torch.types






def    snake_case   (				A		,  A		,  A     )				->				torch.Tensor:




	'''simple docstring'''


	if not inplace:
		lowerCamelCase_				:						int				  =				ma + ma
	else:
		ma += ma

	return ma






def    snake_case   (				A		,  A     )				->				torch.Tensor:




	'''simple docstring'''


	lowerCamelCase_				:						Union[str, Any]				  =				-1 * len(A     )
	lowerCamelCase_				:						List[Any]				  =				list(range(len(tensor.shape[:zero_index]     )     )     )
	return tensor.permute(first_inds + [zero_index + i for i in inds]     )






def    snake_case   (				A		,  A     )				->				torch.Tensor:




	'''simple docstring'''


	return t.reshape(t.shape[:-no_dims] + (-1,)     )






def    snake_case   (				A		,  A		,  A		,  A = 1e-4     )				->				torch.Tensor:




	'''simple docstring'''


	lowerCamelCase_				:						Optional[Any]				  =				mask.expand(*value.shape     )
	return torch.sum(mask * value		,  dim=A     ) / (eps + torch.sum(A		,  dim=A     ))






def    snake_case   (				A		,  A = 2.3125		,  A = 21.6875		,  A = 64     )				->				torch.Tensor:




	'''simple docstring'''


	lowerCamelCase_				:						Dict				  =				torch.linspace(A		,  A		,  no_bins - 1		,  device=pts.device     )
	lowerCamelCase_				:						str				  =				torch.sqrt(torch.sum((pts.unsqueeze(-2     ) - pts.unsqueeze(-3     )) ** 2		,  dim=-1     )     )
	return torch.bucketize(A		,  A     )






def    snake_case   (				A		,  A     )				->				dict:




	'''simple docstring'''


	lowerCamelCase_				:						Optional[int]				  =				dicts[0]
	lowerCamelCase_				:						Union[str, Any]				  =				{}
	for k, v in first.items():
		lowerCamelCase_				:						List[str]				  =				[d[k] for d in dicts]
		if isinstance(A		,  A     ):
			lowerCamelCase_				:						Union[str, Any]				  =				dict_multimap(A		,  A     )
		else:
			lowerCamelCase_				:						Any				  =				fn(A     )

	return new_dict






def    snake_case   (				A		,  A     )				->				torch.Tensor:




	'''simple docstring'''


	lowerCamelCase_				:						str				  =				v_bins.view(((1,) * len(x.shape     )) + (len(A     ),)     )
	lowerCamelCase_				:						int				  =				x[..., None] - reshaped_bins
	lowerCamelCase_				:						List[Any]				  =				torch.argmin(torch.abs(A     )		,  dim=-1     )
	return nn.functional.one_hot(A		,  num_classes=len(A     )     ).float()






def    snake_case   (				A		,  A		,  A = 0		,  A = 0     )				->				torch.Tensor:




	'''simple docstring'''


	lowerCamelCase_				:						List[Union[slice, torch.Tensor]]				  =				[]
	for i, s in enumerate(data.shape[:no_batch_dims]     ):
		lowerCamelCase_				:						Dict				  =				torch.arange(A     )
		lowerCamelCase_				:						int				  =				r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape     ) - i - 1)))     )
		ranges.append(A     )

	lowerCamelCase_				:						List[Union[slice, torch.Tensor]]				  =				[slice(A     ) for _ in range(len(data.shape     ) - no_batch_dims     )]
	lowerCamelCase_				:						Any				  =				inds
	ranges.extend(A     )
	# Matt note: Editing this to get around the behaviour of using a list as an array index changing
	# in recent Numpy versions
	return data[tuple(A     )]


UpperCamelCase__						=		TypeVar('T')






def    snake_case   (				A		,  A		,  A     )				->				Dict[Any, Union[dict, list, tuple, Any]]:




	'''simple docstring'''


	lowerCamelCase_				:						Dict[Any, Union[dict, list, tuple, Any]]				  =				{}
	for k, v in dic.items():
		if isinstance(A		,  A     ):
			lowerCamelCase_				:						str				  =				dict_map(A		,  A		,  A     )
		else:
			lowerCamelCase_				:						int				  =				tree_map(A		,  A		,  A     )

	return new_dict






@overload
def    snake_case   (				A		,  A		,  A     )				->				Any:




	'''simple docstring'''


	...






@overload
def    snake_case   (				A		,  A		,  A     )				->				dict:




	'''simple docstring'''


	...






@overload
def    snake_case   (				A		,  A		,  A     )				->				list:




	'''simple docstring'''


	...






@overload
def    snake_case   (				A		,  A		,  A     )				->				tuple:




	'''simple docstring'''


	...






def    snake_case   (				A		,  A		,  A     )				->				Optional[int]:




	'''simple docstring'''


	if isinstance(A		,  A     ):
		return dict_map(A		,  A		,  A     )
	elif isinstance(A		,  A     ):
		return [tree_map(A		,  A		,  A     ) for x in tree]
	elif isinstance(A		,  A     ):
		return tuple(tree_map(A		,  A		,  A     ) for x in tree     )
	elif isinstance(A		,  A     ):
		return fn(A     )
	else:
		print(type(A     )     )
		raise ValueError('Not supported'     )



UpperCamelCase__						=		partial(tree_map, leaf_type=torch.Tensor)








"""simple docstring"""



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


a  :						Optional[Any]					       =							logging.get_logger(__name__)

a  :						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 	_UpperCamelCase ( __UpperCamelCase							):



    '''simple docstring'''


    __lowercase    :   Optional[Any]											=						'opt'
    __lowercase    :   str											=						['past_key_values']


    def __init__(      self   ,			__lowercase=50272   ,			__lowercase=768   ,			__lowercase=12   ,			__lowercase=3072   ,			__lowercase=2048   ,			__lowercase=True   ,			__lowercase=False   ,			__lowercase=None   ,			__lowercase=0.1   ,			__lowercase=0.0   ,			__lowercase=12   ,			__lowercase="relu"   ,			__lowercase=0.0   ,			__lowercase=0.02   ,			__lowercase=True   ,			__lowercase=1   ,			__lowercase=2   ,			__lowercase=2   ,			__lowercase=True   ,			__lowercase=True   ,			**__lowercase   ,			):
     super().__init__(
         pad_token_id=__lowercase   ,			bos_token_id=__lowercase   ,			eos_token_id=__lowercase   ,			**__lowercase   ,			)
     UpperCAmelCase__ 						=				vocab_size
     UpperCAmelCase__ 						=				max_position_embeddings
     UpperCAmelCase__ 						=				num_attention_heads
     UpperCAmelCase__ 						=				word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
     UpperCAmelCase__ 						=				ffn_dim
     UpperCAmelCase__ 						=				hidden_size
     UpperCAmelCase__ 						=				num_hidden_layers
     UpperCAmelCase__ 						=				dropout
     UpperCAmelCase__ 						=				attention_dropout
     UpperCAmelCase__ 						=				activation_function
     UpperCAmelCase__ 						=				init_std
     UpperCAmelCase__ 						=				layerdrop
     UpperCAmelCase__ 						=				use_cache
     UpperCAmelCase__ 						=				do_layer_norm_before
     # We keep these variables at `True` for backward compatibility.
     UpperCAmelCase__ 						=				enable_bias
     UpperCAmelCase__ 						=				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
     UpperCAmelCase__ 						=				_remove_final_layer_norm



