
import argparse
from argparse import Namespace

import torch
from torch import nn

from transformers import XGLMConfig, XGLMForCausalLM



def   __SCREAMING_SNAKE_CASE (		SCREAMING_SNAKE_CASE )		-> str:
		SCREAMING_SNAKE_CASE_					:	Optional[Any]		  =			[
		    'decoder.version',
		    'decoder.output_projection.weight',
		    '_float_tensor',
		    'decoder.embed_positions._float_tensor',
		]
		for k in ignore_keys:
				state_dict.pop(SCREAMING_SNAKE_CASE ,    SCREAMING_SNAKE_CASE )



def   __SCREAMING_SNAKE_CASE (		SCREAMING_SNAKE_CASE )		-> Dict:
		SCREAMING_SNAKE_CASE_  ,      SCREAMING_SNAKE_CASE_					:	Optional[int]		  =			emb.weight.shape
		SCREAMING_SNAKE_CASE_					:	Dict		  =			nn.Linear(SCREAMING_SNAKE_CASE ,    SCREAMING_SNAKE_CASE ,    bias=SCREAMING_SNAKE_CASE )
		SCREAMING_SNAKE_CASE_					:	Tuple		  =			emb.weight.data
		return lin_layer



def   __SCREAMING_SNAKE_CASE (		SCREAMING_SNAKE_CASE )		-> List[Any]:
		SCREAMING_SNAKE_CASE_					:	str		  =			torch.load(SCREAMING_SNAKE_CASE ,    map_location='cpu' )
		SCREAMING_SNAKE_CASE_					:	Union[str, Any]		  =			Namespace(**checkpoint['cfg']['model'] )
		SCREAMING_SNAKE_CASE_					:	str		  =			checkpoint['model']
		remove_ignore_keys_(SCREAMING_SNAKE_CASE )
		SCREAMING_SNAKE_CASE_					:	Dict		  =			state_dict['decoder.embed_tokens.weight'].shape[0]

		SCREAMING_SNAKE_CASE_					:	str		  =			{key.replace('decoder' ,    'model' ): val for key, val in state_dict.items()}

		SCREAMING_SNAKE_CASE_					:	Tuple		  =			XGLMConfig(
		    vocab_size=SCREAMING_SNAKE_CASE ,    max_position_embeddings=args.max_target_positions ,    num_layers=args.decoder_layers ,    attention_heads=args.decoder_attention_heads ,    ffn_dim=args.decoder_ffn_embed_dim ,    d_model=args.decoder_embed_dim ,    layerdrop=args.decoder_layerdrop ,    dropout=args.dropout ,    attention_dropout=args.attention_dropout ,    activation_dropout=args.activation_dropout ,    activation_function='gelu' ,    scale_embedding=not args.no_scale_embedding ,    tie_word_embeddings=args.share_decoder_input_output_embed ,    )

		SCREAMING_SNAKE_CASE_					:	str		  =			XGLMForCausalLM(SCREAMING_SNAKE_CASE )
		SCREAMING_SNAKE_CASE_					:	Any		  =			model.load_state_dict(SCREAMING_SNAKE_CASE ,    strict=SCREAMING_SNAKE_CASE )
		print(SCREAMING_SNAKE_CASE )
		SCREAMING_SNAKE_CASE_					:	Dict		  =			make_linear_from_emb(model.model.embed_tokens )

		return model


if __name__ == "__main__":
		lowerCAmelCase__:    Optional[Any]      = argparse.ArgumentParser()
		# Required parameters
		parser.add_argument("fairseq_path", type=str, help="path to a model.pt on local filesystem.")
		parser.add_argument("pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
		lowerCAmelCase__:    str      = parser.parse_args()
		lowerCAmelCase__:    Dict      = convert_fairseq_xglm_checkpoint_from_disk(args.fairseq_path)
		model.save_pretrained(args.pytorch_dump_folder_path)








'''simple docstring'''
import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
						print('Googling.....')
						lowerCAmelCase					:    List[Any]           = 'https://www.google.com/search?q=' + ' '.join(sys.argv[1:])
						lowerCAmelCase					:    List[Any]           = requests.get(url, headers={'UserAgent': UserAgent().random})
						# res.raise_for_status()
						with open('project1a.html', 'wb') as out_file:  # only for knowing the class
												for data in res.iter_content(1_00_00):
																		out_file.write(data)
						lowerCAmelCase					:    Tuple           = BeautifulSoup(res.text, 'html.parser')
						lowerCAmelCase					:    List[Any]           = list(soup.select('.eZt8xd'))[:5]

						print(len(links))
						for link in links:
												if link.text == "Maps":
																		webbrowser.open(link.get('href'))
												else:
																		webbrowser.open(f"""https://google.com{link.get('href')}""")




