
"""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 						lowercase:



     def __init__(       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE=1_3    ,							__SCREAMING_SNAKE_CASE=7    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=9_9    ,							__SCREAMING_SNAKE_CASE=3_2    ,							__SCREAMING_SNAKE_CASE=5    ,							__SCREAMING_SNAKE_CASE=4    ,							__SCREAMING_SNAKE_CASE=3_7    ,							__SCREAMING_SNAKE_CASE="gelu"    ,							__SCREAMING_SNAKE_CASE=0.1    ,							__SCREAMING_SNAKE_CASE=0.1    ,							__SCREAMING_SNAKE_CASE=5_1_2    ,							__SCREAMING_SNAKE_CASE=1_6    ,							__SCREAMING_SNAKE_CASE=2    ,							__SCREAMING_SNAKE_CASE=0.02    ,							__SCREAMING_SNAKE_CASE=3    ,							__SCREAMING_SNAKE_CASE=4    ,							__SCREAMING_SNAKE_CASE=None    ,							)		->    List[Any]:







         """simple docstring"""



         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__    = 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  lowercase__     (       self      )		->    List[str]:







         """simple docstring"""



         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  lowercase__     (       self      )		->    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=__SCREAMING_SNAKE_CASE    ,							initializer_range=self.initializer_range    ,							)



     def  lowercase__     (       self      )		->    Optional[int]:







         """simple docstring"""



         a__    = self.get_config()
         a__    = 3_0_0
         return config



     def  lowercase__     (       self      )		->    Optional[int]:







         """simple docstring"""



         (
             (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,        
         )    = self.prepare_config_and_inputs()

         a__    = True
         a__    = floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
         a__    = 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  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Tuple:







         """simple docstring"""



         a__    = YosoModel(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE      )
         a__    = model(__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE      )
         a__    = model(__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)      )



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







         """simple docstring"""



         a__    = True
         a__    = YosoModel(__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							encoder_hidden_states=__SCREAMING_SNAKE_CASE    ,							encoder_attention_mask=__SCREAMING_SNAKE_CASE    ,							)
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							encoder_hidden_states=__SCREAMING_SNAKE_CASE    ,							)
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Any:







         """simple docstring"""



         a__    = YosoForMaskedLM(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.vocab_size)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Tuple:







         """simple docstring"""



         a__    = YosoForQuestionAnswering(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							start_positions=__SCREAMING_SNAKE_CASE    ,							end_positions=__SCREAMING_SNAKE_CASE    ,							)
         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  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Dict:







         """simple docstring"""



         a__    = self.num_labels
         a__    = YosoForSequenceClassification(__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_labels)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    List[Any]:







         """simple docstring"""



         a__    = self.num_labels
         a__    = YosoForTokenClassification(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.num_labels)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:







         """simple docstring"""



         a__    = self.num_choices
         a__    = YosoForMultipleChoice(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         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(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							token_type_ids=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE    ,							)
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_choices)      )




     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = self.prepare_config_and_inputs()
         (
             (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             a__    
         )  ,    (
             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 						lowercase(_lowercase						,	_lowercase						,	unittest.TestCase					):
     __snake_case:  List[str]  				=    (
         (
             YosoModel,
             YosoForMaskedLM,
             YosoForMultipleChoice,
             YosoForQuestionAnswering,
             YosoForSequenceClassification,
             YosoForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     __snake_case:  int  				=    False
     __snake_case:  Optional[Any]  				=    False
     __snake_case:  Union[str, Any]  				=    False

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



     def  lowercase__     (       self      )		->    Optional[int]:







         """simple docstring"""



         a__    = YosoModelTester(self      )
         a__    = ConfigTester(self    ,							config_class=__SCREAMING_SNAKE_CASE    ,							hidden_size=3_7      )



     def  lowercase__     (       self      )		->    List[str]:







         """simple docstring"""



         self.config_tester.run_common_tests()



     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         for type in ["absolute", "relative_key", "relative_key_query"]:
             a__    = type
             self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a__    = YosoModel.from_pretrained(__SCREAMING_SNAKE_CASE      )
             self.assertIsNotNone(__SCREAMING_SNAKE_CASE      )




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







         """simple docstring"""



         return







@require_torch
class 						lowercase(unittest.TestCase					):



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







         """simple docstring"""



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

         with torch.no_grad():
             a__    = model(__SCREAMING_SNAKE_CASE      )[0]

         a__    = torch.Size((1, 6, 7_6_8)      )
         self.assertEqual(output.shape    ,							__SCREAMING_SNAKE_CASE      )

         a__    = torch.tensor(
             [[[-0.06_11, 0.12_42, 0.08_40], [0.02_80, -0.00_48, 0.11_25], [0.01_06, 0.02_26, 0.07_51]]]      )

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



     @slow
     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



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

         with torch.no_grad():
             a__    = model(__SCREAMING_SNAKE_CASE      )[0]

         a__    = 5_0_2_6_5

         a__    = torch.Size((1, 6, vocab_size)      )
         self.assertEqual(output.shape    ,							__SCREAMING_SNAKE_CASE      )

         a__    = torch.tensor(
             [[[-2.13_13, -3.72_85, -2.24_07], [-2.70_47, -3.33_14, -2.64_08], [0.06_29, -2.51_66, -0.33_56]]]      )

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




     @slow
     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = YosoForMaskedLM.from_pretrained('uw-madison/yoso-4096'      )
         a__    = torch.arange(4_0_9_6      ).unsqueeze(0      )

         with torch.no_grad():
             a__    = model(__SCREAMING_SNAKE_CASE      )[0]

         a__    = 5_0_2_6_5

         a__    = torch.Size((1, 4_0_9_6, vocab_size)      )
         self.assertEqual(output.shape    ,							__SCREAMING_SNAKE_CASE      )

         a__    = torch.tensor(
             [[[-2.39_14, -4.37_42, -5.09_56], [-4.09_88, -4.23_84, -7.04_06], [-3.14_27, -3.71_92, -6.68_00]]]      )

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




"""simple docstring"""




import shutil

import requests



def 						__magic_name__		(				UpperCamelCase    :		str       ,		UpperCamelCase    :		bool = False       ,		UpperCamelCase    :		str = "."    )    ->	dict:
    a__    = 'https://api.nasa.gov/planetary/apod'
    return requests.get(UpperCamelCase       ,		params={'api_key': api_key}    ).json()



def 						__magic_name__		(				UpperCamelCase    :		str       ,		UpperCamelCase    :		str = "."    )    ->	dict:
    a__    = get_apod_data(UpperCamelCase    )
    a__    = apod_data['url']
    a__    = img_url.split('/'    )[-1]
    a__    = requests.get(UpperCamelCase       ,		stream=UpperCamelCase    )

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



def 						__magic_name__		(				UpperCamelCase    :		str    )    ->	dict:
    a__    = 'https://images-api.nasa.gov/search'
    return requests.get(UpperCamelCase       ,		params={'q': query}    ).json()


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


