




from collections.abc import Generator
from math import sin





def __UpperCamelCase			(       _A  ):
						if len(_A  ) != 32:
												raise ValueError('''Input must be of length 32'''  )

						lowerCAmelCase_      			=  b''''''
						for i in [3, 2, 1, 0]:
												little_endian += string_aa[8 * i : 8 * i + 8]
						return little_endian





def __UpperCamelCase			(       _A  ):
						if i < 0:
												raise ValueError('''Input must be non-negative'''  )

						lowerCAmelCase_      			=  format(_A ,  '''08x'''  )[-8:]
						lowerCAmelCase_      			=  b''''''
						for i in [3, 2, 1, 0]:
												little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''  )
						return little_endian_hex





def __UpperCamelCase			(       _A  ):
						lowerCAmelCase_      			=  b''''''
						for char in message:
												bit_string += format(_A ,  '''08b'''  ).encode('''utf-8'''  )
						lowerCAmelCase_      			=  format(len(_A  ) ,  '''064b'''  ).encode('''utf-8'''  )

						# Pad bit_string to a multiple of 512 chars
						bit_string += b"1"
						while len(_A  ) % 512 != 448:
												bit_string += b"0"
						bit_string += to_little_endian(start_len[32:]  ) + to_little_endian(start_len[:32]  )

						return bit_string





def __UpperCamelCase			(       _A  ):
						if len(_A  ) % 512 != 0:
												raise ValueError('''Input must have length that\'s a multiple of 512'''  )

						for pos in range(0 ,  len(_A  ) ,  512  ):
												lowerCAmelCase_      			=  bit_string[pos : pos + 512]
												lowerCAmelCase_      			=  []
												for i in range(0 ,  512 ,  32  ):
																		block_words.append(int(to_little_endian(block[i : i + 32]  ) ,  2  )  )
												yield block_words





def __UpperCamelCase			(       _A  ):
						if i < 0:
												raise ValueError('''Input must be non-negative'''  )

						lowerCAmelCase_      			=  format(_A ,  '''032b'''  )
						lowerCAmelCase_      			=  ''''''
						for c in i_str:
												new_str += "1" if c == "0" else "0"
						return int(_A ,  2  )





def __UpperCamelCase			(       _A ,  _A  ):
						return (a + b) % 2**32





def __UpperCamelCase			(       _A ,  _A  ):
						if i < 0:
												raise ValueError('''Input must be non-negative'''  )
						if shift < 0:
												raise ValueError('''Shift must be non-negative'''  )
						return ((i << shift) ^ (i >> (32 - shift))) % 2**32





def __UpperCamelCase			(       _A  ):
						lowerCAmelCase_      			=  preprocess(_A  )

						lowerCAmelCase_      			=  [int(2**32 * abs(sin(i + 1  )  )  ) for i in range(64  )]

						# Starting states
						lowerCAmelCase_      			=  0x67452301
						lowerCAmelCase_      			=  0xEFCDAB89
						lowerCAmelCase_      			=  0x98BADCFE
						lowerCAmelCase_      			=  0x10325476

						lowerCAmelCase_      			=  [
						    7,
						    12,
						    17,
						    22,
						    7,
						    12,
						    17,
						    22,
						    7,
						    12,
						    17,
						    22,
						    7,
						    12,
						    17,
						    22,
						    5,
						    9,
						    14,
						    20,
						    5,
						    9,
						    14,
						    20,
						    5,
						    9,
						    14,
						    20,
						    5,
						    9,
						    14,
						    20,
						    4,
						    11,
						    16,
						    23,
						    4,
						    11,
						    16,
						    23,
						    4,
						    11,
						    16,
						    23,
						    4,
						    11,
						    16,
						    23,
						    6,
						    10,
						    15,
						    21,
						    6,
						    10,
						    15,
						    21,
						    6,
						    10,
						    15,
						    21,
						    6,
						    10,
						    15,
						    21,
						]

						# Process bit string in chunks, each with 16 32-char words
						for block_words in get_block_words(_A  ):
												lowerCAmelCase_      			=  aa
												lowerCAmelCase_      			=  ba
												lowerCAmelCase_      			=  ca
												lowerCAmelCase_      			=  da

												# Hash current chunk
												for i in range(64  ):
																		if i <= 15:
																								# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
																								lowerCAmelCase_      			=  d ^ (b & (c ^ d))
																								lowerCAmelCase_      			=  i
																		elif i <= 31:
																								# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
																								lowerCAmelCase_      			=  c ^ (d & (b ^ c))
																								lowerCAmelCase_      			=  (5 * i + 1) % 16
																		elif i <= 47:
																								lowerCAmelCase_      			=  b ^ c ^ d
																								lowerCAmelCase_      			=  (3 * i + 5) % 16
																		else:
																								lowerCAmelCase_      			=  c ^ (b | not_aa(_A  ))
																								lowerCAmelCase_      			=  (7 * i) % 16
																		lowerCAmelCase_      			=  (f + a + added_consts[i] + block_words[g]) % 2**32
																		lowerCAmelCase_      			=  d
																		lowerCAmelCase_      			=  c
																		lowerCAmelCase_      			=  b
																		lowerCAmelCase_      			=  sum_aa(_A ,  left_rotate_aa(_A ,  shift_amounts[i]  )  )

												# Add hashed chunk to running total
												lowerCAmelCase_      			=  sum_aa(_A ,  _A  )
												lowerCAmelCase_      			=  sum_aa(_A ,  _A  )
												lowerCAmelCase_      			=  sum_aa(_A ,  _A  )
												lowerCAmelCase_      			=  sum_aa(_A ,  _A  )

						lowerCAmelCase_      			=  reformat_hex(_A  ) + reformat_hex(_A  ) + reformat_hex(_A  ) + reformat_hex(_A  )
						return digest


if __name__ == "__main__":
						import doctest

						doctest.testmod()










import argparse
from argparse import Namespace

import torch
from torch import nn

from transformers import XGLMConfig, XGLMForCausalLM





def __UpperCamelCase			(       _A  ):
						lowerCAmelCase_      			=  [
						    '''decoder.version''',
						    '''decoder.output_projection.weight''',
						    '''_float_tensor''',
						    '''decoder.embed_positions._float_tensor''',
						]
						for k in ignore_keys:
												state_dict.pop(_A ,  _A  )





def __UpperCamelCase			(       _A  ):
						lowerCAmelCase_			,					lowerCAmelCase_      			=  emb.weight.shape
						lowerCAmelCase_      			=  nn.Linear(_A ,  _A ,  bias=_A  )
						lowerCAmelCase_      			=  emb.weight.data
						return lin_layer





def __UpperCamelCase			(       _A  ):
						lowerCAmelCase_      			=  torch.load(_A ,  map_location='''cpu'''  )
						lowerCAmelCase_      			=  Namespace(**checkpoint['''cfg''']['''model''']  )
						lowerCAmelCase_      			=  checkpoint['''model''']
						remove_ignore_keys_(_A  )
						lowerCAmelCase_      			=  state_dict['''decoder.embed_tokens.weight'''].shape[0]

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

						lowerCAmelCase_      			=  XGLMConfig(
						    vocab_size=_A ,  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 ,  )

						lowerCAmelCase_      			=  XGLMForCausalLM(_A  )
						lowerCAmelCase_      			=  model.load_state_dict(_A ,  strict=_A  )
						print(_A  )
						lowerCAmelCase_      			=  make_linear_from_emb(model.model.embed_tokens  )

						return model


if __name__ == "__main__":
						_A     =			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.''')
						_A     =			parser.parse_args()
						_A     =			convert_fairseq_xglm_checkpoint_from_disk(args.fairseq_path)
						model.save_pretrained(args.pytorch_dump_folder_path)




