






'''simple docstring'''




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


lowerCAmelCase__          =						logging.get_logger(__name__)

lowerCAmelCase__          =						{
    'google/pegasus-large': 'https://huggingface.co/google/pegasus-large/resolve/main/config.json',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''pegasus'''
	_lowerCamelCase              =  ['''past_key_values''']
	_lowerCamelCase              =  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}

	def __init__(      self   :						int  ,					UpperCAmelCase_   :						Optional[int]=50_265  ,					UpperCAmelCase_   :						Optional[Any]=1_024  ,					UpperCAmelCase_   :						int=12  ,					UpperCAmelCase_   :						Optional[int]=4_096  ,					UpperCAmelCase_   :						Tuple=16  ,					UpperCAmelCase_   :						Optional[int]=12  ,					UpperCAmelCase_   :						Dict=4_096  ,					UpperCAmelCase_   :						Optional[Any]=16  ,					UpperCAmelCase_   :						Tuple=0.0  ,					UpperCAmelCase_   :						List[str]=0.0  ,					UpperCAmelCase_   :						Optional[int]=True  ,					UpperCAmelCase_   :						Union[str, Any]=True  ,					UpperCAmelCase_   :						List[Any]="gelu"  ,					UpperCAmelCase_   :						Any=1_024  ,					UpperCAmelCase_   :						Optional[int]=0.1  ,					UpperCAmelCase_   :						Union[str, Any]=0.0  ,					UpperCAmelCase_   :						List[Any]=0.0  ,					UpperCAmelCase_   :						Tuple=0.02  ,					UpperCAmelCase_   :						List[str]=0  ,					UpperCAmelCase_   :						str=False  ,					UpperCAmelCase_   :						int=0  ,					UpperCAmelCase_   :						Optional[int]=1  ,					UpperCAmelCase_   :						Union[str, Any]=1  ,					**UpperCAmelCase_   :						List[str]  ,					):
			UpperCamelCase__				:					Optional[int]					=					vocab_size
			UpperCamelCase__				:					Union[str, Any]					=					max_position_embeddings
			UpperCamelCase__				:					List[Any]					=					d_model
			UpperCamelCase__				:					Tuple					=					encoder_ffn_dim
			UpperCamelCase__				:					str					=					encoder_layers
			UpperCamelCase__				:					str					=					encoder_attention_heads
			UpperCamelCase__				:					Optional[int]					=					decoder_ffn_dim
			UpperCamelCase__				:					Dict					=					decoder_layers
			UpperCamelCase__				:					Any					=					decoder_attention_heads
			UpperCamelCase__				:					Dict					=					dropout
			UpperCamelCase__				:					List[Any]					=					attention_dropout
			UpperCamelCase__				:					List[Any]					=					activation_dropout
			UpperCamelCase__				:					Union[str, Any]					=					activation_function
			UpperCamelCase__				:					str					=					init_std
			UpperCamelCase__				:					Union[str, Any]					=					encoder_layerdrop
			UpperCamelCase__				:					List[Any]					=					decoder_layerdrop
			UpperCamelCase__				:					Optional[Any]					=					use_cache
			UpperCamelCase__				:					Any					=					encoder_layers
			UpperCamelCase__				:					Union[str, Any]					=					scale_embedding  # scale factor will be sqrt(d_model) if True
			super().__init__(
			    pad_token_id=UpperCAmelCase_  ,					eos_token_id=UpperCAmelCase_  ,					is_encoder_decoder=UpperCAmelCase_  ,					decoder_start_token_id=UpperCAmelCase_  ,					forced_eos_token_id=UpperCAmelCase_  ,					**UpperCAmelCase_  ,					)

	@property
	def      __UpperCamelCase							(      self   :						Dict):
			return self.encoder_attention_heads





	@property
	def      __UpperCamelCase							(      self   :						List[Any]):
			return self.d_model












'''simple docstring'''




from typing import Union

import fire
import torch
from tqdm import tqdm







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_ = "cpu"     ,      lowerCamelCase_ = None)							->     None:
		UpperCamelCase__				:					List[Any]					=					torch.load(lowerCamelCase_     ,      map_location=lowerCamelCase_)
		for k, v in tqdm(state_dict.items()):
				if not isinstance(lowerCamelCase_     ,      torch.Tensor):
						raise TypeError('FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin')
				UpperCamelCase__				:					int					=					v.half()
		if save_path is None:  # overwrite src_path
				UpperCamelCase__				:					List[Any]					=					src_path
		torch.save(lowerCamelCase_     ,      lowerCamelCase_)


if __name__ == "__main__":
		fire.Fire(convert)




