
"""simple docstring"""


import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MODEL_FOR_PRETRAINING_MAPPING,
		    MegatronBertForCausalLM,
		    MegatronBertForMaskedLM,
		    MegatronBertForMultipleChoice,
		    MegatronBertForNextSentencePrediction,
		    MegatronBertForPreTraining,
		    MegatronBertForQuestionAnswering,
		    MegatronBertForSequenceClassification,
		    MegatronBertForTokenClassification,
		    MegatronBertModel,
		)







class 					lowerCAmelCase_					:



						'''simple docstring'''


						def __init__(			self  :   List[Any]	,A_  :   List[str]	,A_  :   Optional[int]=13	,A_  :   Tuple=7	,A_  :   int=True	,A_  :   Optional[Any]=True	,A_  :   Dict=True	,A_  :   Tuple=True	,A_  :   List[Any]=99	,A_  :   Dict=64	,A_  :   int=32	,A_  :   List[str]=5	,A_  :   str=4	,A_  :   Tuple=37	,A_  :   Any="gelu"	,A_  :   Tuple=0.1	,A_  :   Optional[Any]=0.1	,A_  :   List[str]=512	,A_  :   Union[str, Any]=16	,A_  :   Any=2	,A_  :   Tuple=0.02	,A_  :   Any=3	,A_  :   Tuple=4	,A_  :   Optional[Any]=None	,)  -> Optional[Any]:
							A     = parent
							A     = batch_size
							A     = seq_length
							A     = is_training
							A     = use_input_mask
							A     = use_token_type_ids
							A     = use_labels
							A     = vocab_size
							A     = hidden_size
							A     = embedding_size
							A     = num_hidden_layers
							A     = num_attention_heads
							A     = intermediate_size
							A     = hidden_act
							A     = hidden_dropout_prob
							A     = attention_probs_dropout_prob
							A     = max_position_embeddings
							A     = type_vocab_size
							A     = type_sequence_label_size
							A     = initializer_range
							A     = num_labels
							A     = num_choices
							A     = scope


						def     _SCREAMING_SNAKE_CASE   (			self  :   Union[str, Any]   )  -> Tuple:
							A     = ids_tensor([self.batch_size, self.seq_length]	,self.vocab_size   )

							A     = None
							if self.use_input_mask:
								A     = random_attention_mask([self.batch_size, self.seq_length]   )

							A     = None
							if self.use_token_type_ids:
								A     = ids_tensor([self.batch_size, self.seq_length]	,self.type_vocab_size   )

							A     = None
							A     = None
							A     = None
							if self.use_labels:
								A     = ids_tensor([self.batch_size]	,self.type_sequence_label_size   )
								A     = ids_tensor([self.batch_size, self.seq_length]	,self.num_labels   )
								A     = ids_tensor([self.batch_size]	,self.num_choices   )

							A     = self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


						def     _SCREAMING_SNAKE_CASE   (			self  :   Union[str, Any]   )  -> Optional[Any]:
							return MegatronBertConfig(
							    vocab_size=self.vocab_size	,hidden_size=self.hidden_size	,num_hidden_layers=self.num_hidden_layers	,num_attention_heads=self.num_attention_heads	,intermediate_size=self.intermediate_size	,embedding_size=self.embedding_size	,hidden_act=self.hidden_act	,hidden_dropout_prob=self.hidden_dropout_prob	,attention_probs_dropout_prob=self.attention_probs_dropout_prob	,max_position_embeddings=self.max_position_embeddings	,type_vocab_size=self.type_vocab_size	,is_decoder=A_	,initializer_range=self.initializer_range	,)


						def     _SCREAMING_SNAKE_CASE   (			self  :   Dict	,A_  :   int	,A_  :   str	,A_  :   int	,A_  :   Optional[Any]	,A_  :   List[Any]	,A_  :   int	,A_  :   List[str]   )  -> Dict:
							A     = MegatronBertModel(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(A_	,attention_mask=A_	,token_type_ids=A_   )
							A     = model(A_	,token_type_ids=A_   )
							A     = model(A_   )

							self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.hidden_size)   )
							self.parent.assertEqual(result.pooler_output.shape	,(self.batch_size, self.hidden_size)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Dict	,A_  :   Tuple	,A_  :   Any	,A_  :   Optional[Any]	,A_  :   Union[str, Any]	,A_  :   Dict	,A_  :   Union[str, Any]	,A_  :   List[Any]   )  -> Union[str, Any]:
							A     = MegatronBertForMaskedLM(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_   )
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.vocab_size)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Tuple	,A_  :   Optional[Any]	,A_  :   Optional[int]	,A_  :   List[str]	,A_  :   Tuple	,A_  :   str	,A_  :   List[Any]	,A_  :   List[Any]   )  -> Tuple:
							A     = MegatronBertForCausalLM(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_   )
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.vocab_size)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   List[Any]	,A_  :   Optional[Any]	,A_  :   Union[str, Any]	,A_  :   Any	,A_  :   Any	,A_  :   List[str]	,A_  :   Any	,A_  :   Optional[int]   )  -> Optional[int]:
							A     = MegatronBertForNextSentencePrediction(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(
							    A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_	,)
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, 2)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[Any]	,A_  :   int	,A_  :   Union[str, Any]	,A_  :   Any	,A_  :   Dict	,A_  :   Tuple	,A_  :   Optional[int]	,A_  :   List[str]   )  -> Any:
							A     = MegatronBertForPreTraining(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(
							    A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_	,next_sentence_label=A_	,)
							self.parent.assertEqual(result.prediction_logits.shape	,(self.batch_size, self.seq_length, self.vocab_size)   )
							self.parent.assertEqual(result.seq_relationship_logits.shape	,(self.batch_size, 2)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[Any]	,A_  :   Optional[int]	,A_  :   Tuple	,A_  :   List[str]	,A_  :   Union[str, Any]	,A_  :   Optional[Any]	,A_  :   int	,A_  :   Dict   )  -> List[Any]:
							A     = MegatronBertForQuestionAnswering(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(
							    A_	,attention_mask=A_	,token_type_ids=A_	,start_positions=A_	,end_positions=A_	,)
							self.parent.assertEqual(result.start_logits.shape	,(self.batch_size, self.seq_length)   )
							self.parent.assertEqual(result.end_logits.shape	,(self.batch_size, self.seq_length)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   List[Any]	,A_  :   Optional[Any]	,A_  :   Tuple	,A_  :   Any	,A_  :   int	,A_  :   Tuple	,A_  :   List[Any]	,A_  :   Tuple   )  -> int:
							A     = self.num_labels
							A     = MegatronBertForSequenceClassification(A_   )
							model.to(A_   )
							model.eval()
							A     = model(A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_   )
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   str	,A_  :   Tuple	,A_  :   List[str]	,A_  :   str	,A_  :   Tuple	,A_  :   Union[str, Any]	,A_  :   List[str]	,A_  :   str   )  -> Tuple:
							A     = self.num_labels
							A     = MegatronBertForTokenClassification(config=A_   )
							model.to(A_   )
							model.eval()
							A     = model(A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_   )
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.num_labels)   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Any	,A_  :   List[str]	,A_  :   List[Any]	,A_  :   Union[str, Any]	,A_  :   List[str]	,A_  :   int	,A_  :   Tuple	,A_  :   List[str]   )  -> Any:
							A     = self.num_choices
							A     = MegatronBertForMultipleChoice(config=A_   )
							model.to(A_   )
							model.eval()
							A     = input_ids.unsqueeze(1   ).expand(-1	,self.num_choices	,-1   ).contiguous()
							A     = token_type_ids.unsqueeze(1   ).expand(-1	,self.num_choices	,-1   ).contiguous()
							A     = input_mask.unsqueeze(1   ).expand(-1	,self.num_choices	,-1   ).contiguous()
							A     = model(
							    A_	,attention_mask=A_	,token_type_ids=A_	,labels=A_	,)
							self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_choices)   )




						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[Any]   )  -> int:
							A     = self.prepare_config_and_inputs()
							(
							    A  
							)     = config_and_inputs
							A     = {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_torch
class 					lowerCAmelCase_					(   SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_		,       unittest.TestCase     ):



						'''simple docstring'''


						_lowerCamelCase:     Any   =     (
						    (
						        MegatronBertModel,
						        MegatronBertForMaskedLM,
						        MegatronBertForCausalLM,
						        MegatronBertForMultipleChoice,
						        MegatronBertForNextSentencePrediction,
						        MegatronBertForPreTraining,
						        MegatronBertForQuestionAnswering,
						        MegatronBertForSequenceClassification,
						        MegatronBertForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowerCamelCase:     Tuple   =     (
						    {
						        'feature-extraction': MegatronBertModel,
						        'fill-mask': MegatronBertForMaskedLM,
						        'question-answering': MegatronBertForQuestionAnswering,
						        'text-classification': MegatronBertForSequenceClassification,
						        'text-generation': MegatronBertForCausalLM,
						        'token-classification': MegatronBertForTokenClassification,
						        'zero-shot': MegatronBertForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						_lowerCamelCase:     Tuple   =     True
						# test_resize_embeddings = False
						_lowerCamelCase:     Any   =     False


						def     _SCREAMING_SNAKE_CASE   (			self  :   str	,A_  :   Optional[int]	,A_  :   Dict	,A_  :   int=False   )  -> Optional[int]:
							A     = super()._prepare_for_class(A_	,A_	,return_labels=A_   )

							if return_labels:
								if model_class in get_values(A_   ):
									A     = torch.zeros(
									    (self.model_tester.batch_size, self.model_tester.seq_length)	,dtype=torch.long	,device=A_   )
									A     = torch.zeros(
									    self.model_tester.batch_size	,dtype=torch.long	,device=A_   )
							return inputs_dict


						def     _SCREAMING_SNAKE_CASE   (			self  :   Any   )  -> Union[str, Any]:
							A     = MegatronBertModelTester(self   )
							A     = ConfigTester(self	,config_class=A_	,hidden_size=37   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Dict   )  -> Union[str, Any]:
							self.config_tester.run_common_tests()


						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[int]   )  -> List[str]:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_model(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Any   )  -> str:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_masked_lm(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Dict   )  -> Union[str, Any]:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Any   )  -> Union[str, Any]:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Dict   )  -> str:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_pretraining(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Any   )  -> Optional[Any]:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_question_answering(*A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   List[str]   )  -> Union[str, Any]:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*A_   )




						def     _SCREAMING_SNAKE_CASE   (			self  :   int   )  -> Any:
							A     = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_token_classification(*A_   )






def    _snake_case					(		snake_case__ :  List[str]  ):
	return torch.tensor(
	    __lowerCAmelCase						,   dtype=torch.long						,   device=__lowerCAmelCase						,   )


_lowercase				 =					1e-4







@require_torch
@require_sentencepiece
@require_tokenizers
class 					lowerCAmelCase_					(   unittest.TestCase     ):



						'''simple docstring'''


						@slow
						@unittest.skip('Model is not available.'   )
						def     _SCREAMING_SNAKE_CASE   (			self  :   Tuple   )  -> List[str]:
							A     = 'nvidia/megatron-bert-uncased-345m'
							if "MYDIR" in os.environ:
								A     = os.path.join(os.environ['MYDIR']	,A_   )
							A     = MegatronBertModel.from_pretrained(A_   )
							model.to(A_   )
							model.half()
							A     = _long_tensor([[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]   )
							with torch.no_grad():
								A     = model(A_   )[0]
							A     = torch.Size((1, 9, 1024)   )
							self.assertEqual(output.shape	,A_   )

							A     = [-0.60_40, -0.25_17, -0.10_25, 0.34_20, -0.67_58, -0.00_17, -0.10_89, -0.19_90, 0.57_28]
							for ii in range(3   ):
								for jj in range(3   ):
									A     = output[0, ii, jj]
									A     = expected[3 * ii + jj]
									A     = 'ii={} jj={} a={} b={}'.format(A_	,A_	,A_	,A_   )
									self.assertTrue(math.isclose(A_	,A_	,rel_tol=A_	,abs_tol=A_   )	,msg=A_   )




from datetime import datetime

import requests

def        __a			(   __lowerCAmelCase   )     ->     bytes:
					SCREAMING_SNAKE_CASE							:     int						=				'https://downloadgram.net/wp-json/wppress/video-downloader/video?url='
					SCREAMING_SNAKE_CASE							:     Any						=				requests.get(base_url + url   ).json()[0]['urls'][0]['src']
					return requests.get(__lowerCAmelCase   ).content


if __name__ == "__main__":
			_lowerCamelCase    :		List[Any]		      =    input("""Enter Video/IGTV url: """).strip()
			_lowerCamelCase    :		int		      =    f"""{datetime.now():%Y-%m-%d_%H:%M:%S}.mp4"""
			with open(file_name, """wb""") as fp:
						fp.write(download_video(url))
			print(f"""Done. Video saved to disk as {file_name}.""")