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



				"""simple docstring"""

				def __init__(					self		,     lowerCAmelCase		,     lowerCAmelCase=13		,     lowerCAmelCase=7		,     lowerCAmelCase=True		,     lowerCAmelCase=True		,     lowerCAmelCase=True		,     lowerCAmelCase=True		,     lowerCAmelCase=99		,     lowerCAmelCase=32		,     lowerCAmelCase=5		,     lowerCAmelCase=4		,     lowerCAmelCase=37		,     lowerCAmelCase="gelu"		,     lowerCAmelCase=0.1		,     lowerCAmelCase=0.1		,     lowerCAmelCase=5_12		,     lowerCAmelCase=16		,     lowerCAmelCase=2		,     lowerCAmelCase=0.02		,     lowerCAmelCase=3		,     lowerCAmelCase=4		,     lowerCAmelCase=None		,     ):






										"""simple docstring"""

										snake_case             =      parent
										snake_case             =      batch_size
										snake_case             =      seq_length
										snake_case             =      is_training
										snake_case             =      use_input_mask
										snake_case             =      use_token_type_ids
										snake_case             =      use_labels
										snake_case             =      vocab_size
										snake_case             =      hidden_size
										snake_case             =      num_hidden_layers
										snake_case             =      num_attention_heads
										snake_case             =      intermediate_size
										snake_case             =      hidden_act
										snake_case             =      hidden_dropout_prob
										snake_case             =      attention_probs_dropout_prob
										snake_case             =      max_position_embeddings
										snake_case             =      type_vocab_size
										snake_case             =      type_sequence_label_size
										snake_case             =      initializer_range
										snake_case             =      num_labels
										snake_case             =      num_choices
										snake_case             =      scope

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      ids_tensor([self.batch_size, self.seq_length]		,     self.vocab_size     )

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

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

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

										snake_case             =      self.get_config()

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

				def 		snake_case			(					self     ):






										"""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 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.get_config()
										snake_case             =      3_00
										return config

				def 		snake_case			(					self     ):






										"""simple docstring"""

										(
										    snake_case    
										)             =      self.prepare_config_and_inputs()

										snake_case             =      True
										snake_case             =      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

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

				def 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     ):






										"""simple docstring"""

										snake_case             =      True
										snake_case             =      YosoModel(SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      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_		,     )
										snake_case             =      model(
										    SCREAMING_SNAKE_CASE_		,     attention_mask=SCREAMING_SNAKE_CASE_		,     token_type_ids=SCREAMING_SNAKE_CASE_		,     encoder_hidden_states=SCREAMING_SNAKE_CASE_		,     )
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

										snake_case             =      YosoForMaskedLM(config=SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

										snake_case             =      YosoForQuestionAnswering(config=SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

										snake_case             =      self.num_labels
										snake_case             =      YosoForSequenceClassification(SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

										snake_case             =      self.num_labels
										snake_case             =      YosoForTokenClassification(config=SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      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 		snake_case			(					self		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase		,     lowerCAmelCase     ):






										"""simple docstring"""

										snake_case             =      self.num_choices
										snake_case             =      YosoForMultipleChoice(config=SCREAMING_SNAKE_CASE_     )
										model.to(SCREAMING_SNAKE_CASE_     )
										model.eval()
										snake_case             =      input_ids.unsqueeze(1     ).expand(-1		,     self.num_choices		,     -1     ).contiguous()
										snake_case             =      token_type_ids.unsqueeze(1     ).expand(-1		,     self.num_choices		,     -1     ).contiguous()
										snake_case             =      input_mask.unsqueeze(1     ).expand(-1		,     self.num_choices		,     -1     ).contiguous()
										snake_case             =      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 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.prepare_config_and_inputs()
										(
										    snake_case    
										)             =      config_and_inputs
										snake_case             =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict





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



				"""simple docstring"""
				_lowerCAmelCase  :     List[str]      	=    (
				    (
				        YosoModel,
				        YosoForMaskedLM,
				        YosoForMultipleChoice,
				        YosoForQuestionAnswering,
				        YosoForSequenceClassification,
				        YosoForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				_lowerCAmelCase  :     Tuple      	=    False
				_lowerCAmelCase  :     Tuple      	=    False
				_lowerCAmelCase  :     List[str]      	=    False

				_lowerCAmelCase  :     List[str]      	=    ()
				_lowerCAmelCase  :     Optional[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 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      YosoModelTester(self     )
										snake_case             =      ConfigTester(self		,     config_class=SCREAMING_SNAKE_CASE_		,     hidden_size=37     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

										self.config_tester.run_common_tests()

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

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

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_     )

				def 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_     )

				@slow
				def 		snake_case			(					self     ):






										"""simple docstring"""

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

				def 		snake_case			(					self     ):






										"""simple docstring"""

										return





@require_torch
class 	lowerCAmelCase_     (      unittest.TestCase       ):



				"""simple docstring"""

				@slow
				def 		snake_case			(					self     ):






										"""simple docstring"""

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

										with torch.no_grad():
																snake_case             =      model(SCREAMING_SNAKE_CASE_     )[0]

										snake_case             =      torch.Size((1, 6, 7_68)     )
										self.assertEqual(output.shape		,     SCREAMING_SNAKE_CASE_     )

										snake_case             =      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 		snake_case			(					self     ):






										"""simple docstring"""

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

										with torch.no_grad():
																snake_case             =      model(SCREAMING_SNAKE_CASE_     )[0]

										snake_case             =      5_02_65

										snake_case             =      torch.Size((1, 6, vocab_size)     )
										self.assertEqual(output.shape		,     SCREAMING_SNAKE_CASE_     )

										snake_case             =      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 		snake_case			(					self     ):






										"""simple docstring"""

										snake_case             =      YosoForMaskedLM.from_pretrained('uw-madison/yoso-4096'     )
										snake_case             =      torch.arange(40_96     ).unsqueeze(0     )

										with torch.no_grad():
																snake_case             =      model(SCREAMING_SNAKE_CASE_     )[0]

										snake_case             =      5_02_65

										snake_case             =      torch.Size((1, 40_96, vocab_size)     )
										self.assertEqual(output.shape		,     SCREAMING_SNAKE_CASE_     )

										snake_case             =      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'''


from __future__ import annotations

import random






class 						lowerCAmelCase_	:







  '''simple docstring'''

  UpperCamelCase_			:      Optional[int]										=				6



  def __init__( self				:							Dict	)			->		Dict:







       '''simple docstring'''



       A:		Union[str, Any]          =		list(range(1					,  Dice.NUM_SIDES + 1	)	)




  def 					_snake_case     ( self				:							Optional[Any]	)			->		Any:







       '''simple docstring'''



       return random.choice(self.sides	)






def 					SCREAMING_SNAKE_CASE(   __lowercase		,				__lowercase = 2	)			-> list[float]:
     A:		Union[str, Any]          =		[Dice() for i in range(__lowercase	)]
     A:		Union[str, Any]          =		[0] * (len(__lowercase	) * Dice.NUM_SIDES + 1)
     for _ in range(__lowercase	):
          count_of_sum[sum(dice.roll() for dice in dices	)] += 1
     A:		Dict          =		[round((count * 1_0_0) / num_throws		,				2	) for count in count_of_sum]
     return probability[num_dice:]  # remove probability of sums that never appear


if __name__ == "__main__":
     import doctest

     doctest.testmod()






