

"""simple docstring"""
import unittest

from transformers import YosoConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
 import torch

 from transformers import (
     YosoForMaskedLM,
     YosoForMultipleChoice,
     YosoForQuestionAnswering,
     YosoForSequenceClassification,
     YosoForTokenClassification,
     YosoModel,
 )
 from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST

class        _UpperCamelCase	:


  """simple docstring"""





  def __init__( self					: Union[str, Any]       ,       snake_case					: Any       ,       snake_case					: Optional[Any]=13       ,       snake_case					: Union[str, Any]=7       ,       snake_case					: Tuple=True       ,       snake_case					: int=True       ,       snake_case					: Tuple=True       ,       snake_case					: str=True       ,       snake_case					: List[Any]=99       ,       snake_case					: Any=32       ,       snake_case					: Any=5       ,       snake_case					: Any=4       ,       snake_case					: int=37       ,       snake_case					: Optional[Any]="gelu"       ,       snake_case					: List[Any]=0.1       ,       snake_case					: Any=0.1       ,       snake_case					: Union[str, Any]=512       ,       snake_case					: Optional[Any]=16       ,       snake_case					: Dict=2       ,       snake_case					: Optional[Any]=0.02       ,       snake_case					: Optional[int]=3       ,       snake_case					: Dict=4       ,       snake_case					: Dict=None       ,       )	->			str:


         '''simple docstring'''





         __magic_name__			:		str        =     parent
         __magic_name__			:		Dict        =     batch_size
         __magic_name__			:		Optional[int]        =     seq_length
         __magic_name__			:		Tuple        =     is_training
         __magic_name__			:		str        =     use_input_mask
         __magic_name__			:		List[str]        =     use_token_type_ids
         __magic_name__			:		Optional[Any]        =     use_labels
         __magic_name__			:		Any        =     vocab_size
         __magic_name__			:		Union[str, Any]        =     hidden_size
         __magic_name__			:		Optional[Any]        =     num_hidden_layers
         __magic_name__			:		Dict        =     num_attention_heads
         __magic_name__			:		List[Any]        =     intermediate_size
         __magic_name__			:		List[str]        =     hidden_act
         __magic_name__			:		List[str]        =     hidden_dropout_prob
         __magic_name__			:		Optional[Any]        =     attention_probs_dropout_prob
         __magic_name__			:		Optional[Any]        =     max_position_embeddings
         __magic_name__			:		Any        =     type_vocab_size
         __magic_name__			:		Dict        =     type_sequence_label_size
         __magic_name__			:		str        =     initializer_range
         __magic_name__			:		Dict        =     num_labels
         __magic_name__			:		List[Any]        =     num_choices
         __magic_name__			:		str        =     scope



  def 							_UpperCAmelCase      ( self					: Tuple      )	->			int:


         '''simple docstring'''





         __magic_name__			:		List[str]        =     ids_tensor([self.batch_size, self.seq_length]       ,       self.vocab_size      )

         __magic_name__			:		Dict        =     None
         if self.use_input_mask:
                __magic_name__			:		List[str]        =     random_attention_mask([self.batch_size, self.seq_length]      )

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

         __magic_name__			:		Dict        =     None
         __magic_name__			:		Union[str, Any]        =     None
         __magic_name__			:		Optional[Any]        =     None
         if self.use_labels:
                __magic_name__			:		int        =     ids_tensor([self.batch_size]       ,       self.type_sequence_label_size      )
                __magic_name__			:		Optional[int]        =     ids_tensor([self.batch_size, self.seq_length]       ,       self.num_labels      )
                __magic_name__			:		Tuple        =     ids_tensor([self.batch_size]       ,       self.num_choices      )

         __magic_name__			:		Optional[int]        =     self.get_config()

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



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			List[Any]:


         '''simple docstring'''





         return YosoConfig(
             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       ,       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=lowercase_       ,       initializer_range=self.initializer_range       ,       )



  def 							_UpperCAmelCase      ( self					: int      )	->			Union[str, Any]:


         '''simple docstring'''





         __magic_name__			:		Optional[int]        =     self.get_config()
         __magic_name__			:		Optional[Any]        =     300
         return config



  def 							_UpperCAmelCase      ( self					: str      )	->			Optional[Any]:


         '''simple docstring'''





         (
             (
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							       
         )			:		Any        =     self.prepare_config_and_inputs()

         __magic_name__			:		Union[str, Any]        =     True
         __magic_name__			:		Any        =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
         __magic_name__			:		List[Any]        =     ids_tensor([self.batch_size, self.seq_length]       ,       vocab_size=2      )

         return (
             config,
             input_ids,
             token_type_ids,
             input_mask,
             sequence_labels,
             token_labels,
             choice_labels,
             encoder_hidden_states,
             encoder_attention_mask,
         )



  def 							_UpperCAmelCase      ( self					: List[Any]       ,       snake_case					: Union[str, Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Dict       ,       snake_case					: Optional[int]       ,       snake_case					: Dict       ,       snake_case					: str       ,       snake_case					: Union[str, Any]      )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     YosoModel(config=lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Any        =     model(lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_      )
         __magic_name__			:		Union[str, Any]        =     model(lowercase_       ,       token_type_ids=lowercase_      )
         __magic_name__			:		str        =     model(lowercase_      )
         self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)      )



  def 							_UpperCAmelCase      ( self					: int       ,       snake_case					: Optional[Any]       ,       snake_case					: Dict       ,       snake_case					: List[Any]       ,       snake_case					: Union[str, Any]       ,       snake_case					: Tuple       ,       snake_case					: str       ,       snake_case					: Tuple       ,       snake_case					: Tuple       ,       snake_case					: Optional[int]       ,       )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     True
         __magic_name__			:		Tuple        =     YosoModel(lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Dict        =     model(
             lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       encoder_hidden_states=lowercase_       ,       encoder_attention_mask=lowercase_       ,       )
         __magic_name__			:		str        =     model(
             lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       encoder_hidden_states=lowercase_       ,       )
         __magic_name__			:		Tuple        =     model(lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_      )
         self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)      )



  def 							_UpperCAmelCase      ( self					: Optional[Any]       ,       snake_case					: List[Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Optional[Any]       ,       snake_case					: List[str]       ,       snake_case					: Optional[Any]       ,       snake_case					: Optional[int]       ,       snake_case					: int      )	->			Optional[int]:


         '''simple docstring'''





         __magic_name__			:		Dict        =     YosoForMaskedLM(config=lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Optional[Any]        =     model(lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       labels=lowercase_      )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.vocab_size)      )



  def 							_UpperCAmelCase      ( self					: str       ,       snake_case					: Optional[Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Dict       ,       snake_case					: int       ,       snake_case					: Tuple       ,       snake_case					: Optional[int]       ,       snake_case					: Optional[int]      )	->			int:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     YosoForQuestionAnswering(config=lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Tuple        =     model(
             lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       start_positions=lowercase_       ,       end_positions=lowercase_       ,       )
         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 							_UpperCAmelCase      ( self					: Dict       ,       snake_case					: Optional[int]       ,       snake_case					: List[Any]       ,       snake_case					: int       ,       snake_case					: Tuple       ,       snake_case					: Optional[Any]       ,       snake_case					: Optional[Any]       ,       snake_case					: Dict      )	->			Union[str, Any]:


         '''simple docstring'''





         __magic_name__			:		int        =     self.num_labels
         __magic_name__			:		Tuple        =     YosoForSequenceClassification(lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Tuple        =     model(lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       labels=lowercase_      )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_labels)      )



  def 							_UpperCAmelCase      ( self					: Optional[Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Optional[int]       ,       snake_case					: int       ,       snake_case					: int       ,       snake_case					: str       ,       snake_case					: int       ,       snake_case					: Optional[Any]      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     self.num_labels
         __magic_name__			:		str        =     YosoForTokenClassification(config=lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Optional[int]        =     model(lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       labels=lowercase_      )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.num_labels)      )



  def 							_UpperCAmelCase      ( self					: str       ,       snake_case					: Tuple       ,       snake_case					: List[str]       ,       snake_case					: List[Any]       ,       snake_case					: Tuple       ,       snake_case					: int       ,       snake_case					: List[str]       ,       snake_case					: str      )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		Dict        =     self.num_choices
         __magic_name__			:		Any        =     YosoForMultipleChoice(config=lowercase_      )
         model.to(lowercase_      )
         model.eval()
         __magic_name__			:		Optional[int]        =     input_ids.unsqueeze(1      ).expand(-1       ,       self.num_choices       ,       -1      ).contiguous()
         __magic_name__			:		Any        =     token_type_ids.unsqueeze(1      ).expand(-1       ,       self.num_choices       ,       -1      ).contiguous()
         __magic_name__			:		List[Any]        =     input_mask.unsqueeze(1      ).expand(-1       ,       self.num_choices       ,       -1      ).contiguous()
         __magic_name__			:		Any        =     model(
             lowercase_       ,       attention_mask=lowercase_       ,       token_type_ids=lowercase_       ,       labels=lowercase_       ,       )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_choices)      )




  def 							_UpperCAmelCase      ( self					: Dict      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.prepare_config_and_inputs()
         (
             (
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							(
             __magic_name__       
         )       ,							       
         )			:		Optional[Any]        =     config_and_inputs
         __magic_name__			:		List[str]        =     {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict

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


  """simple docstring"""





  snake_case_        =    (
      (
          YosoModel,
          YosoForMaskedLM,
          YosoForMultipleChoice,
          YosoForQuestionAnswering,
          YosoForSequenceClassification,
          YosoForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  snake_case_        =    False
  snake_case_        =    False
  snake_case_        =    False

  snake_case_        =    ()
  snake_case_        =    (
      {
          'feature-extraction': YosoModel,
          'fill-mask': YosoForMaskedLM,
          'question-answering': YosoForQuestionAnswering,
          'text-classification': YosoForSequenceClassification,
          'token-classification': YosoForTokenClassification,
          'zero-shot': YosoForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )



  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     YosoModelTester(self      )
         __magic_name__			:		Any        =     ConfigTester(self       ,       config_class=lowercase_       ,       hidden_size=37      )



  def 							_UpperCAmelCase      ( self					: int      )	->			List[str]:


         '''simple docstring'''





         self.config_tester.run_common_tests()



  def 							_UpperCAmelCase      ( self					: Any      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: str      )	->			str:


         '''simple docstring'''





         __magic_name__			:		int        =     self.model_tester.prepare_config_and_inputs()
         for type in ["absolute", "relative_key", "relative_key_query"]:
                __magic_name__			:		Any        =     type
                self.model_tester.create_and_check_model(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		Tuple        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: str      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Optional[int]        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			List[str]:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: int      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		int        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*lowercase_      )



  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		int        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*lowercase_      )



  @slow
  def 							_UpperCAmelCase      ( self					: int      )	->			Union[str, Any]:


         '''simple docstring'''





         for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                __magic_name__			:		List[Any]        =     YosoModel.from_pretrained(lowercase_      )
                self.assertIsNotNone(lowercase_      )




  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Dict:


         '''simple docstring'''





         return

@require_torch
class        _UpperCamelCase	(						unittest.TestCase	):


  """simple docstring"""





  @slow
  def 							_UpperCAmelCase      ( self					: int      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     YosoModel.from_pretrained('''uw-madison/yoso-4096'''      )
         __magic_name__			:		Optional[int]        =     torch.tensor([[0, 1, 2, 3, 4, 5]]      )

         with torch.no_grad():
                __magic_name__			:		Optional[int]        =     model(lowercase_      )[0]

         __magic_name__			:		Dict        =     torch.Size((1, 6, 768)      )
         self.assertEqual(output.shape       ,       lowercase_      )

         __magic_name__			:		Dict        =     torch.tensor(
             [[[-0.0611, 0.1242, 0.0840], [0.0280, -0.0048, 0.1125], [0.0106, 0.0226, 0.0751]]]      )

         self.assertTrue(torch.allclose(output[:, :3, :3]       ,       lowercase_       ,       atol=1e-4      )      )



  @slow
  def 							_UpperCAmelCase      ( self					: Dict      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		Dict        =     YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''      )
         __magic_name__			:		Any        =     torch.tensor([[0, 1, 2, 3, 4, 5]]      )

         with torch.no_grad():
                __magic_name__			:		Dict        =     model(lowercase_      )[0]

         __magic_name__			:		str        =     5_0265

         __magic_name__			:		Optional[Any]        =     torch.Size((1, 6, vocab_size)      )
         self.assertEqual(output.shape       ,       lowercase_      )

         __magic_name__			:		int        =     torch.tensor(
             [[[-2.1313, -3.7285, -2.2407], [-2.7047, -3.3314, -2.6408], [0.0629, -2.5166, -0.3356]]]      )

         self.assertTrue(torch.allclose(output[:, :3, :3]       ,       lowercase_       ,       atol=1e-4      )      )




  @slow
  def 							_UpperCAmelCase      ( self					: List[str]      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Any        =     YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''      )
         __magic_name__			:		List[str]        =     torch.arange(4096      ).unsqueeze(0      )

         with torch.no_grad():
                __magic_name__			:		Union[str, Any]        =     model(lowercase_      )[0]

         __magic_name__			:		Dict        =     5_0265

         __magic_name__			:		Optional[Any]        =     torch.Size((1, 4096, vocab_size)      )
         self.assertEqual(output.shape       ,       lowercase_      )

         __magic_name__			:		Tuple        =     torch.tensor(
             [[[-2.3914, -4.3742, -5.0956], [-4.0988, -4.2384, -7.0406], [-3.1427, -3.7192, -6.6800]]]      )

         self.assertTrue(torch.allclose(output[:, :3, :3]       ,       lowercase_       ,       atol=1e-4      )      )





"""simple docstring"""


import shutil

import requests

def 					_lowerCAmelCase (  lowercase_						,      lowercase_ = False						,      lowercase_ = "."		):
						UpperCAmelCase			 =					'https://api.nasa.gov/planetary/apod'
						return requests.get(lowercase_						,      params={'api_key': api_key}		).json()

def 					_lowerCAmelCase (  lowercase_						,      lowercase_ = "."		):
						UpperCAmelCase			 =					get_apod_data(lowercase_		)
						UpperCAmelCase			 =					apod_data['url']
						UpperCAmelCase			 =					img_url.split('/'		)[-1]
						UpperCAmelCase			 =					requests.get(lowercase_						,      stream=lowercase_		)

						with open(F"""{path}/{img_name}"""						,      'wb+'		) as img_file:
												shutil.copyfileobj(response.raw						,      lowercase_		)
						del response
						return apod_data

def 					_lowerCAmelCase (  lowercase_		):
						UpperCAmelCase			 =					'https://images-api.nasa.gov/search'
						return requests.get(lowercase_						,      params={'q': query}		).json()


if __name__ == "__main__":
				print(save_apod("""YOUR API KEY"""))
				snake_case_								=			get_archive_data("""apollo 2011""")["""collection"""]["""items"""]
				print(apollo_aaaa_items[0]["""data"""][0]["""description"""])





